ENH: add plot_risk_exposures#433
Conversation
pyfolio/perf_attrib.py
Outdated
| [perf_attrib_data[s] for s in chain(perf_attrib_data.iloc[:, :-3], | ||
| ['specific_returns'])], | ||
| labels=list(perf_attrib_data.iloc[:, :-3]) + ['specific returns'] | ||
| labels=list(perf_attrib_data.iloc[:, :-3]) + ['specific returns'], |
There was a problem hiding this comment.
why are the last three dropped?
There was a problem hiding this comment.
the last three columns are total_returns, common_returns, and specific_returns, and common returns are accounted for by each of the individual factor returns
There was a problem hiding this comment.
maybe perf_attrib_data.drop(['total_returns', ...], axis='columns') then to make the intent more clear?
| momentum reversal | ||
| dt | ||
| 2017-01-01 -0.238655 0.077123 | ||
| 2017-01-02 0.821872 1.520515 |
bdf93a1 to
e23c558
Compare
pyfolio/perf_attrib.py
Outdated
| positions = get_percent_alloc(positions) | ||
|
|
||
| # remove cash after normalizing positions | ||
| del positions['cash'] |
There was a problem hiding this comment.
Perhaps positions.drop('cash', axis='columns') instead?
pyfolio/utils.py
Outdated
|
|
||
| def set_legend_location(ax): | ||
| """ | ||
| Put legend in right of plot instead of overlapping with the it. |
There was a problem hiding this comment.
Typo instead of overlapping with the it.
| """ | ||
| Plot total, specific, and common returns. | ||
|
|
||
| Parameters |
There was a problem hiding this comment.
Also document returns, specific_returns and common_returns
|
See feedback from @eigenfoo but looks good otherwise. |
|
@yankees714 mind taking a look when you can? |
pyfolio/perf_attrib.py
Outdated
| '#b380ff', '#e0e6ac', '#a253a6', '#418020', '#ff409f', | ||
| '#ffa940', '#83ff40', '#3d58f2', '#e3ace6', '#d9a86c', | ||
| '#2db391' | ||
| ] |
There was a problem hiding this comment.
Would it make sense to put this in pyfolio.utils?
There was a problem hiding this comment.
yup, I'll move it there
pyfolio/perf_attrib.py
Outdated
| # convert holdings to percentages, and convert positions to long format | ||
| positions = get_percent_alloc(positions) | ||
| if pos_in_dollars: | ||
| # convert holdings to percentages, and convert positions to long format |
There was a problem hiding this comment.
What does 'convert positions to long format' mean here?
There was a problem hiding this comment.
that part of the comment applies to the line positions = positions.stack(), it means change it from wide format:
AAPL TLT XOM
2017-01-01 0.333333 0.568627 0.098039
2017-01-02 0.188034 0.658120 0.153846
2017-01-03 -0.263158 0.473684 0.526316
to long format (everything in one column with a multi index)
2017-01-01 AAPL 0.333333
TLT 0.568627
XOM 0.098039
2017-01-02 AAPL 0.188034
TLT 0.658120
XOM 0.153846
2017-01-03 AAPL -0.263158
TLT 0.473684
XOM 0.526316
I'll change that comment to be in the right place
|
I'll squash commits, and then merge |
e170ed2 to
11bfe08
Compare
11bfe08 to
7c7acff
Compare
|
once tests pass, I'll merge |
plot risk factor exposures:

add flag
pos_in_dollarstoperf_attribindicating whether positions are in dollars or not (for performance attribution does not work correctly when percentages are passed in #439)