-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAINT Make long/short positions match gross leverage #140
Conversation
Am I correct in assuming that this does not yet fix the issue with there still being a cash allocation incorrectly inferred when there is shorting? |
Otherwise looks great! Thanks for the quick turn-around. |
@humdings thanks for that in depth overview. I really do like that boxplot version at the end but I agree it's a bit confusing and overkill for this visualization usecase. Sent from iPhone On Sun, Sep 13, 2015 at 10:08 AM -0700, "David Edwards" notifications@github.com wrote: Yes, I do think you are correct, the problem is that normalizing the data throws everything out of whack when shorting is involved. We can't use the absolute value of the short positions and still have it make sense. Consider a portfolio with 1x leverage that is equally long and short. They sell 50% of the account value and get the cash proceeds, then buy assets with the other 50%. That means the account has 100% of the account value sitting in cash still, but some of it is collateral for the short sales. That cash earns interest and is an important component of a long/short strategy, especially in a high interest environment. I we lose that when normalizing the long/short/cash components because they should equal 200% of the account value if using absolute values. 100% in cash, then 50/50 in long/short stocks. Having this return the dataframe defined on line 59 before the normalizing would be more correct IMO. I don't think the area plot is the best thing for this either. Here are a few plots of a long/short strategy without normalizing the data, the area plot is not very nice, but the density plot, box plot, and histogram capture the distribution of allocations nicely. This area plot is not so intuitive as to what I'm looking at IMO. A density plot captures the allocation distribution well Histograms work too, but it's a bit more cluttered. Box plots are not that pretty, but the information is a least meaningful. — |
I doesn't feel right to me to mess with the cash level honestly. In this particular case if we want the area plot to match up with the gross leverage, we want to exclude the cash altogether. The cash can be inferred from the long/short allocations. Starting with a positions dataframe here is a script that demos what I mean.
So the gross leverage matches up when the cash position is excluded. If we want to compare long vs. short allocations I'd say we don't worry about the cash component since it can be solved for if the leverage and long/short allocations are known. |
@humdings Thanks for the detailed answer. Your last suggestion makes a lot of sense to me. Exclude the cash as it can be inferred from the leverage and have this analysis focus only on long vs. short exposure. In addition, how do you feel about dropping the leverage plot which now is redundant with this one? |
Also interested in what @justinlent thinks about dropping cash. |
+1 @humdings and Thomas. remove cash from the exposure plot since it can be inferred, and yep we can kill off the current Leverage plot in favor of this new Gross Exposure plot Sent from iPhone On Mon, Sep 14, 2015 at 2:43 AM -0700, "Thomas Wiecki" notifications@github.com wrote: Also interested in what @justinlent thinks about dropping cash. — |
That all sounds good to me, I'll update |
This makes `pos.get_long_short_pos` return a dataframe that matches the gross leverage of the portfolio. I removed the `gross_lev` argument since the leverage is dependent on positions dataframe.
Strange, I'll look into it now |
Something seems to have gone wrong with the uploading of the image. |
@humdings can you run the NBs and commit the updated ones? |
193865a
to
bd5b031
Compare
This removes the cash component from `get_long_short_pos` so the plot matches up with the gross leverage of the algo. I also removed the warning about negative cash from `plotting.plot_exposure`
All I did here was run the zipline notebook
bd5b031
to
d3aaee2
Compare
@humdings Can you force pull? I resolved the conflicts. But I still get that issue of an empty plot. Perhaps it's a python 3 issue? |
What exactly do you need me to do? Where am I pulling from and to where? I'm not sure what commands to run. |
|
I'm still getting conflicts, I'll just scrap the repo and clone again |
I'm all up to date but the notebook is barfing now. I get this error when opening the notebook
|
try |
Closing in favor of #147 |
This makes
pos.get_long_short_pos
return a dataframethat matches the gross leverage of the portfolio.
I removed the
gross_lev
argument since the leverage isdependent on positions dataframe.
This PR is addressing #30