Skip to content

Commit 870b022

Browse files
committed
add turnover_denom para in txn tear sheet
1 parent 85433bd commit 870b022

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pyfolio/plotting.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ def plot_return_quantiles(returns, live_start_date=None, ax=None, **kwargs):
13231323
return ax
13241324

13251325

1326-
def plot_turnover(returns, transactions, positions,
1326+
def plot_turnover(returns, transactions, positions, turnover_denom='AGB',
13271327
legend_loc='best', ax=None, **kwargs):
13281328
"""
13291329
Plots turnover vs. date.
@@ -1345,6 +1345,9 @@ def plot_turnover(returns, transactions, positions,
13451345
positions : pd.DataFrame
13461346
Daily net position values.
13471347
- See full explanation in tears.create_full_tear_sheet.
1348+
turnover_denom : str, optional
1349+
Either AGB or portfolio_value, default AGB.
1350+
- See full explanation in txn.get_turnover.
13481351
legend_loc : matplotlib.loc, optional
13491352
The location of the legend on the plot.
13501353
ax : matplotlib.Axes, optional
@@ -1364,7 +1367,7 @@ def plot_turnover(returns, transactions, positions,
13641367
y_axis_formatter = FuncFormatter(utils.two_dec_places)
13651368
ax.yaxis.set_major_formatter(FuncFormatter(y_axis_formatter))
13661369

1367-
df_turnover = txn.get_turnover(positions, transactions)
1370+
df_turnover = txn.get_turnover(positions, transactions, turnover_denom)
13681371
df_turnover_by_month = df_turnover.resample("M").mean()
13691372
df_turnover.plot(color='steelblue', alpha=1.0, lw=0.5, ax=ax, **kwargs)
13701373
df_turnover_by_month.plot(

pyfolio/tears.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ def create_simple_tear_sheet(returns,
396396
plotting.plot_turnover(returns,
397397
transactions,
398398
positions,
399+
turnover_denom=turnover_denom,
399400
ax=ax_turnover)
400401

401402
plotting.plot_txn_time_hist(transactions, ax=ax_txn_timings)
@@ -691,8 +692,8 @@ def create_position_tear_sheet(returns, positions,
691692

692693
@plotting.customize
693694
def create_txn_tear_sheet(returns, positions, transactions,
694-
unadjusted_returns=None, estimate_intraday='infer',
695-
return_fig=False):
695+
turnover_denom='AGB', unadjusted_returns=None,
696+
estimate_intraday='infer', return_fig=False):
696697
"""
697698
Generate a number of plots for analyzing a strategy's transactions.
698699
@@ -737,6 +738,7 @@ def create_txn_tear_sheet(returns, positions, transactions,
737738
returns,
738739
transactions,
739740
positions,
741+
turnover_denom=turnover_denom,
740742
ax=ax_turnover)
741743

742744
plotting.plot_daily_volume(returns, transactions, ax=ax_daily_volume)

0 commit comments

Comments
 (0)