Dolphin如何计算Alpha 147因子?

def alpha147(t):
{ REGBETA(MEAN(CLOSE,12), list(range(1,13)), 12 }

其中: REGBETA(list1, list2, n):

'''need:(list1,list2,number)  return:number

前 n 期样本 A 对 B 做回归所得回归系数'''


请先 登录 后评论

2 个回答

Juntao Wang
def olss(x, y) {
	return ols(x, y)[1]
}

def alpha147SQL(vector) {
	n = 12
	sequence = 1..n
	mean_12 = mavg(vector, 12)
	return moving(olss{, sequence}, mean_12, 12)
}

pt = select tradingdate, symbol, closeprice from loadTable("dfs://test", "test") where tradingdate = 2021.01.02
alpha147DDBSql = select alpha147SQL(closeprice) from pt context by symbol
请先 登录 后评论
blliu

可以使用如下代码来实现Alpha 147因子的计算

//1、模拟数据
tmp_table = table(
    concatDateTime(take(2023.12.12, 4802000), (rand((09:30:00.000+0..2400*3*1000) join (13:00:00.000+0..2400*3*1000), 4802000).sort())) as dt,
    rand(string(1001..1200), 4802000) as symbol, 
    rand(100.0, 4802000) as price, 
    rand(100, 4802000) as vol);

// 2、alpha147代码实现
defg olss (x) : ols(x, 1..12)[1];
def alpha147SQL (vector) : moving(olss, mavg(vector, 12), 12);

alpha147DDBSql = select alpha147SQL(price) from loadTable("dfs://ohlc_test", "ohlc_test") where date(ts) = 2023.12.12 context by symbol;

测试数据:4.3G(4802000)

attachments-2024-02-5O3uPghy65bb2fcb3b8a4.png

请先 登录 后评论