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

inconsistent days treatment for returns vs pv #235

Closed
drusakov778 opened this issue Dec 14, 2022 · 0 comments
Closed

inconsistent days treatment for returns vs pv #235

drusakov778 opened this issue Dec 14, 2022 · 0 comments

Comments

@drusakov778
Copy link
Contributor

consider the code similar to #233

import pandas as pd
import quantstats as qs

pv_raw = [100, 101, 99, 98, 97, 101, 99]
dates = pd.date_range("2022-12-01", periods=7)
pv = pd.DataFrame(pv_raw, index=dates, columns=["pv"])
vol = qs.stats.volatility(pv)
sharpe = qs.stats.sharpe(pv)

# calculate daily returns, no first day return as since data is daily (assumed EOD) 
rt = pv.pct_change()
rt = rt[1:]
vol2 = qs.stats.volatility(rt)
sharpe2 = qs.stats.sharpe(rt)

printouts

>>> vol[0], vol2[0]
(0.3417106479175939, 0.3742046996695246)
>>> sharpe[0], sharpe2[0]
(-0.9136086220829638, -0.9733213582901914)

volatility, sharpe and almost every other metric differs b/c when calculated from pv quantstats calculates statistics for the one extra first day as well (where returns are NaN). The results differ only a little bit, but it is quite annoying especially when trying to debug and compare results vs external stats valuation

on the other hand, if correct, trimmed returns (like rt above) are supplied to qs.reports.html(), then plots do not start at 0/100% point, which is also confusing

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

2 participants