What the Beta is?
Beta is a numeric value that measures the fluctuations of a stock to the changes in the overall stock market. It is a measure of the volatility, or systematic risk, of a security or a portfolio in comparison to the market as a whole.
Beta is used in the capital asset pricing model (CAPM), a model that calculates the expected return of an asset based on its beta and expected market returns.
CalculatingBeta in R

Downloading the data from Quandl

Check the structure:

As the intersect function can only be applied to two vectors, we call the Reduce function to identify the common dates in the three time series:

Now, let us simply filter all three data frames to the relevant cells to get the vectors:

After cleaning the data, we have to calculate the logreturns and risk premium. Creating a function to do so:

Once we have both time series; the individual asset’s (MRF) and the official Interest rate of India (BCB/17901), beta can be calculated as:

The regression coefficients obtained as:
Notice the coefficient of risk_premium and the one obtained by ratio of covariance are same which is beta calculated.

Plotting, the Security Characteristic Line (SCL) is obtained as follows:

Details of line fit: