Skip to content

Commit

Permalink
Merge pull request #301 from ahgnaw/master
Browse files Browse the repository at this point in the history
Closes #296
  • Loading branch information
twiecki committed May 25, 2016
2 parents 9c5ea8a + 1290741 commit bb721df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 1 addition & 2 deletions pyfolio/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,8 @@ def plot_exposures(returns, positions_alloc, ax=None, **kwargs):
ax = plt.gca()

df_long_short = pos.get_long_short_pos(positions_alloc)

df_long_short.plot(
kind='area', color=['lightblue', 'green'], alpha=1.0,
kind='line', style=['-g', '-r', '--k'], alpha=1.0,
ax=ax, **kwargs)
df_cum_rets = timeseries.cum_returns(returns, starting_value=1)
ax.set_xlim((df_cum_rets.index[0], df_cum_rets.index[-1]))
Expand Down
11 changes: 6 additions & 5 deletions pyfolio/pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ def get_long_short_pos(positions):

pos_wo_cash = positions.drop('cash', axis=1)
longs = pos_wo_cash[pos_wo_cash > 0].sum(axis=1).fillna(0)
shorts = pos_wo_cash[pos_wo_cash < 0].abs().sum(axis=1).fillna(0)
shorts = pos_wo_cash[pos_wo_cash < 0].sum(axis=1).fillna(0)
cash = positions.cash
net_liquidation = longs - shorts + cash
df_long_short = pd.DataFrame({'long': longs,
'short': shorts})

return df_long_short.divide(net_liquidation, axis='index')
df_pos = pd.DataFrame({'long': longs.divide(net_liquidation, axis='index'),
'short': shorts.divide(net_liquidation,
axis='index')})
df_pos['net exposure'] = df_pos['long'] + df_pos['short']
return df_pos


def get_top_long_short_abs(positions, top=10):
Expand Down

0 comments on commit bb721df

Please sign in to comment.