Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
658 B
1
Indexable
Never
weights_long<-subport_long(weights)
weights_short<-subport_short(weights)

final_weights_long <- weights_long[1:(nrow(weights_long)-1),]
portfolio_long <- final_weights_long * final_returns
portfolio_returns_byday_long <- apply(portfolio_long, MARGIN = 1, FUN = sum)

final_weights_short <- weights_short[1:(nrow(weights_short)-1),]
portfolio_short <- final_weights_short * final_returns
portfolio_returns_byday_short <- apply(portfolio_short, MARGIN = 1, FUN = sum)

long_vs_short <- bind_cols(portfolio_returns_byday_long, portfolio_returns_byday_short)
colnames(long_vs_short) <- c("long", "short")
cor(long_vs_short$long,long_vs_short$short)