August 16, 2016
Since I've returned to Quantopian, I've been busy getting reacquainted with their trading software. What follows are my first attempts at participating in their forums, even if I should have waited. But, the occasion presented itself. Anthony Garner, like many others, graciously posted his trading strategy results and code for all to see. It is the first strategy I looked at. I found it the easy way to review Python syntax as in learning by example.
I soon got to modifying some of the program code values, especially after Peter Falter made modifications to it. Not being that good yet, I limited myself to just changing parameter settings. Didn't change or add any line of code except for changing their default values.
To a comment by Thomas Chang, I answered:
What I look for in a trading strategy is replicability. Will this trading strategy behave the same going forward, and is its trading concept sound?
The concept, in this case, of sorting by highest past momentum has some basis. It makes the assumption that this momentum might continue. A reasonable backtest for a sufficiently long time interval generating a sufficient number of trades should show this.
Anthony's initial program generated the following:
Anthony's initial program
(click to enlarge)
Now, that translates to about a 4.45% CAGR on its $1M initial stake, not that great a performance level. Profitable, but you want more.
Correction: It should read: 17.45% CAGR. And this makes it an interesting performance level.
Peter's modifications over Anthony's trading script show that there is positive alpha there. There is something that can be used going forward.
As both said, there are some weaknesses in this trading script, I concur, but I think they can be addressed. Removing them should only enhance the strategy's performance level.
What I am more interested in, in a preliminary overview, are the underlying strengths of a concept and why it should work going forward. I can always address the weaknesses later.
One key concept Peter added to this strategy is the increase in the number of trades as the strategy progresses. For me, it says this: expressed in a single payoff matrix equation: A(t) = A(0) + Σ(H(1+at).*ΔP) which I expect to outperform the averages.
What I want is: Σ(H(strat_A)(1+at).*ΔP) > Σ(H(strat_B).*ΔP) > Σ(H(strat_S&P500).*ΔP). And this strategy (stratA) can do it.
Also, as Peter surmised, ER (the efficiency ratio) has no positive impact. Therefore it does not matter, it is not what is driving this strategy. It could be removed or set to 0.0 as suggested since there is no value there.
If you reverse the momentum sorting, you will see all the performance disappear to the point that: Σ(H(strat_S&P500).*ΔP) > Σ(H(strat_B).*ΔP). It will not even outperform the index. Therefore, again, I say, there is some value in playing the momentum continuation gambit.
It's an interesting script and worth investigating.
What's Under the Hood
Anthony's simple momentum rotation system is merely a variation on the moving average crossover theme. And that, I can say, is not much to promote a trading script.
What interested me in Peter's version of the program was the increasing position size as the portfolio grew. There is more power in there than meets the eye. In fact, I see it as the way to open up to higher alphas.
But first, some of the funny stuff. Say you reduce the stock universe to be treated. It will also reduce overall performance. Anyone could test this simply by replacing the 3,000 stock universe used in the strategy to 2,000, 1,000 or even lower. The impact will be to reduce performance. The reason is simple, one is taking out "potential" trade candidates and thereby reducing the center of mass of the selectable ones. One could increase the average daily volume value as selection criterion which would also reduce potential trade candidates with a direct impact on the bottom line. Try it. This can also be done by changing only one number (0.5e6). If you reduce the number, you will get more illiquid stocks being able to pass through on momentum alone. Not so good, you also want to be able to exit on a trade.
Once you have accepted that there is merit in this momentum concept and that in the future, the strategy should behave somewhat the same as in its past, it could be used going forward. Naturally, after you would have corrected its weaknesses, and there are some.
Here are tests I've made.
I generally use leverage. Some trading strategies don't support leverage very well, however, this one is quite suited for it. It will add a little bit more in drawdown, but nothing scary.
Change one number in the program from 1.0 to 1.5 to use at most 50% leverage. The test gave the following result:
#1 SMRS 50* Leverage
(click to enlarge)
Pushing the leverage to 85% generated:
#2 SMRS 85% Leverage
(click to enlarge)
From the above charts, putting leverage at 1.50 produced: 4,289.4%; while at 1.85 generated: 6,491.9%. Their respective drawdowns were: 28,39% vs 31.6%. This meant putting $3,200 more at risk, or 3.2% more, which I find more than acceptable. For the added $3,200 of momentary risk, the program generated some $2.2M in added profits on an initial stake of $100k.
Another test that was done was a walk forward.
All presenters stopped their strategy on 2015-11-30, just as the two tests above using leverage. Doing a walk forward would add 9 months of unseen data to that program. It is a perfect way to show if the trading strategy would have behaved the same going forward as it did in the past. The test was easy to make, change the test's end date, and you had your out-of-sample test. Here are the results:
#3 SMRS 85% Leverage + 9 months walk forward
(click to enlarge)
What can be seen is that most metrics improved: alpha, beta, Sharpe, Sortino and information ratio. The volatility and the max drawdown remained the same. So, we can't say that the risk increased, but the overall return surely did.
Overall, that is about a 23% CAGR and that is a pretty good number to have.
I kept studying Peter's modifications and found more ways to improve performance with little in incremental risk. My next post went like this:
The original program is aiming for a 25% profit target on its trades. Now, if you reduce this target, the impact will be to also reduced profitability. But what about increasing it?
You are with a trading strategy that is amplifying its trading volume as you progress in time. Reducing its profit target should allow for more trades to be closed, returning cash into the account that could then be reused down the line since you are still trying to leverage up to 1.85 of equity. Nonetheless, you make less because you are also curtailing the program's ability to increase volume by providing it less ongoing equity, therefore reducing the general volume of trades as the program evolves. Not by much, but enough to significantly reduce its potential. In a way, you've reducing trade volatility excursions, reaching earlier stopping times.
#4 SMRS 85% Lev. : 20% profit target (was 25%)
(click to enlarge)
When you look at the metrics, the 20% profit target compared to the original 25% produced about $1.2M less for what amounts to about the same level of risk: look at the volatility and max drawdown numbers. So, the idea of hoping that reducing the profit target might put more money back into the account earlier also reduced the strategy's future buying power resulting in an overall less desirable scenario.
Based on the above, requesting more profits by pushing the profit target higher, one should expect this to result in higher overall profitability. But, not necessarily so. That too is easy to test, just change a few numbers since they do control the strategy's general behavior.
I kept changing numbers, not haphazardly, but with definite objectives in mind. I view a trading strategy as a whole, all I see is its payoff matrix: Σ(H(strat_A).*ΔP). I'm interested in whatever will have an impact, not just locally, but globally. What will influence the trading strategy to go one way or the other. Naturally, always with profitability and executability in mind. If a trading strategy can't be executed in real life, it simply has no value.
As an attempt to answer Anthony's dismissal of the trading strategy as being too particular to its rebalancing time, I posted what follows.
I've read that some think this trading strategy is almost worthless. Even the original author thinks so. Now, that is not a high five recommendation. But...
It should be noted that Peter's additions to the code changed the underlying trade mechanics. I've studied this phenomenon a lot over the years, and have been using it in my programs as well (not in Q). Sure, you will probably be taking an incremental risk, which often will turn out to be about almost the same as everyone else, but you could also generate higher alpha, be more profitable.
The reason would be simple as well: you would be reinvesting more of the generated profits. Providing a positive feedback to your trading strategy. I have applied this to stocks as I think it is one of the places where such procedures can prevail. I have not tested other environments, and don't intend to do so in the near future. So, view all I say as being related to US stocks only.
We have Kelly numbers, fix-fraction, optimal-f, and a lot of other portfolio weighting schemes. I see this one more like expectation opportunity weighting. You are allocating your equity to the highest ranking slopes (highest upward momentum) of a group of stocks on the premise that their relative trends will continue up in the near future.
... to be continued