Question
I need to calculate the linear relationship between the companies using the correlation coefficient. Here I need to calculate the correlation between company pairs. For
I need to calculate the linear relationship between the companies using the correlation coefficient. Here I need to calculate the correlation between company pairs. For example: company 1 vs company 2, company 1 vs company 3, etc.
Table_cor <- Monthly_Ret_Join %>%
group_by(symbol) %>%
summarise(Num_of_Months=n(),
mRet_Mean=mean(mRet, na.rm= TRUE),
mRet_SD=sd(mRet, na.rm= TRUE),
Rb_SD=sd(Rb, na.rm= TRUE),
Cov_mRet_Rb=cov(x=mRet,y=Rb, use="pairwise.complete.obs"),
Cor_mRet_Rb=cor(x=mRet,y=Rb, use="pairwise.complete.obs"),
Cor_mRet_Rb2=Cov_mRet_Rb/(mRet_SD*Rb_SD))
This line compares every company with the portfolio, but I need to compare the other companies between them.
Cor_mRet_Rb=cor(x=mRet,y=Rb, use="pairwise.complete.obs")
So, I just need to modify R code to obtain these calculations.
I need to calculate the linear relationship between the companies using the correlation coefficient. Here I need to calculate the correlation between company pairs. For example: company 1 vs company 2, company 1 vs company 3, etc.
Table_cor <- Monthly_Ret_Join %>%
group_by(symbol) %>%
summarise(Num_of_Months=n(),
mRet_Mean=mean(mRet, na.rm= TRUE),
mRet_SD=sd(mRet, na.rm= TRUE),
Rb_SD=sd(Rb, na.rm= TRUE),
Cov_mRet_Rb=cov(x=mRet,y=Rb, use="pairwise.complete.obs"),
Cor_mRet_Rb=cor(x=mRet,y=Rb, use="pairwise.complete.obs"),
Cor_mRet_Rb2=Cov_mRet_Rb/(mRet_SD*Rb_SD))
This line compares every company with the portfolio, but I need to compare the other companies between them.
Cor_mRet_Rb=cor(x=mRet,y=Rb, use="pairwise.complete.obs")
So, I just need to modify R code to obtain these calculations.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started