I have a table with a column trade_date and multiple factor columns. I would like to standardize these factor columns using the funciton zscore(), with trade-date as the grouping basis.
How can I pass these columns in batch?
On
You can refer to the following methods:
For single column:
select zscore(factor1) from t context by trade_date
For multiple columns:
(1) in-memory table:
contextby(zscore, t, t.trade_date)
(2) Otherwise, use meta-programming:
t = table(100:0, [`trade_date, `symbol, `f1,`f2,`f3,`f4,`f5], [DATE, SYMBOL, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE])
otherCol = [`trade_date, `symbol]
colName = t.colNames()
factorCol = colName[not colName in otherCol]
sql(select=sqlCol(factorCol, zscore, "re_" + factorCol), from=objByName("t"), groupBy=sqlCol("trade_date"), groupFlag=0)
Let's say you have a table
tblwith columnstrade_date,f1, andf2. You can useupdatefunction to group the table by thetrade_datecolumn and calculate the z-scores for each factor column using thezscore()function. The result includes new columnsf1_zscoreandf2_zscorewhich are standardized values off1andf2.