Back to Community
The Gold King And His Knights

There are a multitude of tweaks to the "Bottom Feeder Bandit". Now this is dubbed, "The Gold King And His Knights".
It seems to do extraordinarily well except when the stock market keeps hitting all-time record highs. I'm guessing here. I didn't "check my facts". This one shows great potential though.

Clone Algorithm
300
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: 578670d22b10410f8ff94d77
There was a runtime error.
198 responses

Found some major bugs in my logic. More thorough backtesting to follow. But the fixes are already in here.

Clone Algorithm
300
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: 57881d8fcbbcb90f87c56331
There was a runtime error.

Charles,

I have not looked at the logic of your algo or assessed its returns, but I am a big fan of the naming conventions. Every algo deserves a good title....

Ok, so here is a backtest similar time span as the original. I gotta research what is fundamentally different starting Jan 2013. I suspect that gold does horrible after that point because of the stock market doing so well. It's also interesting that something about the mechanics of my original flawed logic was causing noticeably better results during the time before Jan 2013. Things that make you go hmmmm.

Clone Algorithm
300
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: 5788b9b6b9df9c11f891da8d
There was a runtime error.

I have made alot of tweaks here. Big improvement I think. Still considering what to do about April 2013 forward.

Clone Algorithm
300
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: 5788f53c480f1811fd093955
There was a runtime error.

Ok, a huge improvement here. Room for more improvement obviously.

Clone Algorithm
300
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: 578a184663699512a3fc78dc
There was a runtime error.

Charles ,

If you replace GLD by TLT you will get The Bond King And His Knights.
Inspired by Anthony FJ Garner post.
Who is the King of Kings?

Clone Algorithm
12
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: 5786beffabec220f8dabf29b
There was a runtime error.

Nice Vladimir! I haven't checked yet. Is that all you did was swap the GLD for TLT? Wow, either way.

Ok, here is my latest version. Another huge improvement. I swapped the GLD for IAU IShares Gold. This one works even for small portfolios because of the smaller price and the mechanics of my algorithm.
Other improvements are:
Virtual trailing stop loss
Randomness in each rebalancing's stock picks (other than the gold one)
Adjusted the take profit target to 12.5%. Others which might work are 3% or 25%. So far I think the 12.5% may be about right.
Rebalancing happens only when triggered and never while at a loss
While at a loss, holdings are sold at close to cost basis, and rebalancing does not happen... no new purchases

I have some ideas for more tweaking. But technically this is my first successful algorithm to beat the S&P500 from 2010 forward. So I shared it.

Clone Algorithm
300
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: 578c439b2a465f0f91c75478
There was a runtime error.

Ok folks, this is a huge improvement. Check this out!
I made some more tweaks.
I changed the factor of the rebalance trigger.
I changed the conditions under which Wait is triggered.
This is my best one yet! Hopefully, the results are not somehow skewed.
I don't think that I am guilty yet of overfitting.

Clone Algorithm
300
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: 578da894b4b6070f9687eb15
There was a runtime error.

Charles
Would you indulge me and set out briefly the thinking behind your algo?

I am running the algo back to 2002 but I am not sure whether slippage, comm and the borrowing costs of shorting are accounting for. Also the handing back of dividends. I suspect not but perhaps certain defaults are automatically included in the Q code.

Hopeless:

Something went wrong. Sorry for the inconvenience. Try using the built-in debugger to analyze your code. If you would like help, send us an email.

One things for sure. It doesn't scale, yet, for larger portfolios. I'll work on that. I have an idea how to make it scale.

I just now added "do not sell until at least the next day" in order to not attempt pattern day trading transactions which otherwise causes excessive number of rejected sell attempts. The end result performance is very close to the same as before, but should have way fewer rejected orders.

I'm not an expert investor. So my ideas are perhaps naive, if not uninformed.

Gold tends to do opposite of market during downturns. So I have a relatively small weight of gold at all times to counter downturns. I noticed that gold also seems to do well at least some of the time that the market is going up.

I made the one best performing stock of my pipeline the "king" part of the gold king. The idea is the best performing stock may have momentum and may continue. I will, at some point, make this scale to portfolio size.

Under current configuration, there are at least 23 worst performing stocks that we attempt to invest in. The idea is that if we are invested in a large enough number of worst performing stocks, a profitable number of them will bounce back up at least temporarily, long enough to take profit. I will, at some point, make this scale to portfolio size.

When I sell a stock in my positions that is no longer in my favorite list, I sell only 20% of it per day. I noticed that often downturns are reversed within 2 to 3 days. So the 20% per day does not completely liquidate my positions for 5 days and allows for at least a partial recovery of the market for that stock.

Clone Algorithm
300
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: 578ebd1d3859a70f8a995088
There was a runtime error.

