Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why unusually high result?

Hi I copied sample algorithm and changed amount to 10,000. My returns are 4360%. What is wrong ?

3 responses

I mean that seams impossible

It seems like you have a very leveraged position. You are trading with the assumption of $10,000 of initial capital, but you are allowing the algorithm to take positions as large as $1,000,000 (this is the line of code 'context.max_notional = 1000000.1').

I'm not sure if you are familiar with how leverage works, but it multiplies both your gains and losses. A quick example: I buy a stock that trades for $10 a share using all cash. It goes up to $10.10, and I sell it. I make a 1% profit. If it goes down to $9.90 and I sell it, I have a 1% loss. Now let's assume that instead of buying 1 share for $10, I buy 100 shares for a total cost of $1,000. I still only have $10 though, so I borrow the remaining $990. Now the stock goes up to $10.10 and I sell it. I have 100 shares, so I receive $1,010. I pay back the $990 loan and I have $20 left, so I had returns of 100%. If the stock falls to $9.90 and I sell, I receive $990 in cash. I pay back the loan, and now I have nothing left over. I had a 100% loss.

So as you can see, when I borrowed money to take a position 100x my initial capital (as your algorithm is doing), I went from a 1% loss or gain to a 100% loss or gain. That's why your returns are so high. If you change the line of code to be 'context.max_notional = 10000.1', you should see returns of about 43%. Still great, but not quite as unbelievable.

Hi Gaurav,

Sam's explanation is accurate. In the attached example I've edited two things about this algo to make it a little more robust. (1) I've added a basic margin model (courtesy of this post from David Edwards), this model calculates a running estimate of the margin requirement for the account, I have added a custom plot to show that value, I added a warning statement that will print when the margin requirement exceeds 90% of the portfolio value - you could adjust this. (2) I switched from using the flat order() method, which obviously doesn't scale with your initial capital base, to using order_target_percent() which will allocate a fixed percentage of your portoflio to each position -- this does scale with capital base.

Take a look at this and let me know if you have any questions! Best, Jess

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.