Using FFN, I set the risk free rate as a Series but the Sharpe Ratio is considerably different from the one calculated just with a float number, even if the Series of risk free rates is equal to the float.
for example:
import pandas as pd
import numpy as np
import ffn
float_rf = 0.02
single_rf = ((1+float_rf)**(1/12))-1
rf = pd.Series(np.repeat(single_rf, 13),name="rf")
time = pd.date_range(pd.Timestamp(2024,1,31), periods=12, freq="1m")
time = pd.Series(time)
time.loc[-1] = pd.Timestamp(2024,1,1)
time.index = time.index + 1
time = time.sort_index()
price = pd.Series([100,101.5,102.9,103.6,104.6,105.8,105.4,105.7,106.6,107.5,108.1,108.7,109.9], name="price")
book = pd.DataFrame([price,rf]).transpose()
book = book.set_index(time)
STATS_1 = ffn.core.PerformanceStats(book["price"], rf=float_rf, annualization_factor=12)
STATS_1.display()
STATS_2 = ffn.core.PerformanceStats(book["price"], rf=book["rf"], annualization_factor=12)
STATS_2.display()
STATS_1 uses 2% as risk free, while STATS_2 uses a series of montlhy risk free rates calculated from a annual 2% risk free rate.
Since the risk free rate used in the Series is identical to the float number, the calculation of the Sharpe ratio should be the same for both methods.
Paul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.