I have data like the following:
set.seed(1)
portfolio_profit_daily <- data.table(`Stat`="Profit","2019-01-01"=rnorm(1), "2019-01-02"=rnorm(1), "2019-01-03"=rnorm(1), "2019-01-04"=rnorm(1), "2019-01-05"=rnorm(1))
asset_forecasted_daily <- data.table(`Asset`=c("A1","A2","A3","A4"),"2019-01-01"=rnorm(4), "2019-01-02"=rnorm(4), "2019-01-03"=rnorm(4), "2019-01-04"=rnorm(4), "2019-01-05"=rnorm(4),
"2019-01-06"=rnorm(4),"2019-01-07"=rnorm(4),"2019-01-08"=rnorm(4),"2019-01-09"=rnorm(4),"2019-01-10"=rnorm(4))
The data.table portfolio_profit_daily
contains the daily returns of the whole portfolio (5 days of the month have passed). asset_forecasted_daily
contains the forecasted returns for several individual stocks (note the forecasted period is for 10 days). I would like to add a new column to asset_forecasted_daily
that calculates the correlation between the first 5 days of each stock's forecast and the 5 days of the daily portfolio returns.
Thanks so much.