Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
a-campbell committed Oct 16, 2015
1 parent 80e99be commit 86405e9
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions pyfolio/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,8 @@ def plot_turnover(returns, transactions, positions,


def plot_slippage_sweep(returns, transactions, positions,
slippage_params=None, ax=None, **kwargs):
slippage_params=(3, 8, 10, 12, 15, 20, 50),
ax=None, **kwargs):
"""Plots a equity curves at different per-dollar slippage assumptions.
Parameters
Expand All @@ -1060,10 +1061,10 @@ def plot_slippage_sweep(returns, transactions, positions,
transactions : pd.DataFrame
Daily transaction volume and dollar ammount.
- See full explanation in tears.create_full_tear_sheet.
positions : pd.DataFrame
positions : pd.DataFrame
Daily net position values.
- See full explanation in tears.create_full_tear_sheet.
slippage_params: list
slippage_params: tuple
Slippage pameters to apply to the return time series (in
basis points).
ax : matplotlib.Axes, optional
Expand All @@ -1081,9 +1082,7 @@ def plot_slippage_sweep(returns, transactions, positions,
ax = plt.gca()

turnover = txn.get_turnover(transactions, positions,
period=None, average=False)
if slippage_params is None:
slippage_params = [3, 8, 10, 12, 15, 20, 50]
period='D', average=False)

slippage_sweep = pd.DataFrame()
for bps in slippage_params:
Expand All @@ -1094,8 +1093,7 @@ def plot_slippage_sweep(returns, transactions, positions,
slippage_sweep.plot(alpha=1.0, lw=0.5, ax=ax)

ax.set_title('Cumulative Returns Given Per-Dollar Slippage Assumption')
df_cum_rets = timeseries.cum_returns(returns, starting_value=1)
ax.set_xlim((df_cum_rets.index[0], df_cum_rets.index[-1]))

ax.legend(loc='center left')

return ax
Expand All @@ -1113,9 +1111,9 @@ def plot_slippage_sensitivity(returns, transactions, positions,
transactions : pd.DataFrame
Daily transaction volume and dollar ammount.
- See full explanation in tears.create_full_tear_sheet.
slippage_params: list
Slippage pameters to apply to the return time series (in
basis points).
positions : pd.DataFrame
Daily net position values.
- See full explanation in tears.create_full_tear_sheet.
ax : matplotlib.Axes, optional
Axes upon which to plot.
**kwargs, optional
Expand All @@ -1135,17 +1133,16 @@ def plot_slippage_sensitivity(returns, transactions, positions,
avg_returns_given_slippage = pd.Series()
for bps in range(1, 100):
adj_returns = txn.adjust_returns_for_slippage(returns, turnover, bps)
avg_returns = timeseries.sharpe_ratio(
adj_returns, returns_style='calendar')
avg_returns = timeseries.annual_return(
adj_returns, style='calendar')
avg_returns_given_slippage.loc[bps] = avg_returns

avg_returns_given_slippage.plot(alpha=1.0, lw=2, ax=ax)

ax.set_title('Average Annual Returns Given Per-Dollar Slippage Assumption')
# ax.tick_params(axis='x', which='major', labelsize=10)
ax.set_xticks(np.arange(0, 100, 10))
ax.set_ylabel('Average Annual Return')
ax.set_xlabel('Per-Dollar Slippage (bps)')
ax.set(title='Average Annual Returns Given Per-Dollar Slippage Assumption',
xticks=np.arange(0, 100, 10),
ylabel='Average Annual Return',
xlabel='Per-Dollar Slippage (bps)')

return ax

Expand Down

0 comments on commit 86405e9

Please sign in to comment.