Funny story! 8)
I was in the doctor's office with my wife discussing her chronic pain / trigeminal neuralgia. My subconscious must have been still working on the algorithm. Because, all of a sudden, I had an epiphany, "else stop wait" will make the algorithm behave like I was expecting it to. Sure enough, gigantic improvements. Then, just now, I decided to make an attempt at making the algorithm scale to whatever portfolio size you throw at it. Well, 100,000,000 keeps up with the benchmark, but not good enough obviously. However, the change in code to make it scale to portfolio size also bumped the speed and results even higher for the smaller portfolios. I suspect it does very well even for large portfolios, but I'm not sure yet at what size the results start dragging down to benchmark level. I'll keep working on it.

Clone Algorithm
300
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: 57909e9de080a51244b5f927
There was a runtime error.

Charles,

I'm starting to dig into this code as I'm really curious, as I'm sure a lot of others are. Just a quick comment/question:

And anyone please correct me if I'm wrong... but the 'make_pipeline' only gets called once (in initialize). It would appear that you have variables within 'make_pipeline' that you intended to change before each trading every day. This is not the case, and as a result, 'HighVar', 'LowVar', 'TopVar', and 'BottomVar' are fixed at a static value, which I don't think you intended.

I don't yet know how this influences your intended strategy.

It's initialized each trading day

Filthy Robinhood peasant here: How does this algo perform going long only? The results so far look really good! Nice work Charles!

James - are you sure? This is where I lack an understanding with the pipeline functionality in general, but I believe I am right. If I hard code values for the 4 previously mentioned variables, I get the same stock picks and overall results as Charles original algo

Delman, this is a long only strategy as is.

I'm not sure. It would seem reasonable that it's only initialized once in a backtest.

Charles - I swapped IAU with SPY to just throw a wrench into the theory. Things didn't change much from the 'too good to be true' results of your last post. I'll continue to investigate when I find time, but I'm just your average hobbyist that can get by with python

Clone Algorithm
21
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: 579184cb92a21e1015dfb987
There was a runtime error.

Here's the long only version. I think the bug in his randomization is irrelevant other than it might explain why it is sensitive to the amount of money in his account.

Like seriously, this feels like the first episode of silicon valley when the guys at hoolie are looking at Richard's compression for the first time and saying "I don't think he realizes what he has".

What's crazy is that this still has room to squeeze in some other algorithm in the areas where it uses low leverage to get even more money.

Can someone from Q hide this thread from the public? If this isn't "give a contract to the man" material I don't know what is. This long only version seriously went a year and the max drawdown was 2%. It didn't go above that util halfway through my backtest. Charles deserves credit for what he's created.

Clone Algorithm
43
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: 5791a0f451baeb1223eda587
There was a runtime error.

Hi guys,
Thanks for the nice and interesting comments! Way back close to when I first started messing with quantopian algorithm stuff, I had one backtest that showed outlandishly awesome results similar to this. The difference was that, upon digging, I discovered that it was treating me as if I had an extremely leveraged margin account. That is not the case here. I've been through each line of code here. It feels real. Enough, that I put another couple grand of my own money on the live trade. Before it only had about 380 dollars. Only been live trading it, in effect for 2 days so far. The first day, I noticed alot of rejected pattern day trader sells, so I modified the code to avoid attempting those. yada yada yada ... Anyways, I hope this is real. It has a nice "I built it" feel to it! I have lost so much freakin sleep building this thing, I feel like a zombie half the time. It does feel surreal.

Whether or not the randomization attempt on my part is actually working, I'm not sure yet. My logic for trying it, is that I don't want my algorithm to get tunnel vision and look at the same group of stocks day after day after day. Seems like too much chance of disaster that way. This way, it hopefully recovers, after bad days or after some of my stocks go bankrupt or whatever.

So, a bit of a huge request here knowing how much work you've already put into it, but if you get time and don't feel like tweaking the 'meat' of the algorithm, is there any chance you might be able to comment line-by-line or logic by logic so that newer coders such as myself might be able to get a better grasp on what's going on with the algo and how it ties together?

With that in mind, if you feel like keeping the logic to yourself, that's totally reasonable as well. You've built an outstanding algo here.

This is so interesting. Was not expecting such a high Sortino and Sharpe ratio

The algorithm does need cleaning up and probably more commenting as well. If I don't have more itches to fix with this, then I will get around to clean up and better documentation. I'm losing my job in mid October. Hopefully, this will provide some real income.

Running a backtest starting in 2006, there is an insane jump starting around late 2008. Any idea why this might be? Also, I'm sorry to hear about you losing your job, and wish you luck in your next job search.

[Will attach a backtest once its done generating]

I don't mind, per se, sharing the algorithm. This feels like it could work for the little guy. Also, if the ideas get out there enough, hopefully it will be available for learning, or getting started. I mainly am trying to build a better one that works for my particular circumstances. I like how this algorithm tends to have at least some cash all the time. So if I need it, I can withdraw it without causing havoc with my portfolio. My goal is to have a large enough portfolio, that occasional withdrawal of cash for my needs will not effect it.

