Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set risk free rate as a pd.Series #257

Open
superopaz opened this issue Dec 20, 2024 · 0 comments
Open

set risk free rate as a pd.Series #257

superopaz opened this issue Dec 20, 2024 · 0 comments

Comments

@superopaz
Copy link

superopaz commented Dec 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant