Skip to content

Commit ef516e9

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

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pyfolio/plotting.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ def plot_capacity_sweep(returns, transactions, market_data,
15201520
return ax
15211521

15221522

1523-
def plot_daily_turnover_hist(transactions, positions,
1523+
def plot_daily_turnover_hist(transactions, positions, turnover_denom='AGB',
15241524
ax=None, **kwargs):
15251525
"""
15261526
Plots a histogram of daily turnover rates.
@@ -1533,6 +1533,9 @@ def plot_daily_turnover_hist(transactions, positions,
15331533
positions : pd.DataFrame
15341534
Daily net position values.
15351535
- See full explanation in tears.create_full_tear_sheet.
1536+
turnover_denom : str, optional
1537+
Either AGB or portfolio_value, default AGB.
1538+
- See full explanation in txn.get_turnover.
15361539
ax : matplotlib.Axes, optional
15371540
Axes upon which to plot.
15381541
**kwargs, optional
@@ -1546,7 +1549,7 @@ def plot_daily_turnover_hist(transactions, positions,
15461549

15471550
if ax is None:
15481551
ax = plt.gca()
1549-
turnover = txn.get_turnover(positions, transactions)
1552+
turnover = txn.get_turnover(positions, transactions, turnover_denom)
15501553
sns.distplot(turnover, ax=ax, **kwargs)
15511554
ax.set_title('Distribution of daily turnover rates')
15521555
ax.set_xlabel('Turnover rate')

pyfolio/tears.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,9 @@ def create_txn_tear_sheet(returns, positions, transactions,
710710
transactions : pd.DataFrame
711711
Prices and amounts of executed trades. One row per trade.
712712
- See full explanation in create_full_tear_sheet.
713+
turnover_denom : str, optional
714+
Either AGB or portfolio_value, default AGB.
715+
- See full explanation in txn.get_turnover.
713716
unadjusted_returns : pd.Series, optional
714717
Daily unadjusted returns of the strategy, noncumulative.
715718
Will plot additional swippage sweep analysis.
@@ -744,7 +747,9 @@ def create_txn_tear_sheet(returns, positions, transactions,
744747
plotting.plot_daily_volume(returns, transactions, ax=ax_daily_volume)
745748

746749
try:
747-
plotting.plot_daily_turnover_hist(transactions, positions,
750+
plotting.plot_daily_turnover_hist(transactions,
751+
positions,
752+
turnover_denom=turnover_denom,
748753
ax=ax_turnover_hist)
749754
except ValueError:
750755
warnings.warn('Unable to generate turnover plot.', UserWarning)

0 commit comments

Comments
 (0)