Also, I am an audiobook producer / narrator. It would be lovely to be able to spend my "work" time doing that instead of what is otherwise necessary to pay the bills. I enjoy audiobook creation, like it is art. I am way behind on my current audiobook contract. The author is being extremely patient with me. I feel intense motivation to create another source of income. This feels a bit surreal, but maybe it will work. My money is already in the live trade. I find myself having to resist the occasional urge to manually sell at a profit and wait and see if the algo does it for me.

My background and specialty is automation. That may have helped me with this, maybe.

The automation more than likely has a lot to do with the success of the algo if you've already got the experience of 'thinking' like a machine, so to speak.

An itch to scratch in Q's code would be to not include cash deposits as part of the "Returns" and "Dollar P/L". If you have auto deposits going into your brokerage account, they are getting included as if they are profits.

Charles,

Have you had a chance to compare the fill prices you received in live trading in the last two day against the fill prices reported by the backtester for the same trades? I would be really interested to know how that shook out.

Thanks

Frank

That would be useful information. I don't think it would be a clean comparison yet though. There was at least one glitch during that time where the live trading algo was delayed. I think sometime this next 7 days, that comparison should be able to be made cleanly. Maybe I'll be a few hundred dollars richer by that time as well. 8) The first day made 8% with 30 dollars profit off of about 377 starting cash. ...
Here's an interesting exercise in "what might have been"?
377 invested starting on the below date till 07/21/2016
07/01/2016 7.7%
06/01/2016 14.6%
05/01/2016 9.6%
04/01/2016 34.0%
03/01/2016 44.6%
02/01/2016 110.9%
01/01/2016 170.9%

Attached is the backtest I mentioned earlier. Everything looks ho-hum until 2008. What happened that put this algo into Wolf of Wall Street mode?

Clone Algorithm
23
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: 5791b8ea76edc01290074bcf
There was a runtime error.

Also, after looking at some of the daily logs, and I think you mentioned this earlier, there is a TON of day trading going on. Lots of buy and then sell for a $0.001 gain.

Holy #?!# Batman ----- 93,705% return -----
I hope this is for real! I tried to make this algo compound returns quickly, but those results are, I don't know what to say?!.

I think that the algo 'might' be selling stock which it doesn't currently hold. Also, lots and lots of 1 penny day trading. I might try and go through line by line tomorrow evening and see if I can pick out where that's coming from, because after a quick glanceover, it looks like it should only be rebalancing on the first day of the week. With that being said, as it stands you reach the day-trade law 5 trade limit almost immediately within the first few trades.

Delman I think it has to do with some things that were uncommented out in the algo. Some orders are being placed at places it should not. I am going to be looking at this code more closely tomorrow too to see exactly whats going on. This is definitely interesting.

Seungmin, definitely let me know what you find. I'll be going through it as well. More eyes should help speed the tweaking process along significantly.

After you mentioned the day trade stuff, I looked in my live trade logs for yesterday. Sure enough, there were what appear to be "get out" sell orders that were being rejected as pattern day trade.

The only place in the code that I see that could be happening is possibly the "get out" code itself.
Here is the fix:
if context.NextDay:
order_target_percent(stock, 0, style=LimitOrder(Curr_P*GetOutFactor))

I added it to the code and am testing it now.

By the way, I like the effect this change will have. It gives at least a day for the stock to be in profit or at least not in loss. So "get out" now waits at least till the next day just like "take profit" does.

Let us know how the backtest goes and if this changes things significantly.

Unfortunately it is difficult to trust the backtest result when the universe selected by the algorithm is low volume stocks.

Please note that the base universe is created using:

AverageDollarVolume(...).percentile_between(LowVar, HighVar)  

but LowVar is always 1 and HighVar is always 10. This means the universe is using the lowest volume stocks available and those are the stocks that are less reliable to be backtested with Quantopian. It is very difficult to model the order impact on such low volume stocks. Simon Thornington taught me something once:

If you are seeing results that only work when trading very low volume
stocks at high frequencies, you need to be very careful that you are
not just trying to do mean-reversion on meaningless bid-ask bounce.
Unfortunately, there's no way to really test this with Quantopian, but
one of my main findings in the process of creating a quote-based
tick-frequency backtester (in Scala) was that most of my basket
mean-reversion profits were just untradeable bid-ask bounce. I
mentioned this once in
https://www.quantopian.com/posts/inaccurate-max-drawdowns-on-no-trade-days-slash-periods
with a handy diagram: http://imgur.com/1WPMwFD

To double check if the algorithm is affected by this kind of problem I ran a backtest with LowVar = 40 HighVar = 50, but you might try higher values.

Clone Algorithm
3
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: 579207f485bfc80ffda16fd6
There was a runtime error.

Latest change cuts the total return from 93,705% to 33,104.9%. Still very very awesome and I believe it is probably avoiding day trades altogether.

Interesting thing happens June 17, 2007. The MaxPV spikes to 2, much higher than expected at that point. Looks like a historical or market pricing glitch. It caused longer than typical wait for the next rebalancing because the "get out" factor was much higher than typical. March 2009 is where that "bat out of hell" rocket climb begins that you mentioned earlier.
I like the 50 minute wait between possible actions. You end up with first action of day at 50 minutes after opening and 40 minutes before closing... when markets are calmer. That's my theory anyways.

