determine monthly risk free rate

Viewed 33

i have the following problem. i want to determine the monthly risk-free rate using 10 years of data of a bond. I think it would make sense to use the same approach to the risk-free rate as you would do for a random stock. My question is, is the below code the right approach to find the risk-free rate

import datetime
import yfinance as yf
import numpy as np

start_daterf = datetime.date(2000, 1, 1)
end_daterf = datetime.date(2010, 1, 31)
risikofrie = yf.download('^TNX', start=start_daterf, end=end_daterf)
risikofrie =  risikofrie['Adj Close'].dropna()
rf = (((risikofrie.resample('M').sum().apply(lambda x: np.log(1 + x)).mean()))/12)/100
print(rf)

this is a part of a larger problem i'm doing where i'm using the risk-free rate together with 3 stocks. I'm finding logreturns of the 3 stocks, thus i believe the same approach should be applied to the risk-free rate, however i have doubts if i am doing it right.

Thanks in advance

0 Answers
Related