Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Permanent Portfolio (Beginner's algorithm to learn the system)

This is implementation of the of the permanent portfolio. Mainly to get started and try few of the features like re-balancing and recording variables.

8 responses

Has anyone tried this algo in minute mode? I've tried, but I continually get a failure at the order statement. (line 14, approx)

Anyone else see this problem?

Thanks,
-mc

I don't see any problem in minute mode (other than losing money...).

Figured it out... my backtest was starting from approx 2008, whereas yours is just the YTD (2013).

I believe my failure was with data not being present for SHY back in '08, but I'd have to do some more digging around.

On to bigger issues... any thoughts on why the algo is so poor? Seems to follow GLD pretty heavily... I'll take a look at recording the weights for each equity next...

Thanks for the algo, and for your minute backtest!
-mc

D. V. Dend

Great work! I've gone and made it a bit more reusable and have added custom weights as well as a cash buffer to stop a dip into leverage.

Feel free for anyone viewing this post to use the algorithm and it works in minute mode of course ;)

-Seong

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Excellent... I like re-useable code.

Quick question about your weights... do you ever use them again after the default? From some prelim quant stuff I've looked at, the weight is a significant portion of many portfolio management algos. They seem to calculate their target weight (based on the target exposure to each security), then put the order in based on the calculated weight. While this may just be semantics, I see it as first making sure that your weight for each security is good before putting in the order... ie, calc the target weight, make sure it is a valid weight (sum wts = 1.0), do some other checks, then finally put in the order once your algo is happy with the weight. Any thoughts on this approach? Am I just splitting hairs at this point?

While I'm posting, figured I'd include a quick snippet for auto-calculating a default weight... it allows you to add securities w/o having to re-set the weights...

    #-- default weight for each equity...  
    context.wt = 1. / len(context.secs)  

Let's keep this development rolling on... anyone else out there with comments / suggestions / concerns?

Performance is still lacking a bit... maybe it's b/c we're comparing to SP500... I'd like to add a custom signal which takes the "hindsight" best portfolio and compares our guesses to it as a proper benchmark for the equities we've choosen.

Thanks,
-mc

Michael,

Thanks for your input, definitely not splitting hairs. I think having a check for whether the weights sum==1 is a good idea and I've put that in here.
The problem with having

context.wt = 1. / len(context.secs)  

is that you can't input specific weights for each security. Although if that's not your goal then it's perfectly fine. In this example, you can put in .50 as a weight for one stock and .50/3 for the rest

Let's keep this going!

Sure thing... let me clarify...

the default weight snippet was just in my initialize function. After that, I figure each security weight would be re-calculated. So it would really be something more like (in pseudo-code):

for each sec:
context.wt(sec) = 1 / len(context.secs)

then in a loop, we'd re-calc each weight based on the target position.

for each sec:
context.wt(sec) = (insert some logic)

which could then place 50% to one security, and 50%/3 to the other three.

-mc

MC,

Do you mean something where the weight of each security changes periodically?

-Seong