Clone Algorithm
300
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: 5791e12f05f4990ffe214890
There was a runtime error.

Luca, thanks for the response and explanation! The results you posted look pretty bleak.

Luca, it's using limit orders so I'm not sure we can just discount low volume stocks. That said, taking a better look at the code it seems it would have defaulted to a moving windows using values of 1 and 10 and then looked at the bottom 10% by dollar volume. LowVal and HighVal affect the universe AND the moving window lengths. You changed the moving window lengths it used in addition to the universe it looked at.

James you are right, thanks for pointing it out. Here is a backtest where only the universe is changed and not the moving windows (the same backtest resulted in 288% returns with low volume universe).

Please note I am not saying the algorithm doesn't work in live trading (because I don't know), I am just saying you cannot trust the backtest results with low volume stocks, they are difficult to model.

Clone Algorithm
3
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: 57922a5ec2c8541000fa3fa2
There was a runtime error.

Here's with the universe being the stocks in the 20 - 90% percentile by dollar volume. Moving window is still 1/10 like it would have been.

Clone Algorithm
43
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: 57922873206f8e100dcebe44
There was a runtime error.

I just spot checked some of the stocks on my original backtest and it looks like it's definately a penny stock trader, but the volumes are high enough it could work on a small account. These stocks have more than a couple transactions per day. It does seem like this would be totally unsuitable for the fund though.

This one is kind of funny. It's using 10 - 30 percentile and is long only.

Clearly it got lucky. Max drawdown 25%

Clone Algorithm
43
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: 579230b3206f8e100dcebf3d
There was a runtime error.

@ Luca, great catch in reviving Simon's insight. I remember reading that last year but it apparently didn't stick.

Do you think paper trading can lead to sobering results (on the low volume stocks), or would one still see meaningless gains? Obviously these low volume stocks are not of much interest to Q

I'm going to rework the algo a little bit tonight using the info that Simon gave us. Personally, I tend to trade (manually) relatively low volume and low price stocks, so if I can replicate that using this algo, there shouldn't be an issue. I have yet to run into the issue via manual trading where an order could not be filled.

Another issue I see is that the algo basically gives $100 per stock and as your account size increases it just adds to the number of stocks it holds until it's basically a broad market fund.

An optimal value would probably be based on daily volume, with it favoring quality over quantity

Ok guys, I made some significant changes in the contested pipeline code. I also made some significant tweaks to the rebalance code.

I dub this one, "The Gold King And His Knights Reboot Edition" Hint: If you don't like it. Reboot!

This one scales way way better. And the algo runs faster too! I am currently running a $100,000,000 portfolio against it. It is currently trailing the benchmark. But I believe it will excel way beyond the benchmark given enough time.

Clone Algorithm
300
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: 57932f57b9e537127988cf8b
There was a runtime error.

I ran a five year backtest and did some real quick analysis of the result. Still a lot of penny stocks mixed into the bunch. You might want to try setting a minimum stock price of something like $10 and seeing how that skews the results. I don't think any sane person is going to want to buy something trading for less than a dollar.

Clone Algorithm
0
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: 57933bf6ba43361228b3c504
There was a runtime error.

Ok, I changed the short moving average and long moving average to be fixed. My favorite seems to be 3 and 45.
And I jiggered with the "Get Out" code to trigger at a lower leverage.

I have a couple of full 10 year backtests in progress.

Clone Algorithm
300
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: 57934baa1379581002a3e019
There was a runtime error.

Algorithm initialized variables:
BottomVar 10
TopVar 1
LowVar 15
HighVar 45

Clone Algorithm
300
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: 57934b67fd75dc1000b275e2
There was a runtime error.

I just ran another 5 year 1k backtest. This time, there's a pretty noticible jump (also present in your backtest Charles) relating to a purchase of $HERO on 2015/08/21 at $0.06 per share which is then sold on 2015/11/11 at $9.44 per share. I tried poking around Barchart and Yahoo Finance, but I was not able to verify if this was legitimate stock data or not.

For those who are interested/more dedicated than I am, the stock can be found using HEROQ or Hercules Offshore, Inc.

Clone Algorithm
1
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: 57935105790a191000b3d708
There was a runtime error.

Algorithm initialized variables:
BottomVar 100
TopVar 10
LowVar 66
HighVar 96

I'm posting this for the most part without comment. I have some ideas to test.

Clone Algorithm
300
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: 57934b89790a191000b3d6b9
There was a runtime error.

Algorithm initialized variables:
BottomVar 100
TopVar 10
LowVar 15
HighVar 45

I added a $1.00 price filter and for testing purposes fixed the LowVar 15 and HighVar 45.

Clone Algorithm
300
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: 579436a9950e550ffb8761bd
There was a runtime error.

Algorithm initialized variables:
BottomVar 100
TopVar 10
LowVar 15
HighVar 45

Clone Algorithm
300
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: 579440cbde6e710ffb5f6bea
There was a runtime error.

