Calculating Beta
Calculating Beta
Does anyone here know if MC has a built-in function for calculating the beta between two stocks? Something like what's described here -- https://www.investopedia.com/ask/answer ... g-beta.asp . It's something that's hand-codeable, but if there's an existing function, I'd rather not duplicate the work ...
Re: Calculating Beta
For anyone interested, this is what I hand-coded so far. I think it's right, though I haven't verified it yet:
Code: Select all
input:
length(100);
vars:
return(0),
return_benchmark(0),
sd_security(0),
sd_benchmark(0),
Beta(0);
return = (close of data2 - close of data2[1])/close of data2;
return_benchmark = (close- close[1])/close;
sd_security = StandardDev(return, length, 2);
sd_benchmark = StandardDev(return_benchmark, length, 2);
Beta = Correlation(return, return_benchmark, length) * (sd_security / sd_benchmark);
plot1(Beta);