Skip to content

Commit 7c325a4

Browse files
committed
Merge pull request #201 from quantopian/alloc-denom
BUG use net liquidation value as the denominator in percent allocation calculation
2 parents b3da76d + 1ac5f9e commit 7c325a4

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

pyfolio/pos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_percent_alloc(values):
3434
Positions and their allocations.
3535
"""
3636
return values.divide(
37-
values.abs().sum(axis='columns'),
37+
values.sum(axis='columns'),
3838
axis='rows'
3939
)
4040

@@ -162,7 +162,7 @@ def get_sector_exposures(positions, symbol_sector_map):
162162
positions = positions.drop('cash', axis=1)
163163

164164
unmapped_pos = np.setdiff1d(positions.columns.values,
165-
symbol_sector_map.keys())
165+
list(symbol_sector_map.keys()))
166166
if len(unmapped_pos) > 0:
167167
warn_message = """Warning: Symbols {} have no sector mapping.
168168
They will not be included in sector allocations""".format(

pyfolio/tests/test_pos.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from pandas.util.testing import (assert_frame_equal)
1212

1313
from numpy import (
14-
absolute,
1514
arange,
1615
zeros_like,
1716
)
@@ -40,7 +39,7 @@ def test_get_percent_alloc(self):
4039
result = get_percent_alloc(frame)
4140
expected_raw = zeros_like(raw_data)
4241
for idx, row in enumerate(raw_data):
43-
expected_raw[idx] = row / absolute(row).sum()
42+
expected_raw[idx] = row / row.sum()
4443

4544
expected = DataFrame(
4645
expected_raw,

0 commit comments

Comments
 (0)