Back to Posts
Listen to Thread

I encourage you to press the "Clone Algorithm" button below. That will copy the code into your "My Algorithms" page. You can then hack, edit, tweak, modify, and change it as you see fit. A couple easy changes you can try:

  • Change the sid to a different stock
  • Change the vwap to be a different number of days

You can see how the backtest results change with even tiny code updates.

This very basic algorithm comes from our help documentation. In the backtest object below, click the "Source Code" tab to see the code. Read the comments in that code carefully, and you'll get a good idea how to write an algorithm in Quantopian.

Also, you might find the Video Tutorial helpful. It walks you through the same programming concepts. Watch it on YouTube.

P.S. This algorithm was last updated on 11/13/12.

Clone Algorithm
3578
Loading...
Backtest from to with initial capital ( data)
Cumulative performance:
Algorithm Benchmark
Custom data:
Week
Month
All
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Information Ratio
--
Benchmark Returns
--
Volatility
--
Max Drawdown
--
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
Information Ratio 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
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.

uvxy

svxy

thanks

I have a small question, if you're up 45% with this, why don't you use this to trade in the real world?

Hi Paul,

try cloning the algorithm and play with the following parameters:

  • use a realistic budget
  • use a realistic commission per trade or share
  • trade a different stock
  • trade for a longer timeframe, especially in a time when the APPL stocks didn't skyrocket :)

You will likely notice, that the algorithm will barely outperform the benchmark.

-Chris

Similar strategy with different parameters for trading SPY(SPDR S&P 500 ETF TRUST).

Clone Algorithm
167
Loading...
Backtest from to with initial capital ( data)
Cumulative performance:
Algorithm Benchmark
Custom data:
Week
Month
All
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Information Ratio
--
Benchmark Returns
--
Volatility
--
Max Drawdown
--
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
Information Ratio 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
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.

if you're up 45% with this, why don't you use this to trade in the
real world?

This algorithm suffers from bias - in retrospect, Apple was a great pick. But there's no way for me to know that will be true going forward.

I will say that the commission is realistic, and it works in different budgets, too. But the "apple-went-up-tons" bias make this a terrible idea as an actual production algorithm.

Hi Dan,

Momentum trading is a good idea. It's one of the great huristics. By using S&P 500 ETF(same with the benchmark) and a 11-year backtest, this heuristic is confirmed again.

Di Chen

My sense is that there is a strong bias in a lot of the algorithms cooked up on Quantopian, with backtests that include the 2008-2009 collapse. My own experience is that it is relatively easy to devise an algorithm that avoids the downturn...the problem is that the algorithm either tracks the market or under-performs it under normal conditions. Di Chen's algorithm gains mostly by avoiding the 2008-2009 market drop, but then appears to track the market...so, it is not obvious that it would be a good choice to use for future trading. --Grant

Hi guys, I'm new to this platform and have been playing around with some simple scripts. Is there a way to apply some sort of a tax rate to the dividends received in the portfolio, since dividends are taxed differently from trading or capital gains?

Dominic,

Dividends aren't directly accessible in back-testing (more information here), however they are accounted for in overall returns (except special dividends)

This version has better performance. What I like is 12.3% max drawdown. But it can't beat the benchmark during 2009 - 2013.

Clone Algorithm
167
Loading...
Backtest from to with initial capital ( data)
Cumulative performance:
Algorithm Benchmark
Custom data:
Week
Month
All
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Information Ratio
--
Benchmark Returns
--
Volatility
--
Max Drawdown
--
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
Information Ratio 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
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.

I don't believe the strategy is behaving as you'd expect, as illustrated by its NAV and the Notional it is trading.

Also note that the min notional was changed to -100,000 vs. -1,000,000.

Clone Algorithm
18
Loading...
Backtest from to with initial capital ( data)
Cumulative performance:
Algorithm Benchmark
Custom data:
Week
Month
All
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Information Ratio
--
Benchmark Returns
--
Volatility
--
Max Drawdown
--
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
Information Ratio 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
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.

Going short is much riskier than going long. So I changed the min notional.

hi all, just a thought, anyone thought of making the number of stocks which are short and long variable and can be calculated by a tracker? say if the tracker spots the trend moving up, it will put more stocks in long rather than short

Ivan, do you mind putting this on a new thread by itself?

Log in to reply to this thread.
Not a member? Sign up!