3000支股票,两两之间求相关性,DolphinDB有什么快速算法吗

如题,现在有没有现成快速算法代码?

请先 登录 后评论

1 个回答

Johhny

pairwise correlation的代码如下:

priceMatrix = exec wavg(Trade_Price, Trade_Volume) from trades where Time between 09:30:00.000000000 : 16:00:00.000000000 pivot by minute(Time) as minute, Symbol

priceMatrix.ffill!()

retMatrix = each(def(x):ratios(x)-1, priceMatrix)

corrMatrix = cross(corr, retMatrix)

首先根据高频数据计算每分钟的vwap,把结果转化为一个矩阵,每列一只股票,每行一分钟,然后 forward fill missing value,然后使用高阶函数each,把这个无名函数def(x):ratios(x)-1 应用于 priceMatrix 的每一列,产生分钟级别的stock return,最后使用高阶函数cross,对 retMatrix的没两列计算corr。

请先 登录 后评论