- https://in.mathworks.com/help/stats/fitlm.html
- https://in.mathworks.com/help/stats/fitlm.html
- https://in.mathworks.com/help/matlab/ref/polyfit.html
- https://in.mathworks.com/help/curvefit/fit.html
- https://in.mathworks.com/help/matlab/ref/cov.html
- https://in.mathworks.com/help/matlab/ref/var.html
- https://in.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html
How to compute beta between stock and index returns, when the index returns are negative.
9 次查看(过去 30 天)
显示 更早的评论
Hello!, im having troubles when trying to calculate the beta of a stock in relation with an index returns, with the condition that the calculation of the beta only takes into consideration when the index returns are negative. The code i have up to is the following:
% Find the beta
mdl = fitlm(as51r,bhpr,'linear','Intercept',true);
coeffs = mdl.Coefficients.Estimate;
bhp_beta = coeffs(2);
this will give me the normal beta of the stock, but i need it when the index returns are negative.
Cheers.
0 个评论
回答(1 个)
Saarthak Gupta
2023-9-5
编辑:Saarthak Gupta
2023-9-5
Hi Marlon,
I believe you are trying to calculate the beta of a stock through linear regression. ‘fitlm’ works for any set of data points, which may or may not be negative. You can also use functions like fit and polyfit to fit a polynomial.
In case you wish to calculate beta only for those set of data points, for which the index returns are negative, you can filter them using logical indexing in MATLAB, and subsequently use ‘fitlm’ or the analytical formula for calculating beta:
neg_indx = as51r < 0;
as51r_neg = as51r[neg_indx];
bhpr_neg = bhpr[neg_indx];
mdl = fitlm(as51r_neg,bhpr_neg,'linear','Intercept',true);
coeffs = mdl.Coefficients.Estimate;
bhp_beta = coeffs(2);
Or use the analytical formula:
Covariance (RS , RM) / Variance(RM)
Where RS is the return on the stock, and RM is the return on the index
neg_indx = as51r < 0;
as51r_neg = as51r[neg_indx];
bhpr_neg = bhpr[neg_indx];
bhp_beta = cov(as51r_neg, bhpr_neg) / var(as51r_neg);
Please refer to the following MATLAB documentation for more details
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!