This is a nice algo, I think the only issue is the high beta. Whenever the market goes down (i.e. 2008/2009, 2015) so does this algo. I guess that is the problem with being stocks only - there is a lot of market risk.

If we could maybe switch to SH or do some sort of hedging when a bear market is sensed, I think it would help the draw down a lot.

Mohammad, if it were possible to achieve a CAGR of 56% who would care about a 24% drawdown? The question is "is it"?
Same question as this other thread

I'd love to believe it possible......but....

The problem is not so much the amount of the drawdown, but the length of time between peaks. When the system is losing money for 2 years during a recession - no investor can be expected to keep having faith in the system.

There is no guarantee the system will turn around and become profitable, so they will cut their losses and stop the system way before 2 years.

The same is true of the S&P 500. Which is itself a systematic way to invest. There is no law of pysics which sates that the US stockmarket's upward bias will continue for ever. In fact it is most unlikely. A two year period between peaks is nothing in systematic trading.

The deeper point is "does Charles' system really work or is it a figment of back testing". If he he has discovered some genuine market truth then......whoopee! If not, then shucks, there goes my daughter's new pony.

It makes sense that low volume stocks would be an open opportunity that had been missed. The first thing you do when making algo is throw them out since you can't use them for entering a large position.

Regarding Charles Witt's most recent post and its attached algorithm: What is the justification for these settings?

    set_commission(commission.PerTrade(cost=0.00))  
    set_slippage(slippage.FixedSlippage(spread=0.00))  

If you remove these settings, the algorithm underperforms the benchmark.

A two year period between peaks is nothing in systematic trading.

It depends who you ask. In my books, an algo that has a two year period between peaks is worthless.

I dont classify all systematic trading as the same. To me, an ETF is very different to an algo because there are additional risks involved in deploying an algo.

For the commission, my reason is that I use Robin Hood brokerage which has zero commissions. Maybe there is a reason to not use zero in the backtest, I am not currently aware of it.

For the slippage, I am only using limit orders. Not being an expert, I understand that to mean that slippage is avoided because I am not using market orders.

I may be wrong, but the partially filled orders from large orders do not necessarily hurt my long term results. The unspent money from a partially filled (or completely unfilled for that matter) order is available for the next day's attempt to enter a position at a discount.

slippage is avoided because I am not using market orders.

Have you done any research into how Robin Hood turns a profit? Limit orders can be exploited, if you can front-run them.

Have you tried the strategy with real trades? A few dozen trades might be enough to include a rough model of the speed of execution you're getting in the algorithm.

I would like to try this out in real time trading soon. Been messing with it by changing around numbers and tweaking things here and there but the only thing that matters is if it works in the real world. I will also be using Robinhood for this. Trial run will start tomo. Wish me luck.

I am live trading an older version of my algo that does not filter under $1.00 priced stocks and I think it is using the 1 - 10 low volume universe (I think). I actually have used my experience with that to adjust my algorithm sometimes. For example, the rejected day pattern trades for my attempted sells. I adjusted the code to avoid selling the same day that they were bought. It is still possible to attempt to enter a position later in the same day that I had exited it earlier .

It does, so far, appear to be doing what I told it to do - namely getting in at or below limit price and getting out at or above limit price. At this point, I'm not sure how Robin Hood's methods of reaping profit are effecting my results. I suspect, that at worst, my live trading returns will be worse than the backtest, but still profitable to me personally.

In effect, I've only been live trading with a fairly recent version of this algo for a few days so far.

it's odd that slippage would be factor if you're using limit orders. Does it result in fewer orders executing?

James: Yes, limit orders can be front-run in such a way that you're less likely to get filled if the price movement favors you.

https://www.reddit.com/r/investing/comments/4uczkd/front_running_and_limit_orders/

UPDATE: I like the current version enough that I'm gonna use it for live trading. For my personal live trading, I removed the price filter and did 1 and 45 volume universe.
Algorithm initialized variables:
BottomVar 100
TopVar 10
LowVar 1
HighVar 45

Clone Algorithm
634
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: 579567c171a3a00ff9593c43
There was a runtime error.

I have some ideas that I'm testing to improve the performance for high volume stocks. Maybe if that works, I'll dub that version, "The Gold King Gets High". 8)

Quantopian doesn't model front running. These are also relatively small orders on the side of the market that is often ignored (which is why they are low volume)

If slippage affects the results of small limit orders on low volume stocks it would seem the slippage isn't being modeled correctly.

I think the only way to be sure is to live trade with real money

In my books, an algo that has a two year period between peaks is worthless.

I agree that it is not a pleasant prospect but you will find very few hedge or other funds which manage to avoid this. In the long term, almost certainly none.

@Delman - looks like that $HERO stock went into bankrupcy and then emerged in Nov 2015. Im not sure how the shares were restructured or if the algo correctly valued its shares, but it seems to have held on through the entire Chapter 11 procedure.

