A Simple Framework to Quantify your trading! - Part.1
A Simple Framework to Quantify your trading! - Part.1
One of the most asked questions from retail traders is where to get the next trade idea from? Which chart pattern is the best? Or maybe it's a Crossover? A candle pattern or one of the other 100 indicators or combinations thereof?
If you are into Option trading.. the idea stays the same. The question becomes which one of the calendar, diagonal, vertical, butterfly, iron condor or just plain call should he buy? or sell? What DTE? How far in or out of the money? And that generally leads them to one of the many web services trying to sell them that next idea - and the next. After one or two unsuccessful trades with one service, the quest moves on - onto another website, another web service.
In this set of articles, let's explore if that is the best way of going about it? Or if there is a better way to approach the problem (hint: ofcourse there is..).
So how to actually go about it? Think - if you were running a business - say a restaurant - would you actually want to come in every morning and think about the menu for that day? how about what customers you want to sell today to? or where to setup your shop today? Nope. All that thinking goes much before you get your license. Same goes for any business. You shouldn't have to think about these things on a daily basis.
If you cannot express an idea however complex it be in a half-page with a set of rules and be able to code it.. and test it and access if its worthy of putting your money behind it - it's not worth thinking about. Most likely though in my experience when a trader is not able to succinctly write a set of rules that capture the essence of his trade philosophy - it's generally because the idea is vague in his head and just hasn't really been flushed out properly.
Profitable trade ideas do not need to be overly complex either - and even in a very complex system the key idea that works can be distilled into a handful of simple rules that govern like the lions share of the strength of the signal - and by simplifying things as much as possible you might avoid the trap of curve fitting to a great extent.
Trading as a business when successfully run.. should be boring as hell. You shouldn't have to think about where the next trade idea is going to come from. It should always be a rinse and repeat business. And there is only one way I know of.. of doing exactly that. Quantify everything you do and systematize everything. Again I repeat - the mantra is to Quantify and Systematise everything.
Another one of the common misconceptions is that you need a dozen different great ideas. Honestly folks - there might not be that many great ideas. I know of hedge funds trading a single idea successfully - yes; you read that right. Exactly ONE good idea is all it takes - to run even say 40-50mil of capital. Execution is not going to come easy - and perfecting executing that one idea might be worth more than searching for new ideas.
Even big hedge funds running billions in capital - with an army of phd's running the show - AQR run by the famous Cliff Asness for example is powered primarily with only a handful of key ideas, and only a couple of them, long-short based on some factor model running most of the capital. It's amazing. And the edges you will find won't be enabling you to double your money every two months - that is a wrong approach.
https://www.youtube.com/watch?v=oSZZejm9Vn4
Hedge funds focussing on very small caps and staying concentrated with exposures in a handful of them - to get that elusive alpha - are neither actually hedging nor quantitative for that matter - they should be marketed as "Gambling Funds" and not as "Hedge Funds" but I suppose it would be very hard to raise money if named as such eh.. anyways.. I digress.
Back to topic. For us retail traders - in today's world, for a couple hundred bucks it's quite easy to get setup with a good backtesting platform. This holds true whether you are a fundamental measures oriented trader, technically oriented, or just plain quantitative.
There will be a learning curve but it will be the end of searching for your next signal and no more shooting out into the dark or searching for your next best trade idea from some web service promising 100% returns. Here is a comprehensive list of backtesting platforms from Quantpedia (my favorite has been Amibroker for more than a decade now - there are many other good platforms as well - just pick your poison and stay with it):
https://quantpedia.com/links-tools/
Here's code for a simple 3Day High-Low system - goes long after 3 days of lower lows and lower highs - and shorts in reverse. With a couple of filters to keep you on the side of a longer-term moving average:
//3-day high low system
SetTradeDelays(0,0,0,0);
SetOption("ExtraColumnsLocation",1);
//ProfitTarget = 01;
//ProfitTarget = Optimize("ProfitTarget", 0.7, 0.1, 3, 0.2); // 0.2;
//ApplyStop( stopTypeProfit, stopModePercent, ProfitTarget);
ApplyStop(stopTypeNBar, stopModeBars, 20);
BuyPrice = SellPrice = C;
ShortPrice = CoverPrice = C;
LongTermMALength = 50;
ShortTermMALength = 10;
LongTermMA = MA(C, LongTermMALength);
ShortTermMA = MA(C, ShortTermMALength);
LongFilterRule1 = C > LongTermMA;
LongEntryRule1 = C < ShortTermMA;
//Three days of lower lows and lower highs
LongEntryRule2 =Ref(H,-2) < Ref(H, -3)
AND Ref(H,-1) < Ref(H, -2)
AND H < Ref(H,-1)
AND Ref(L,-2) < Ref(L, -3)
AND Ref(L,-1) < Ref(L, -2)
AND L < Ref(L,-1);
LongExitRule1 = C > ShortTermMA;
myTimeNum = TimeNum();
BuySignal = LongFilterRule1 AND LongEntryRule1 AND LongEntryRule2;
SellSignal = LongExitRule1;
//Short code
ShortFilterRule1 = C < LongTermMA;
ShortEntryRule1 = C > ShortTermMA;
ShortEntryRule2 = Ref(H,-2) > Ref(H, -3)
AND Ref(H,-1) > Ref(H, -2)
AND H > Ref(H,-1)
AND Ref(L,-2) > Ref(L, -3)
AND Ref(L,-1) > Ref(L, -2)
AND L > Ref(L,-1);
ShortExitRule1 = C < ShortTermMA;
ShortSignal = ShortFilterRule1 AND ShortEntryRule1 AND ShortEntryRule2;
CoverSignal = ShortExitRule1;
Buy = ExRem(BuySignal, SellSignal);
Sell = ExRem(SellSignal, BuySignal);
Short = ExRem(Shortsignal, Coversignal);
Cover = ExRem(Coversignal, Shortsignal);
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
Plot(Close, "3D-HL - Close", colorBlack, styleCandle);
PlotShapes( shape, IIf( Buy, colorGreen, colorRed), 0, IIf(Buy, Low, High) );
PlotShapes( Short*shapeHollowDownArrow + Cover*shapeHollowUpArrow, IIf(Short, colorRed, colorGreen));
GraphXSpace = 5;
Plot(C, "Close", colorBlack, styleCandle);
Plot( LongTermMA, "LongTermMA", colorRed, styleLine);
Plot( ShortTermMA, "ShortTermMA", colorGreen, styleLine);
SizingType = 1; // toggle between 0 and 1
if (SizingType == 0)
{
// *** Position Sizes for Stocks or Portfolios of futures ***
PositionSize = -10;
PosQty = 50;
SetOption("MaxOpenPositions", PosQty);
}
else if(SizingType == 1)
{
// *** Position size when testing one future contract. Trading only one lot at a time. *** //
RoundLotSize = 1;
PositionSize = MarginDeposit = 1;
}
Comments make most of the code self explanatory - sizing type boilerplate at the bottom to switch between a percentage of portfolio to each trade vs compare 1 unit traded, makes it easier to compare - apples vs apples.
Here's how the plot would show up with general SPY stock price plotted in the chart above with a default bollinger band - and the signal plotted along with the MA filter lines in the bottom pane:
In the next part, we will look at the pnl for this system - along with some optimizations you can do (or the gotchas thereof), what to look for in general - pnl wise, distribution of pnl - and a few other ratios like Sharpe, max adverse excursions, then perhaps in the next part look at a few other things.
But more importantly - take this as a general framework or a template to test your systems - develop your own systems. That is the only way to have full confidence in the signals and move out of the phase of searching for where the next trade will come from.
So until we meet next time.. adios.
Feel free to play around with the code. Last time I checked Amibroker had a 30-day free trial. (PS: I am not affiliated with them in any way and don't get any fee from recommending them - just something I use as a tool).
Good Trading!
-Gariki