pyfolio
pyfolio copied to clipboard
Inconsistent Turnover Calculations
We have a turnover function in pos.py, but plotting.plot_turnover() does not use it. Also, the two calculations are done differently.
# plotting.plot_turnover
df_turnover = transactions.txn_volume / positions.abs().sum(axis='columns')
# pos.turnover
turnover = transactions_df.apply(
lambda z: z.apply(
lambda r: abs(r))).resample(period, 'sum').sum(axis=1)
portfolio_value = backtest_data_df.portfolio_value.resample(period, 'mean')
turnoverpct = turnover / portfolio_value
These two calculations do not produce the same output