Skip to content

Commit d644cda

Browse files
committed
Closes #296
1 parent 9c5ea8a commit d644cda

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pyfolio/plotting.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -911,9 +911,8 @@ def plot_exposures(returns, positions_alloc, ax=None, **kwargs):
911911
ax = plt.gca()
912912

913913
df_long_short = pos.get_long_short_pos(positions_alloc)
914-
915914
df_long_short.plot(
916-
kind='area', color=['lightblue', 'green'], alpha=1.0,
915+
kind='line', style=['-g', '-r', '--k'], alpha=1.0,
917916
ax=ax, **kwargs)
918917
df_cum_rets = timeseries.cum_returns(returns, starting_value=1)
919918
ax.set_xlim((df_cum_rets.index[0], df_cum_rets.index[-1]))

pyfolio/pos.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ def get_long_short_pos(positions):
5757

5858
pos_wo_cash = positions.drop('cash', axis=1)
5959
longs = pos_wo_cash[pos_wo_cash > 0].sum(axis=1).fillna(0)
60-
shorts = pos_wo_cash[pos_wo_cash < 0].abs().sum(axis=1).fillna(0)
60+
shorts = pos_wo_cash[pos_wo_cash < 0].sum(axis=1).fillna(0)
6161
cash = positions.cash
6262
net_liquidation = longs - shorts + cash
63-
df_long_short = pd.DataFrame({'long': longs,
64-
'short': shorts})
65-
66-
return df_long_short.divide(net_liquidation, axis='index')
63+
df_pos = pd.DataFrame({'long': longs.divide(net_liquidation, axis='index'),
64+
'short': shorts.divide(net_liquidation,
65+
axis='index')})
66+
df_pos['net exposure'] = df_pos['long'] + df_pos['short']
67+
return df_pos
6768

6869

6970
def get_top_long_short_abs(positions, top=10):

0 commit comments

Comments
 (0)