quantopian / pyfolio

Portfolio and risk analytics in Python
https://quantopian.github.io/pyfolio
Apache License 2.0
5.66k stars 1.77k forks source link

260 Day years? #559

Open smalldatascaled opened 6 years ago

smalldatascaled commented 6 years ago

Hi, trying to run a simple tear sheet and am getting weird results.

code that I am running is simply pf.create_returns_tear_sheet(stock_rets['rtn'],benchmark_rets=bm_rets['rtn'])

I have attached my stock returns and benchmark returns.

Problem is that there is only a year's worth of data but the tear sheet is calculating everything based on 17 months:

Start date 2017-07-31 End date 2018-07-31 Total months 17

backtest.zip

I'm guessing that its using a 260 day year?

twiecki commented 6 years ago

The code is dividing len(returns) / 21, did you include weekends in your returns?

smalldatascaled commented 6 years ago

Yeah I did include weekends - I'm looking at global markets, and so some markets are open on weekends (middle eastern in particular), plus the currencies move over the weekend plus when we measure from different time zones we get either Saturday returns (eg measuring Friday US returns from Australia/Japan) or Sunday.

I removed weekends and it works fine.

Maybe you would be better dividing by max(date)-min(date)? That might help for irregular data as well.

twiecki commented 6 years ago

We should just pandas' functionality, something like (end - start).months. Pull request welcome.