Skip to content

Commit bdf93a1

Browse files
author
vikram-narayan
committed
MAINT: add flag for if positions are in dollars
1 parent 95b9c8b commit bdf93a1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pyfolio/perf_attrib.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
]
3535

3636

37-
def perf_attrib(returns, positions, factor_returns, factor_loadings):
37+
def perf_attrib(returns, positions, factor_returns, factor_loadings,
38+
pos_in_dollars=True):
3839
"""
3940
Does performance attribution given risk info.
4041
@@ -82,6 +83,10 @@ def perf_attrib(returns, positions, factor_returns, factor_loadings):
8283
TLT -1.066978 0.185435
8384
XOM -1.798401 0.761549
8485
86+
pos_in_dollars : bool
87+
Flag indicating whether `positions` are in dollars or percentages
88+
If True, positions are in dollars.
89+
8590
Returns
8691
-------
8792
tuple of (risk_exposures_portfolio, perf_attribution)
@@ -103,10 +108,13 @@ def perf_attrib(returns, positions, factor_returns, factor_loadings):
103108
2017-01-01 0.249087 0.935925 1.185012 1.185012
104109
2017-01-02 -0.003194 -0.400786 -0.403980 -0.403980
105110
"""
106-
# convert holdings to percentages, and convert positions to long format
107-
positions = get_percent_alloc(positions)
111+
if pos_in_dollars:
112+
# convert holdings to percentages, and convert positions to long format
113+
positions = get_percent_alloc(positions)
114+
108115
# remove cash after normalizing positions
109116
del positions['cash']
117+
110118
positions = positions.stack()
111119
positions.index = positions.index.set_names(['dt', 'ticker'])
112120

0 commit comments

Comments
 (0)