It bought the shares on 8 Jul 2015, the company then went through Chapter 11 and the stock was delisted. It then emerged with a new loan and started trading again in Nov 2015. Im not sure if 1 share pre-Chapter 11 was equivalent to 1 share post-Chapter 11 - I was not able to find the data online.

@Charles

re: "UPDATE: I like the current version enough that I'm gonna use it for live trading. For my personal live trading, I removed the price filter and did 1 and 45 volume universe.
Algorithm initialized variables:
BottomVar 100
TopVar 10
LowVar 1
HighVar 45"

Does this version work with RobinHood? I notice in the code it set_long_only() but it also seems to take quite a few positions from day to day. Have you seen RobinHood flag it for day-trading?

In practice, I've seen the RobinHood day pattern protection work very well. And I've used my RobinHood live trading experience to adjust the code. For example, day trades are 99% avoided. It is still possible for it to attempt to buy the same stock it sold earlier in the trading day. If that happens frequently enough, I'll go ahead and add code to avoid it. But it does wait till at least the next day before it tries to sell the stock it just bought.

Keep in mind that a large percentage of the buy limit orders are cancelled at end of trading day. That's by design. The orders that do get filled are sometimes the low price of the day from what I've seen.

Charles, any update on the reboot live trading performance?

Ok, I made some small changes that appear to have big improvements in efficiency and returns.

Orders are now never cancelled, except at end of day. So no more cancelled "Take Profit" limit sells except at end of day.
During live trading, I saw one stock at 144% profit got its limit sell order cancelled apparently by the rebalance code.

StopWait now effectively starts fresh, to properly give the stocks a chance to come alive again.
The only thing that keeps it in Wait mode is in a continually downward price trend, which is as it should be.

Clone Algorithm
634
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: 579a4af0b51d271280d7f9bd
There was a runtime error.

I found a cash balance logic error. Fixed it.

Clone Algorithm
634
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: 579a537e2e04a3129a267d0d
There was a runtime error.

Charles,

That spike at mid Nov-2015 (and actually half your returns all together) are from 'HERO'. No idea what this is and if the data is good/bad, but attached is a back test that filters it out in the pipeline. Still a solid looking algo for low capital.

Clone Algorithm
16
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: 579a7201b51d271280d7fd11
There was a runtime error.

Andrew, I think that with $HERO filtered out, that is the most accurate backtest to date.

I made a comment on $HERO previously. Although it was unusual, it is actually valid.

See my previous comment for more info.

I'm fairly new to quant-driven trading.

@Charles, or anybody else who knows, do you have any more info on the theory behind this algo? Maybe a paper somewhere or just a brief overview of the theory behind it?

Adam,

I'm just a guy who wrote an algorithm for trading that seems to do extraordinarily well with low volume (less popular) stocks. If you read the whole thread, you will notice that I was not targeting low volume stocks on purpose. In fact, I initially thought that it was "randomizing" to some degree the selection. That has mostly been proven to not be true. The original code was selecting from the 1 to 10 % volume universe - the lowest of the low, in other words, of volume traded stocks.

My uneducated guess at why this works so well:
1. the very low price stocks allow, in the first place, for a larger basket of stocks, especially for smaller portfolios
2. because the volume traded is so low, the price is much more volatile, which plays well with the mechanisms in my algorithm

Point 1 may be completely irrelevant, because I've tested with $100,000,000 with the high volume basket of stocks, and it still did not get anything close to similar returns as low volume stocks do.

The algorithm has evolved, eventually arriving where we are now.

As far as, "Are the results real?", that remains to be seen. In my live trading for about one week now, I have seen very similar patterns, compared to the back tests. No huge returns yet, but definitely similar patterns.

Good catch Mohammad, I read your post but apparently it didn't stick with me.

Adam - I'm also interested in the theory as I don't understand it as well. I'm also not sure if Luca's previous point about the bid-ask bounce is impacting this algo. I think that's where live or paper (would paper trading address that?) trading would help solidify the logic. I understand the logic but don't see the theory. The gold component doesn't appear to be too significant... I'm waiting for someone with some more knowledge to provide some insight on what's going on. But maybe this is a valid strategy for a low cap universe. That would certainly be nice, I hope Charles makes some money on his work

@Adam Chavez, I'm sitting here with Charles. Here's a quick and dirty insight:

  1. This algo trades in stocks that are small in value. Losses are not huge, so no major issues.

  2. These 'bottom feeder' stocks have, mostly, nowhere to go but up. Charles is using the 100 worst performers. The chances that all 100 of them will tank in the same time period is very small, so the algo will make money for the most part. He's also using the 10 best performers over a rolling 45-day period which provides him with a solid base for security.

Mostly, though, think of this from a statistics point of view. Most data sets - stocks included - can be accurately displayed on a bell curve. Now, the vast majority of the data is in the central 90% of the curve and those are the stocks this algo seeks to invest in. The stocks that are are outliers on the edge of the curve are shaved off by the algo limits.

Also, since a lot of the stocks are low-priced, the sheer volume of stocks that will be bought by the algo kind of hedges its bets: it simply buys enough different stocks that the chance of all of them tanking is minimized.

