If building and testing last week’s idea was fun, this week was bound to be the opposite. This week’s idea, inspired by the Sofien Kabaar article on Medium, The Fisher Aggregate Index. Detecting Market Tops & Bottoms With Accuracy, gave me high hopes. I like Sofien’s frank analysis on the various ideas he generates for forex systems. He took John Ehlers’ Fisher Transform and tweaked it a little. He then calculated the Fisher Transform for each of 27 periods (3-period Fisher Transform through 29-period Fisher Transform) and averaged those 27 Fisher Transforms. He calls the final value the Aggregate Fisher Index (AFI from here on) and uses it to generate trading signals.
The idea is novel. He is looking for the AFI to hit extremes, like an RSI or other oscillator. When in extremes, take a trade in the opposite direction.
I decided to try his idea for futures. It went downhill from there. I will warn you now, I was only able to properly test this on one instrument, and just barely. Here is what I dealt with this week:
- Short week due to the U.S. Memorial Day holiday
- I burned out the CPU on my main workstation… for real. It had been getting flaky for a while, but I finally killed it. Too many optimizations I suppose.
- Heavy workload outside of trading.
- My workstation, currently awaiting a fresh CPU, where I do most of my development and testing, was offline.
- My laptop is powerful enough, but I was missing some of my trading software, so I could not optimize as I like.
- Then there were the bugs, and I don’t mean the Brood X cicadas.
Here at Systematic Algo Trader, you get to see the development process warts and all. This is the way (of an algo trader).
Phase 1: Plan & Design
1. Trading Idea
I described the Aggregate Fisher Index (AFI) in the Introduction. The main idea behind the Fisher Transform is to try to get transform the price data into a nearly Gaussian distribution (think bell curve). Prices are not random nor are they distributed neatly around a mean. They are chaotic. John Ehlers created the Fisher Transform to try to normalize price data.
Sofien Kaabar takes this a step further.
- Calculate the Fisher Transform for 3-periods and store the value (CummulativeFisher)
- Calculate the Fisher Transform for 4-periods and add to CummulativeFisher
- Repeat for each period through 29-periods
- Divide the CummulativeFisher by 27 and that is the AFI
When the AFI is in the upper extreme (think ‘overbought’), go short. When the AFI is in the lower extreme, go long. It is contrarian trading at it’s core. Insert some risk management and exits, and you are ready to trade.
2. System Definition
I will use the following position sizing:
- Futures: 1 contract
|UpperBound||Double||2.24||Suggested by Kaabar, based on the Golden Ratio plus it’s reciprocal|
|LowerBound||Double||-2.24||Opposite of the UpperBound|
|Price||Double||–||Median price, i.e. High+Low/2|
|LongATR||Double||3||Multiplier for ATR (Average True Range) in our trailing long stop|
|ShortATR||Double||3||Multiplier for ATR in our trailing short stop|
|MyATR||Double||0||20 period ATR for stop loss and trailing stop calculation|
|MaxH||Double||0||Maximum High over n-periods, used in FT calculation|
|MinL||Double||0||Minimum Low over n-periods, used in FT calculation|
|AggFisherIndex||Double||0||Holds the averaged sum of all the FT calculations|
|StopPrice||Double||0||Variable to hold the stop price|
|PosHigh||Double||0||Position High, for trailing stop on long positions|
|PosLow||Double||0||Position Low, for trailing stop on short positions|
- If flat or short and
- AggFisherIndex < LowerBound and
- AggFisherIndex[1 bar ago] > LowerBound and
- AggFisherIndex[2 bars ago] > LowerBound then
- Buy next bar at market
- If flat or long and
- AggFisherIndex > UpperBound and
- AggFisherIndex[1 bar ago] < UpperBound and
- AggFisherIndex[2 bars ago] > UpperBound then
- Sell short next bar at market
- Profit targets: none
- Stop Loss: 1 * MyATR from Entry Price
- Trailing sell stop, PosHigh – (3 * MyATR)
- Trailing buy to cover stop, PosLow + (3 * MyATR)
- Puzzling out the AFI calculation
3. Performance Objectives
The system will meet the following objectives:
|System Type (trend, mean-reversion, day, swing, etc.)||Swing|
|Risk of Ruin||0%|
|Profit Factor||>= 1.5|
|Win Percent||>= 35%|
|Max Drawdown %||< 35%|
|Profit/Drawdown Ratio||>= 2.0|
This idea is S.M.A.R.T.: Specific, Measurable, Achievable, Realistic, Time-bound
4. Market Selection
I wanted to test on energies, currency futures, index futures, and metals. I only ended up with one single instrument.
|Currencies-Futures||Futures: Euro FX||EC||After numerous issues and delays, this one instrument was the best I could do.|
Chart Type, Timeframe, Session, Time Zone:
|Chart Type||Regular Candlestick||Charting is only useful for validating entry and exit signals|
|Timeframe / Interval(s)||Daily, 60, 240, 360, 480 minute|
Phase 2: Build
5. Manual Test
To perform a manual test, I had to write a new indicator for the AFI. That was challenging and educational. The problem I had is that Kaabar uses a modified version of the Fisher Transform, so that threw me off for a while, since I am used to a different algorithm. You can see the result in the Manual test section. The manual test passed for E-mini S&P futures.
There is enough complexity to make it interesting, but I do not feel that this system is overly complex in the entry or exit rules.
7. Unit Test
This was a nightmare of a train wreck in a Category 5 hurricane. Debugging this was a terrible experience. I had issues with:
- Funky AFI calculations (my fault)
- Plenty of zero divisor errors (when you calculate FT 27 times per bar, you are bound to get a few)
- ATR trailing stops not being hit
In the end, I have a pretty little chart to confirm that my unit test passed. Barely.
In the end, I was not able to get ATR stops working. When I have separate code for my exits, it works, which is what you see above. The problem with this is that it makes optimization exceptionally difficult.
Note: Unit Test verifies that the system is executing the trading rules correctly. It is, essentially, quality control.
Phase 3: Test
I had to scrap optimization because I had to have my exits outside of my code, where my optimization engine would not see them. I just went with my default values.
9. Walk-Forward Analysis
This was a failure. I will not bore you with statistics and will allow this equity curve (10 years, daily chart), illustrate it. There is one comment I will make about using a long look-back period: If the look-back period started at trade 80 and my walk-forward analysis stopped at trade 200, this system would look stellar. In fact, the longer period (10 full years), gives me a much better picture.
10. Monte Carlo Simulation
We did not make it this far.
We did not make it this far.
Phase 4: Deploy
We did not make it this far.
Trading System Result: FAIL
Notes and Commentary
I love this idea, I really do. A series of unfortunate events led me to disaster. The reason I show this is to show you that building trading systems is sometime very, very messy. Real life happens, computers crash, tropical storms knock out your power, and a host of other hazards.
From the Continuous Improvement department, here is what I will do for the next version of this system:
- Fix the ATR exits
- Optimize the upper and lower bounds
- Optimize the ATR long and short multipliers
I have the core code, albeit with a buggy exit, but I will bring it back, better than ever. Coding the AFI was the most difficult part, but now I have a new tool for my toolbox.
Thank you for reading and I hope you enjoyed. Feel free to leave a comment below and let me know what you think.
Next week’s idea: It is a surprise. See you next Friday!
- The Fisher Aggregate Index, Sofien Kaabar
- Cycle Analytics for Traders, John Ehlers
- Trading Systems and Methods, 6th Edition, Perry Kaufman
Did you like what you read? Do you want to see more? Subscribe now and receive our weekly email, with the Trading System Idea of the Week and other fun stuff.
Don’t worry, we will never, ever, ever sell, overuse, or donate your email address. Promise.