Skip to content

Commit

Permalink
add turnover_denom para in txn tear sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
huaiweicheng committed Sep 23, 2019
1 parent 85433bd commit 870b022
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pyfolio/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ def plot_return_quantiles(returns, live_start_date=None, ax=None, **kwargs):
return ax


def plot_turnover(returns, transactions, positions,
def plot_turnover(returns, transactions, positions, turnover_denom='AGB',
legend_loc='best', ax=None, **kwargs):
"""
Plots turnover vs. date.
Expand All @@ -1345,6 +1345,9 @@ def plot_turnover(returns, transactions, positions,
positions : pd.DataFrame
Daily net position values.
- See full explanation in tears.create_full_tear_sheet.
turnover_denom : str, optional
Either AGB or portfolio_value, default AGB.
- See full explanation in txn.get_turnover.
legend_loc : matplotlib.loc, optional
The location of the legend on the plot.
ax : matplotlib.Axes, optional
Expand All @@ -1364,7 +1367,7 @@ def plot_turnover(returns, transactions, positions,
y_axis_formatter = FuncFormatter(utils.two_dec_places)
ax.yaxis.set_major_formatter(FuncFormatter(y_axis_formatter))

df_turnover = txn.get_turnover(positions, transactions)
df_turnover = txn.get_turnover(positions, transactions, turnover_denom)
df_turnover_by_month = df_turnover.resample("M").mean()
df_turnover.plot(color='steelblue', alpha=1.0, lw=0.5, ax=ax, **kwargs)
df_turnover_by_month.plot(
Expand Down
6 changes: 4 additions & 2 deletions pyfolio/tears.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def create_simple_tear_sheet(returns,
plotting.plot_turnover(returns,
transactions,
positions,
turnover_denom=turnover_denom,
ax=ax_turnover)

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

@plotting.customize
def create_txn_tear_sheet(returns, positions, transactions,
unadjusted_returns=None, estimate_intraday='infer',
return_fig=False):
turnover_denom='AGB', unadjusted_returns=None,
estimate_intraday='infer', return_fig=False):
"""
Generate a number of plots for analyzing a strategy's transactions.
Expand Down Expand Up @@ -737,6 +738,7 @@ def create_txn_tear_sheet(returns, positions, transactions,
returns,
transactions,
positions,
turnover_denom=turnover_denom,
ax=ax_turnover)

plotting.plot_daily_volume(returns, transactions, ax=ax_daily_volume)
Expand Down

0 comments on commit 870b022

Please sign in to comment.