It's a heroic effort in any event. Congratulations.

It is FUN. Fun to trade and huge fun to make those sort of returns if it works. Who cares if it for the small account hobbyist? If it does work you can trade it up from tiny capital and that is really the object of all small traders - to make a fortune from nothing. And nothing wrong with that if it can be done.

Hope it works for you.

Very curious results. I hope someone gives us an update to their live trading in a couple of months.

Edit: Is this basically a mean reversion algorithm? Buy very low and sell high!

Apologies to the live traders of my algorithm. I got this deployed minutes before market opening this morning. But just now posting to this thread.

The "start fresh" change I mentioned above plus what I changed overnight with the gold stuff seems to have improved results demonstrably.

I've been studying the patterns of IAU Gold. It seems that 2% is the typical max change up or down in a day. So the 6% discount get in order was never getting filled. So I changed it for the "Other" gold only to be 2% discount get in and 1% take profit. Take profit is 12.5% for everything else.

By the way I prefer gold over bonds because:
not only does gold tend to go up when the stock market goes down
but gold, a surprising amount of time, also goes up when the stock market goes up

Notice, with the last 2 changes mentioned, that the max drawdown is now below 10% and most of the time is below 5%.
Also, the drawdowns are smaller both
horizontally (length of time)
and
vertically (size)

Clone Algorithm
300
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: 579adedbbbd64f126b970792
There was a runtime error.

1 million percent return? Good lord, man. There needs to be a reality check!

I would say the final numbers are not a good way to look at it because they are too big and can be misleading. I find the best way to look at long backtests is it's CAGR - which is about 165% for the above algo.

I wish Q would just display the CAGR in their stats.

Ok, sorry it took so long to implement this behavior. It is logical.

Take Profit sell will cancel any existing order for that stock. So now Take Profit sell takes priority.

Clone Algorithm
300
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: 579ba9f6c06db4100f4bcfc3
There was a runtime error.

Charles
I have put a lot of work in over the last few days and will post an algo eventually. My research so far in different market environments is that neither gold nor the best stocks are adding any value. I have thus stripped them out. I am also cleaning up my version since there seems to be some unused features which for me at least cloud my understanding of the basic concept.

I should hasten to add I have no experience whatsoever of penny stocks or of trading in this timescale. The big, big question is whether the use of limit orders is going to avoid the perils of spreads which can approach 100% - bid 1c offer 2c.

I have no idea at all whether paper trading would answer this question - I have to assume not because it is better to err on the side of caution. If I could open a Robinhood account and start trading this I would. Its the only way to get the answer. And with $1,000 to $10,000 who cares!

Sadly, until such time as RH opens in the UK I guess I am stuck.

In any event thank you for all your efforts and well done indeed on the concept.

Incidentally, I find Quantopian mind bogglingly impressive and have nothing but admiration for the incredible framework they have provided. My only real frustration is the inability to export spreadsheets of the information I really want to drill down into.

I know it can be achieved in code and logic but I would dearly like to see such statistics as % winners / losers, r sq of equity curve, length of trades, length of winners, length of losers, CAGR and so forth.

I guess I'll just have to get off my butt and write the code.

I intend to try it in a few days with Robinhood. It should be a good test for the efficiency of Robinhood. However I kind of doubt this was what they had in mind when they started the company. In my backtests the "best" stocks did seem to help a little. I did not see it trade any gold. Maybe it should be
renamed the "Soaring sparrow and the bouncing cat"

Ok, in the process of trying to make it somehow work in the contest, I ended up radically changing certain portions of it. A big change is the "get out" behavior. Also, you'll find that the 10 year backtests are much slower now. I also changed the gold code to allow it to play a bigger role.

This is the version I am live trading on RobinHood with. It still needs to be thoroughly tested. I noticed some sell orders getting rejected unexpectedly. Not sure how significant that is yet.

Thanks Anthony and others for your testing. I figured if I keep posting my changes and the backtests, it would gradually get better.

By the way, in the interests of full disclosure, I have experienced, apparently, one delisting (BINDQ), in my live trading. Not sure what the end result will be, but I had about $90 in that one. There is a buy or sell button for that one, not sure what would happen if I tried to sell or buy it. Quantopian tries to sell it as BIND and it gets rejected. In the RobinHood phone app, it says, "This stock is not currently listed on an exchange.".

Clone Algorithm
634
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: 579fc933abf1fc104073035e
There was a runtime error.

"By the way, in the interests of full disclosure, I have experienced, apparently, one delisting (BINDQ), in my live trading."

@Charles, I think that's the fatal flaw of the algo. I'm starting to see that Quantopian really doesn't handle liquidity risk well.

Does anybody know if Quantopian's backtesting engine even looks at delisting? Or does it only trade stocks that are still currently being traded?

@Adam - I agree.
It seems Q keeps the value of the delisted stock as last quoted - see HERO in my previous comments.
Tracking a delisted stock is really complicated - often it goes to OTC with a "Q" on the end. So HERO becomes HEROQ.
Delisted stocks usually lose a lot of liquidity. In the real world, it takes balls of steel to keep holding on to delisted stocks as this algo does.

