Seeking help with correcting pnl calculations within pyfolio round_trips.py in order to correct the round_trip_tear_sheet for futures backtesting.
First, I ran a 50/100, 25 day breakout version of Andreas Clenow's core trend code from Trading Evolved with Norgate futures data and a $500k capital base, returning 11.1% annually and 635% cumulative.
When I run create_round_trip_tear sheet - the key pnl stats look like this - clearly a problem with how profit and loss is being calculated.
Digging under the hood to understand how pnl is being calculated, I ran the following code to view the extract_round_trips function:
We can see from this table that pnl is incorrect - and digging in to round_trips.py code and the transactions from perf, pnl is being calculated as follows:
pnl += -(price + prev_price)
and is not applying asset price_multipliers for futures.
The following github links address this, and outline a code fix in pos.py, but that fix doesn't apply in round_trips.py:
Hi Everyone,
Seeking help with correcting pnl calculations within pyfolio round_trips.py in order to correct the round_trip_tear_sheet for futures backtesting.
First, I ran a 50/100, 25 day breakout version of Andreas Clenow's core trend code from Trading Evolved with Norgate futures data and a $500k capital base, returning 11.1% annually and 635% cumulative.
When I run create_round_trip_tear sheet - the key pnl stats look like this - clearly a problem with how profit and loss is being calculated.
Digging under the hood to understand how pnl is being calculated, I ran the following code to view the extract_round_trips function:
import pyfolio as pf
returns, positions, transactions = pf.utils.extract_rets_pos_txn_from_zipline(perf)
Correct dt error per https://github.com/quantopian/pyfolio/issues/509
transactions.drop(['dt'], axis=1, inplace=True)
rts = pf.round_trips.extract_round_trips(transactions)
rts.head()
We can see from this table that pnl is incorrect - and digging in to round_trips.py code and the transactions from perf, pnl is being calculated as follows:
pnl += -(price + prev_price)
and is not applying asset price_multipliers for futures.
The following github links address this, and outline a code fix in pos.py, but that fix doesn't apply in round_trips.py:
https://github.com/quantopian/pyfolio/issues/570
https://github.com/quantopian/pyfolio/pull/571
Take care, Ben