Open hatboysam opened 4 years ago
I'm also curious what negative weights mean for when only_long=1
.
Some of the weights exceed 100%, which, I assume, the use of leverage/margin loans will make that a possibility.
Some info about the negative weights:
"So the negative weights are just ignored during the forward and back tests. They are there just to show you the raw portfolios without any filtering." 1
From the link @edoreld posted:
So the negative weights are just ignored during the forward and back tests. They are there just to show you the raw portfolios without any filtering. As for the other question, the weights are just proportions of your money that you should put in each stock. If a weight is negative, that means just short with that proportion. You can simply normalize the weights to sum up to one if it's harder to read them without them being normalized.
So reading that correctly let's say I put in 5 stocks and get the following weights:
A: 0.5
B: 1.0
C: -1.0
D: 2.0
E: 0.5
If I am long-only I can throw away C, it shouldn't be in my portfolio at all. So if I normalize the weights:
A: 0.125
B: 0.25
(no C)
D: 0.5
E: 0.125
So for a $1000 portfolio that would be:
A: $125
B: $250
D: $500
E: $125
I think an example like that would be really helpful in the README! Or better yet, add a --portfolio-principal
flag to the command to turn everything into real dollars.
Let me back to you folks with a detailed response. Thanks for asking.
@hatboysam - this is a perfect example so thanks a lot for sharing.
So when is_long is set to 1, the weights are not constrained during optimization but during back and forward testing. When you build a long only portfolio, you can simple ignore the negative weights because that is what's happening during the testing.
As for an example, I think @hatboysam has a pretty good one, that's exactly how everything is working right now. I would let someone else add a PR though if there is any interest in adding an example in the readme?
@tradytics happy to do a PR but I actually don't understand how weights would work if short positions are allowed. Let's use the above example again. Would all of the long positions stay the same and I'd just add a $250 short position to the portfolio? Or would the size of all positions change?
Also a follow up from my original question: does the algorithm assume rebalancing at any point or are these pure buy-and-hold portfolios?
First thank you. It's very interesting.
Same question as hatboysam about rebalancing : daily, monthly, never?
For the author to confirm, but in my understanding:
If you allow short positions, then yes, you would short the stock with -1.0 weight with $250 as per your example.
I think rebalancing is up for you to do. If you want to rebalance monthly, then you would run the algorithm monthly and adjust your portfolio accordingly.
@hatboysam if you just want to use longs, you can discard negative values and the weights would be the same. Likewise if you just want to use shorts. If you want to use both, just sum up the positive then sum up the absolute of the negatives. the sum of positives plus the sum of abs negatives is the total weight. Divide each part by the total weight and you will get the money proportion for longs and shorts. Now you can easily find the money allocation by dividing each positive weight by the sum of positives and so on...
As @edoreld correctly mentioned, this algorithm does NOT consider re-balancing as of right now. You woud have to run it in shorter periods of time to find how to rebalance your portfolio.
First of all thank you! This tool was so easy to get up and running, despite the obvious underlying complexity.
After running
portfolio_manager.py
on a few different stock lists I am left with the following simple questions:README
only explains the former, I am having trouble interpreting the latter. They seem to be wildly different!