Open polakowo opened 3 years ago
Hey man, I had the same problem. The way I solved this is by changing this line in timeseries.py
within the actual package:
893 valley = np.argmin(underwater) # end of the period
to:
893 valley = underwater.index[np.argmin(underwater)] # end of the period
I think this is because valley is expected to be a datetime (at least that's what it says in the docs above it), but the actual result that comes from np.argmin(underwater)
is an integer (the index of the drawdown valley). Using this integer to then get the actual datetime allows the function to continue and produce a full tear sheet. No idea if the drawdown numbers are correct, as I'm quite new to trading myself and all the terms, but looks correct
Hope this helps
Thanks. It surprises me that this bug hasn't been fixed yet. Seems like this package isn't actively maintained anymore.
@polakowo Yes, this code (and zipline) doesn't appear to be very actively maintained. FYI, with the following (somewhat outdated) versions:
@cactus1549 I wanted to integrate pyfolio into vectorbt but realized it wasn't worth the effort of adding a library that uses an outdated tech stack. Just implemented the most useful plots from scratch + added interactivity with Plotly.
Yes, @polakowo I think you made the correct decision. I initially thought of using zipline, but was too frustrated by the lack of support. I ended up writing my own ad-hoc backtester but adopting their performance dataframe format thinking I'd be able to use all the analysis tools such as pyfolio, but that's proven a bit of a pain also. Does vectorbt have analysis tools? Would it be relatively easy to switch over?
Also @hirenpatel101, in case anyone wants to continue with pyfolio, I think the future-proof code fix for that line should be:
valley = underwater.index[underwater.values.argmin()]
@cactus1549 vectorbt integrates backtesting and data analysis so it has tons of cool stuff. It doesn't offer all the plots from pyfolio, but it's definitely more flexible in computing/visualizing custom metrics. For example, plotting the distribution of trade returns is as simple as portfolio.trades.returns.histplot()
, where both trades
and trades.returns
consist of numpy arrays, which can be analyzed with other tools.
The complexity of switching over depends upon the use case - vectorbt doesn't implement margin trading and futures yet, neither it implements some complex order management (It ain't a native backtester per se that competes with backtrader and zipline). But as soon as you can represent your orders in an array format, it's very much superior in terms of performance and analysis tools. What has worked for me in the past is prototyping my strategy with vectorbt, doing a final test with another backtester, deploying the strategy, and then again analyzing its performance with vectorbt.
@polakowo, thank you, it does sound interesting. I'll check it out.
Problem Description
I already tried lots of different returns to create a full tear sheet but still cannot get it working, while simple tear sheet works.
Versions