def calcCRMA(date, ret){ t=table(date as date, ret as ret) t[`cr1] =log(move(ret, 21) +1) diff = t[`cr1] - log( move(ret, 21)) for(x in 2 .. 12){ t["cr" + string(x) ] = diff + log(move(ret, 21*x)) } return exec log(1 + rowMax(cr1,cr2,cr3,cr4,cr5,cr6,cr7,cr8,cr9,cr10,cr11,cr12)) - log(1 + rowMin(cr1,cr2,cr3,cr4,cr5,cr6,cr7,cr8,cr9,cr10,cr11,cr12)) from t } //产生一些模拟数据 t=table(2019.01.01 + 0..252 as date, norm(0.0005, 0.0001, 253)+ 0.01 as ret, take(`ibm, 253) as sym) //计算全部股票每天的crma select sym,date, ret, calcCRMA(date, ret) as crma from t context by sym