Analyzer (pyfolio) for intraday trades
-
Hi all,
BACKGROUND:
I have a strategy that ingests tick data (on a microsecond interval). I resample these data to daily bars to calculate my technical indicators (e.g. moving average). See the code below which indicates my two data sources (
self.data/self.data0
represents tick level data andself.data1
represents daily bar data):datapath = os.path.join(os.getcwd(), 'input_data/EURUSD_tick_data.csv') datac = bt.feeds.GenericCSVData(dataname = datapath, fromdate = datetime.datetime(2021, 1, 3), todate = datetime.datetime(2021, 1, 8), dtformat=('%Y%m%d'), tmformat=('%H:%M:%S:%f'), timeframe=bt.TimeFrame.MicroSeconds, compression=1, date=0, time=1, open=2, high=3, low=2, close=3, volume=4, openinterest=-1 ) cerebro = bt.Cerebro(exactbars = False) cerebro.replaydata(datac, timeframe=bt.TimeFrame.MicroSeconds, compression=1, name='data') datac.plotinfo.plotmaster = datac cerebro.replaydata(datac, timeframe=bt.TimeFrame.Days, compression=1, name='data1')
The logic of my strategy is not that important for this inquiry, however, note that
self.data
is used to make trades (thereforedef next()
is triggered each tick and trades are executed at a tick level). Even though the technical indicators are calculated on daily bar data, the trades are executed every tick.MY QUESTION:
Although my strategy runs end-to-end and I can get a plot after my execution, I want to calculate additional performance measures.
I have tried the following to get
pyfolio
tear sheets, however, it seems like it struggles with intraday trades. Is there a analyzer (or pyfolio if im using it wrong) to output performance measures for intraday trades.results = cerebro.run() strat = results[0] pyfoliozer = strat.analyzers.getbyname('pyfolio') returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items() import pyfolio as pf pf.create_simple_tear_sheet(returns) pf.create_returns_tear_sheet(returns)
-
I am investigating quantstats a bit. Seems to fulfill the needs for intra-day trades (on a tick level).
-
Some code I am experimenting with
results = cerebro.run() strat = results[0] pyfoliozer = strat.analyzers.getbyname('pyfolio') returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items() returns.index = returns.index.tz_convert(None) # Plot the result cerebro.plot(iplot=False) import pandas as pd import quantstats quantstats.reports.html(returns, output='stats.html', title='Strategy naive')