In backtesting I believe that desisted stocks cannot be sold so they accumulate in you protfolio and hold cash.

Here is some code to remove them, although it does not subtract their value like is should (if you actually lost the money like you probably will)

#exit soon to be delisted stocks
if (stock.end_date - get_datetime()).days <= 3:
order_target(stock, 0.0)
log.info("Closing deslisted %s" % (stock.symbol))

I wonder if there's a lot of delisted stocks in a long backtest. It would significantly affect your return since delisted stocks in Quantopian is automatically converted to cash.

Greg,
That code looks useful. How effective has it been so far in your backtests or live trading? It looks like it attempts to get out of a position if it is within 3 days of delisting.

I guess I'm wacky. 8) I'm waiting to see how many of these actually effect me and what the final outcomes are. I'm certain I'll get more concerned, as more money gets tangled / lost in these.

Some "news" on BINDQ:
" On July 2, 2016 BIND Therapeutics, Inc. (BIND), a biotechnology company developing targeted and programmable therapeutics called ACCURINS®, announced it has filed a motion for court approval of a stalking horse asset purchase agreement bid from Pfizer Inc. (PFE) for the purchase of the majority of BIND’s assets.

The agreement is the initial stalking horse bid under Section 363 of the U.S. Bankruptcy Code, to be followed by an orderly auction process as established by the U.S. Bankruptcy Court. Under terms of the agreement, Pfizer has agreed to acquire substantially all of BIND’s assets for approximately $20 million in cash subject to certain price adjustments. Pfizer has also agreed to assume certain contractual liabilities of BIND.
"

20 million shares outstanding.

So about $1 / share less liabilities. That's probably where the otc price comes from. What did your algo pay?

I wonder if there's a lot of delisted stocks in a long backtest. It would significantly affect your return since delisted stocks in Quantopian is automatically converted to cash.

Do you have an algorithm handy which demonstrates this? Seems like a potentially significant bug.

It's not a bug but a decision by the developers: https://www.quantopian.com/posts/delisted-securities-now-removed-from-portfolio
You have to be careful when backtesting penny stocks. I've attached a backtest that buys Aeropostale stocks before they went to OTC. You can see the cashback.

Clone Algorithm
0
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: 57a0243d02d108122a0e5bb7
There was a runtime error.

I would recommend something like Greg Rollins example. Liquidate your stock before it is delisted. For live trading, I guess you just gotta watch your stocks like a hawk and manually liquidate when the delisting announcing comes up.

Thanks.

"20 million shares outstanding. So about $1 / share less liabilities. That's probably where the otc price comes from. What did your algo pay?"

98 shares average cost $0.9273

The 5 year backtest keeps timing out apparently. Here is 2006.

Clone Algorithm
634
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: 57a039966e68c4122a83264e
There was a runtime error.

It's not a bug but a decision by the developers: https://www.quantopian.com/posts/delisted-securities-now-removed-from-portfolio
You have to be careful when backtesting penny stocks. I've attached a backtest that buys Aeropostale stocks before they went to OTC. You can see the cashback.

Ouch, yes. So in these back tests you are guaranteed never to lose all your money on a position.

You can either look for statistics like: what percentage of delisted stocks ended up at zero or make your own I suppose by combing through delisted stocks systematically. I have delisted stocks from CSI data going back to 1985 and it includes bulletin board and Pink Sheet prices (I think).

If you own the stocks in depot with Robinhood can you deal in them on the Pink Sheets or BB? If so, all may not be lost.

Nasdaq delistings

GNOW

Take GNOW for instance. It was delisted on 19th May 2016 and continues to trade otc: on 1st August the price listed is c 19 and over $7,000 worth traded. And yet Q has the last traded date as 3rd Jan 2014.

data = get_pricing('GNOW')  
data.tail()  
    open_price  high    low close_price volume  price  
2013-12-27 00:00:00+00:00   1.5200  1.5200  1.4322  1.4800  3410    1.4800  
2013-12-30 00:00:00+00:00   1.4700  1.5499  1.4700  1.5400  11048   1.5400  
2013-12-31 00:00:00+00:00   1.5801  1.6400  1.5801  1.6400  1084    1.6400  
2014-01-02 00:00:00+00:00   1.6300  1.6600  1.6200  1.6499  2627    1.6499  
2014-01-03 00:00:00+00:00   1.5500  1.6000  1.5400  1.6000  766 1.6000  

So you certainly can NOT say this idea is crap it doesn't work. You just have to take pot luck and test it out.

Incidentally some of these insane spikes in stock prices may well be caused by consolidations which have not correctly been adjusted for.

I added the .985 (1.5% immediate drop get out) code back in just in case there is a strong downward trend when you're trying to get in.

There is no obvious change to this backtest in the graph. However, I think it is a potential lifesaver in a downward trending market.

Clone Algorithm
634
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: 57a0cbd91d33f412183648e3