필터 지우기
필터 지우기

How to compute beta between stock and index returns, when the index returns are negative.

조회 수: 6 (최근 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.

답변 (1개)

Saarthak Gupta
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
  1. https://in.mathworks.com/help/stats/fitlm.html
  2. https://in.mathworks.com/help/stats/fitlm.html
  3. https://in.mathworks.com/help/matlab/ref/polyfit.html
  4. https://in.mathworks.com/help/curvefit/fit.html
  5. https://in.mathworks.com/help/matlab/ref/cov.html
  6. https://in.mathworks.com/help/matlab/ref/var.html
  7. https://in.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html

카테고리

Help CenterFile Exchange에서 Analysis of Variance and Covariance에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by