Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
playing jnug/jdst with 257% return in two years

EMA strategy is used. I am still improving this algo.
Intraday trade only, no margin usage, and maximal 8 transaction allowed in one day.
Any comment is welcomed.

10 responses

Have you live traded this? If so what was your experience? I am working on a JNUG and JDST daytrading algo myself.

Best,
Need4Greed

I tried trading a variant of ths, but somehow he executions I got were not like the backtest. Happy to collaborate on something Gold.. I have a few algo's that did not stand the test of time as the market changed a few times radically

Gotcha. I'd be happy to tell you the strategy I'm working on, I think you could help. I know it works every day over the past two months based on Yahoo finance data (all I have free access to) and hope to backtest further with quantopian.

If you look at JNUG and JDST over the past two months, every day in the mornings they either slope steeply upward or downward. I believe this is due to the unusually high trading volumes that occur in the morning. I have manually backtested a strategy that buys either JNUG or JDST when it moves .6% above open price, and to start protecting gains when it moves .7% above that buy price. I have paper-traded it for a while and it has worked great, but I'm having some issues with the code. Want to help? I'm happy to send you screenshots of the chart trends I've noticed.

happy to help, send me the screenshots and or Quantopian code you have so far

I attached the code. Haven't looked at JDST or trailing stops yet. Would like to send you a picture I marked up to help you visualize the strategy but don't know the best way to do so.

Some of the problems I am having:

  • It is buying and selling different amounts, despite what I tried to code
  • Some days it never executes any of the sell functions

Made some major changes to the code and added a trailing stop loss. Can't figure out why my leverage is getting out of control. Do you think these gains are reasonable?

the lverage is going insane and the main reason would be that you try to try the state but do it inaccuately. In principle you dont have to do this: you look in the positions object what you have and cancel all standing orders and then order again. dont try to count as that is too fragile. I ahve added code to track what you're doing but I dont know what the idea behind the algo is so I'm not able to 'fix' it

Thanks for adding those tools.

An interesting case for seeing leverage move with changes in short share price. The column after INFO below is minute of the day. On the last line, price went from 81.11 to 100.94 and leverage (the number before cash) correspondingly from 2.48 to 7.85.

2016-04-06 12:45 _trac:231 INFO  375   Sell -173 JNUG (-177.0) at 76.54               1.02  cash 26848  47b0  
2016-04-06 12:46 _trac:231 INFO  376      Sold -173 JNUG (-350.0) at 76.44            2.01  cash 40070  47b0  
2016-04-07 06:31 _trac:231 INFO    1   Buy 138 JNUG (-350.0) at 81.96 limit 81.81     2.52  cash 40070  2073  
2016-04-07 07:40 _trac:231 INFO   70      Bot 138 JNUG (-212.0) at 81.68  (-1165) limit 81.81  1.51  cash 28798  2073  
2016-04-07 07:46 _trac:231 INFO   76   Sell -143 JNUG (-212.0) at 81.01               1.48  cash 28798  b2e4  
2016-04-07 07:47 _trac:231 INFO   77      Sold -143 JNUG (-355.0) at 81.11            2.48  cash 40396  b2e4  
2016-04-11 06:34 _trac:231 INFO    4   Buy 45 JNUG (-355.0) at 100.94 limit 100.78    7.85  cash 40396  5606  

On the first line, with leverage of 1.02, there is an order to sell 100% of the portfolio value using order_percent() while the position is already short, at -177 shares, driving leverage to 2.01 the next minute when the sell goes through. The cherry on top is that leverage goes negative sometimes too.
Try replacing the four instances of order_percent() with order_target_percent() as a start.

I added leverage to track_orders here and set its start date to where leverage begins climbing.
Modified the overall N. McGee code quite a bit just to be able to wrap my head around it a little better perhaps.

In addition to the use of order_target_percent() that Blue suggested, the other issue is that your sell order is for -100% instead of 0%, which causes you to go short. Unless I'm misinterpreting things, I'm assuming that you are only intending to take long positions on JNUG. Attached is my correction.

As far as the original post in this thread, the algorithm has promise, but needs some tweaks. The biggest issue is that it starts way too early. If you're using 200/30 EMA crossover, and begin trading at 9:40, over 90% of the data being used is from the previous day, which is no good. It seems like often, JNUG might open at 5% up, but then decline over the first hour. As far as this algorithm is concerned, the short MA is higher than the long MA, so it buys as the price is declining. If you move the start time to an hour, the returns go up to 400%, and the drawdown is reduced by 5-6%. The second issue is the condition for low volatility is too conservative. It misses a lot of good buying opportunities because of breakouts during a period that was considered low volatility at the beginning of the day. Personally, I set support and resistance levels before trading start, and do not allow the algorithm to enter a position if the price is between support and resistance.

I used this algorithm to learn Python and Quantopian, and am live trading one that is inspired by it, but bears little resemblance to it now, though the basic premise is the same. Since starting in June, I've had a couple of really good days (5-10%+ returns), one awful day (lost 7% because of a poorly thought out change), but otherwise not much of anything, as volatility has been relatively low in this timeframe. The good news is that JNUG and JDST are so liquid that I end up getting better results in live trading than I do in backtesting (I backtest every day and compare to the actual results), even with 0% slippage.