Back to Community
Simplest trading system - First algorithm

Hello everybody,

I'm starting to get familiar with Quantopian, and for a first try I wanted to implement this trading algorithm : http://systemtradersuccess.com/worlds-simplest-trading-system/

Obviously, the objective is not to be the more effecient, but to learn how to build algorithms on Quantopian. That's why I'm sharing my algorithm. Could you please:

  • Criticize my coding styles, my beginner errors, etc
  • Give me hints on how to improve it starting from here
  • Recommend me some lectures or anything else

Thanks a lot, have a nice day :)

Clone Algorithm
36
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 579f32226912201007c0885f
There was a runtime error.
6 responses

I really like this algorithm and your coding style is great! i really like the clear concise comments on your code; they really do help. The only real criticism I have is the performance relative to the SPY500 - this in part causes a low sharpe ratio which is not ideal. Perhaps adding other securities, such as big blue chips (AAPL, GOOG etc) or other ETFs would further lower beta and improve your returns.

Carry on though what you have is great for a first algo! :)

In frequency is says "1d". But it is supposed to me a monthly ma, right?

That 1d refers to the data - it is called every day at the close price. Because you set the schedule_function() function to every month, your code is run every month.

You can change the 1d to one minute if you have a faster strategy that opens and closes trades within a day.

Hello everybody,

Thank you for your answers.

Ricardo, that's why I get history prices on 300 bars (= 300 days, roughly 10 months). If there is a more convenient way to calculate it, please let me know :)

Max, if I understand well, you advise me to try to change my trading system for a long-term based strategy (monthly) to an intraday strategy ? I will give it a try !

Meanwhile, I improved the algorithm to have several securities at once. I know the algorithm has a survival biais, as I used Amazon, Apple and Microsoft. It was just for the example.

Clone Algorithm
36
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 579f9f508b9c6e1001a98856
There was a runtime error.

No, I probably didn't explain myself well! You have just done exactly what I suggested and that data is looking much better! That interpretation could also work, but the moving average may have to be shorter (like 20 or 50 points). Hope that helps!

Hi Théo,

It looks like you're off to a great start! I just wanted to point out that the bar_count in data.history is in business days so a lookback of 300 days is more than a year (13-14 months). There are roughly 21 trading days per month so you might want to use a bar_count of 210.

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.