From d644cda28defc9ab99d43d08bcd46a48bfcdea2a Mon Sep 17 00:00:00 2001 From: ahgnaw Date: Thu, 19 May 2016 10:59:01 -0400 Subject: [PATCH 1/2] Closes #296 --- pyfolio/plotting.py | 3 +-- pyfolio/pos.py | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyfolio/plotting.py b/pyfolio/plotting.py index 686f1ec7..ffb83d7f 100644 --- a/pyfolio/plotting.py +++ b/pyfolio/plotting.py @@ -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])) diff --git a/pyfolio/pos.py b/pyfolio/pos.py index 53db7738..9f3e5956 100644 --- a/pyfolio/pos.py +++ b/pyfolio/pos.py @@ -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): From 12907415ecd871a19bd60e39c35613cc13692168 Mon Sep 17 00:00:00 2001 From: ahgnaw Date: Fri, 20 May 2016 15:53:49 -0400 Subject: [PATCH 2/2] Closes #301 --- pyfolio/pos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfolio/pos.py b/pyfolio/pos.py index 9f3e5956..37c9da2e 100644 --- a/pyfolio/pos.py +++ b/pyfolio/pos.py @@ -62,7 +62,7 @@ def get_long_short_pos(positions): net_liquidation = longs - shorts + cash df_pos = pd.DataFrame({'long': longs.divide(net_liquidation, axis='index'), 'short': shorts.divide(net_liquidation, - axis='index')}) + axis='index')}) df_pos['net exposure'] = df_pos['long'] + df_pos['short'] return df_pos