I'm trying to write a function to calculate the beta between a stock and an index. I have three ranges, the stock returns, the index returns, and the risk free rates.
For the stock returns and the index returns I need to subtract out the risk free rates from each observation. I then calculate the slope of the line that fits the data.
Right now, my function looks like:
I know I need to store Excess Stock Returns and Excess Index Returns as arrays in the function, but I don't know how. Any help would be appreciated.
Thanks!
For the stock returns and the index returns I need to subtract out the risk free rates from each observation. I then calculate the slope of the line that fits the data.
Right now, my function looks like:
Code:
Function Beta(StockReturns As Range, IndexReturns As Range, RiskFreeRates As Range) As Double
Dim ExcessStockReturns As Range
Dim ExcessIndexReturns As Range
Dim Start As Integer
For Start = 1 to StockReturns.Count
ExcessStockReturns = StockReturn.Value - RiskFreeRate.Value
Next Start
For Start = 1 to IndexReturns.Count
ExcessIndexReturns = IndexReturn.Value - RiskFreeRate.Value
Next Start
Beta = WorksheetFunction.Slope(ExcessStockReturns,ExcessIndexReturns)
End Function
I know I need to store Excess Stock Returns and Excess Index Returns as arrays in the function, but I don't know how. Any help would be appreciated.
Thanks!