Skip to content

Commit

Permalink
Merge pull request #201 from quantopian/alloc-denom
Browse files Browse the repository at this point in the history
BUG use net liquidation value as the denominator in percent allocation calculation
  • Loading branch information
twiecki committed Nov 12, 2015
2 parents b3da76d + 1ac5f9e commit 7c325a4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pyfolio/pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_percent_alloc(values):
Positions and their allocations.
"""
return values.divide(
values.abs().sum(axis='columns'),
values.sum(axis='columns'),
axis='rows'
)

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

unmapped_pos = np.setdiff1d(positions.columns.values,
symbol_sector_map.keys())
list(symbol_sector_map.keys()))
if len(unmapped_pos) > 0:
warn_message = """Warning: Symbols {} have no sector mapping.
They will not be included in sector allocations""".format(
Expand Down
3 changes: 1 addition & 2 deletions pyfolio/tests/test_pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from pandas.util.testing import (assert_frame_equal)

from numpy import (
absolute,
arange,
zeros_like,
)
Expand Down Expand Up @@ -40,7 +39,7 @@ def test_get_percent_alloc(self):
result = get_percent_alloc(frame)
expected_raw = zeros_like(raw_data)
for idx, row in enumerate(raw_data):
expected_raw[idx] = row / absolute(row).sum()
expected_raw[idx] = row / row.sum()

expected = DataFrame(
expected_raw,
Expand Down

0 comments on commit 7c325a4

Please sign in to comment.