tradytics / eiten

Statistical and Algorithmic Investing Strategies for Everyone
https://www.tradytics.com/
GNU General Public License v3.0
2.77k stars 327 forks source link

Provide more advice on how to interpret outputs of portfolio_manager #2

Open hatboysam opened 4 years ago

hatboysam commented 4 years ago

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:

dashed commented 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.

edoreld commented 4 years ago

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

hatboysam commented 4 years ago

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.

tradytics commented 4 years ago

Let me back to you folks with a detailed response. Thanks for asking.

tradytics commented 4 years ago

@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?

hatboysam commented 4 years ago

@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?

jmg17 commented 4 years ago

First thank you. It's very interesting.

Same question as hatboysam about rebalancing : daily, monthly, never?

edoreld commented 4 years ago

For the author to confirm, but in my understanding:

silvavn commented 4 years ago

@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.