santoshlite / EigenLedger

An Open Source Portfolio Backtesting Engine for Everyone | 面向所有人的开源投资组合回测引擎
https://eigenledger.gitbook.io/documentation
Apache License 2.0
950 stars 128 forks source link

Hard-coded Risk-free rate #23

Closed karim1104 closed 3 years ago

karim1104 commented 3 years ago

The risk-free rate is hard-coded in empyrial.py in line 197 (rf = 0.0). Please change it to a variable so we can adjust it as needed.

santoshlite commented 3 years ago

Hey,

You can change that by doing empyrial(your_portfolio, rf=0.1) for example.

Hope it helps

karim1104 commented 3 years ago

Hi Santosh, It worked as a code, but it broke the Sharpe Ratio. When I use "empyrial(portfolio, rf=0.0)", I get a Sharpe Ratio of 1.33 which is realistic. When I use "empyrial(portfolio, rf=0.01)", I get a Sharpe Ratio of -7.06 which is unrealistic.

santoshlite commented 3 years ago

Can you share the whole code please so I can try it out?

karim1104 commented 3 years ago

start_date = datetime.datetime(2010, 1, 1) df = pd.read_csv('Portfolio1.csv')

x = df.to_string(header=False, index=False, index_names=False).split('\n') names = [','.join(ele.split()) for ele in x]

portfolio = Engine(
start_date= start_date, portfolio= names, benchmark = ["SPY"]

)

empyrial(portfolio, rf=0.01)

santoshlite commented 3 years ago

Ok just modified it a little bit with the new version (1.5.5).

Should work now as you can see in this notebook: https://colab.research.google.com/drive/1CKMf1YudMsf8ryD5tOYddVU0fRaQJnWx?usp=sharing

The sharpe ratio is credible. Is it fine?

karim1104 commented 3 years ago

Confirmed it's working fine. Issue is fixed in version 1.5.5.

Thanks!