Fractal Adaptive Moving Average (FRAMA)

FRAMA stands for Fractal Adaptive Moving Average and we have classed it as a Log-Normal Adaptive Moving Average (LAMA).  Created by John F Ehlers (See his original paper or the article from the 2005 edition from Technical Analysis of Stocks and Commodities – Fractal Adaptive Moving Averages), it utilizes Fractal Geometry in an attempt to dynamically adjust its smoothing period to suit the changing price action over time.  The FRAMA theory is extremely clever, but clever theories don’t guarantee good results so we are putting the concept into the ring for the ‘Technical Indicator – Fight for Supremacy‘.

But before we go any further it is important that we understand what we are testing.  So I will explain how the FRAMA works although I must admit it is a bit above the the maths education that I didn’t pay attention to in school.  Also we have put together a free excel spreadsheet containing the Fractional Adaptive Moving Average so you can test it for yourself.

(If you would rather skip the maths then jump to the completed test results here – Is the FRAMA Effective?)

.

FRAMA Topics

.

Test Results – Is the FRAMA Effective?

.

How The FRAMA Works

.

First of all the FRAMA takes advantage of the fact that financial markets are fractal.  A fractal shape is said to be rough or fragmented and can be split into parts, each of which is at least similar to a reduced size copy of the original.  Example: Can you see anything strange about the chart below?

.

The Markets are Fractal.

Without being told would you have known that the left half of the chart above was 5 years of monthly bars and the right half was 15 days on 30 minute bars?  Probably not, because price movements look similar no matter what time frame we are viewing them in.  This characteristic is called self-similarity and defines a fractal shape.

By finding the Fractal Dimension or “D” we get an indication as to how completely a Fractal appears to fill space as one zooms down to finer and finer scales.  Think of it this way: A stock chart is too big to be one dimensional but too thin to be two dimensional so its Fractal Dimension is a reading between one and two.

(For a more in depth look into Fractals and “D” please read this post – The Fractal Dimension)

The FRAMA identifies the Fractal Dimension of prices over a specific period and then uses the result to dynamically adapt the smoothing period of an exponential moving average.

Return to Top

.

Finding The Fractal Dimension of a Shape

.

To find the Fractal Dimension “D” of a shape we cover it with a number “F” of small objects that are various sizes “S”:

D = Log(F2 / F1) / Log(S1 / S2)

What is Log?

For those of you like me who didn’t pay attention in maths class ‘Log’ is short for Logarithm and is the power that a number needs to be raised to in order to produce a given result.  Unless otherwise stated the base number is 10, therefore:

Log(1000) = 3

Because

10^3 = 10 * 10 * 10

10^3 = 1000

After that quick maths lesson lets calculate the Fractal Dimension for a line segment that is 10 meters long.  First select two small dimensions such as S1 = 1 meter and S2 = 0.1 meters.  By placing boxes of these sizes on the line segment we can fit 10 of the one meter size and 100 of the 0.1 meter size.  So F1 = 10 and F2 = 100.  Therefore:

D = Log(F2 / F1) / Log(S1 / S2)

D = Log(100 / 10) / Log(1 / 0.1)

D = Log(10) / Log(10)

D = 1 / 1

D = 1

Because D = 1 we have revealed that the Fractal exists fully in one Dimension which makes sense because the measured shape was just a flat line.

For a second example instead of a flat line lets use a square that is 10 x 10 meters.  Keeping S1 and S2 the same we now get F1 = 100 and F2 = 10,000 therefore:

D = Log(F2 / F1) / Log(S1 / S2)

D = Log(10,000 / 100) / Log(1 / 0.1)

D = Log(100) / Log(10)

D = 2 / 1

D = 2

Because D = 2 we have revealed that the Fractal has completely filled two dimensions which makes sense as the measured shape was a square and a square requires two dimensions to exist.

Unfortunately stock prices lack this regularity but are still self similar.  So, in order to discover the “D” of stock prices we must average the measured Fractal Dimension over different scales.

Covering a price curve with a series of small boxes is far too cumbersome but because price samples are uniformly spaced (each bar is 1 day, 1 week, 10 min etc) Ehlers decided that the average slope of the curve could be used as an estimation of the box count.  This is far less complicated than it sounds as the slope is found by simply taking the highest price over a period minus the lowest price during that period and dividing the result by the number of periods.  We will call this measure “HL”, therefore:

HL = (Max(High,N) – Min(Low,N)) / N

N = Periods

We will need to find the “HL” measure (slope) over the first half, second half and full length of “N” to help us find “D”, clear as mud?

Return to Top

.

How to Calculate a Fractal Adaptive Moving Average

.

It starts with the Close price.

FRAMA(N-1) = Close

After that FRAMA is calculated according to the following formula:

FRAMA = FRAMA(1) + α * (Close – FRAMA(1))

You will notice that this is the same as the formula for an Exponential Moving Average (EMA):

EMA = EMA(1) + α * (Close – EMA(1))

But Alpha in an EMA is α = 2 / (N + 1) so it remains constant while for the FRAMA α = EXP(W*(D – 1)) making it adapt as the Fractal Dimension changes.

What is EXP?

EXP is known as the Exponential Function, it is like Log but instead of an assumed base of 10 it has a base of “e”.  So x = Log(10^x) and x = EXP(e^x) where “e” is approximately 2.718281828.  Confused yet?  “e” is a unique number because the slope of its curve is 1 when x = 0 and it solves the compound interest problem.

Didn’t know there was a problem with compound interest?  Neither did I.

You see if you invest $1 at an interest rate of 100% calculated annually, at the end of the first year you will have $2; simple.  But if you compound the interest during the year it gets a bit more complicated.  When interest is compounded every 6 months you can find the result for the year by multiplying $1 by 1.5 twice, so $1.00 × 1.5^2 = $2.25.  If the interest is compounded quarterly then the result is $1.00 × 1.25^4 = $2.44, and monthly it is $1.00 × 1.0833…^12 = $2.613035….

Notice how each time you increase the frequency of compounding you get a larger result?  This is the ‘compound interest problem’.  However if you invest $1 with a return of 100% each year and the interest is compound constantly then the result is ‘e’.

So why did Ehlers use EXP?

If a number “Y” has a random variable with a Normal Distribution then EXP(Y) has a Log-Normal Distribution.  Stock prices are said to be Log-Normal so EXP is used to relate the Fractal Dimension to Alpha.  Keep reading this will make more sense soon…

What is Log-Normal and why does it describe stock prices?

(In theory) the percentage change to achieve possible future stock prices at the end of a period is Normally Distributed.  That is; the change will result in a positive or negative return and 95% of the outcomes should fall within two standard deviations of the mean.  (In reality price changes aren’t normally distributed – Michael Stokes explains Fat Tails)

The possible prices that will result from those changes can range from zero and infinity.  This is because a stock can’t drop more than 100% as that would result in a negative price but a it can more than double.  Therefore prices are said to be Log-Normal.  This concept really confused me at first but a picture is worth a 1000 words so:

.

Stock Prices are Log-Normal.

To show that stock prices are roughly Log-Normal I calculated the price change over the prior year for the last 10,000 market days on the Dow.  In theory these results are Normally Distributed so by finding their EXP and plotting the frequency each result occurs, the above chart reveals the most probable closing prices for the Dow in one years time.

Now if a number “Y” is Log-Normal, then Log(Y) will be Normally Distributed.  So if stock prices are indeed Log-Normal then by taking the Log of the price changes on the above chart we should get something that looks like a bell curve:

.

Price Changes are Normally Distributed

.

Above you can see a bell curve (all be it an ugly one) that displays the probability of any percent chance on the Dow over the next year between -20% and 25%.  So hopefully that explains what Log-Normal is and why it is a characteristic of stock prices… Here ends the maths lesson.

Return to Top

.

How to Calculate a Fractal Adaptive Moving Average – Continued

.

FRAMA = FRAMA(1) + α * (Close – FRAMA(1))

Where:

α = EXP(W * (D – 1))

D = (Log(HL1 + HL2) – Log(HL)) / Log(2)

Note: Log(2) = Log(N / (½N))

HL1 = (Max(High,½N..N) – Min(Low,½N..N)) / ½N

HL2 = (Max(High,½N) – Min(Low,½N)) / ½N

HL = (Max(High,N) – Min(Low,N)) / N

N = FRAMA Period, must be an even number.

W = -4.6 (Set by Ehlers but can be changed.  See: Modified FRAMA)

If Alpha < 0.01  then Alpha = 0.01

If Alpha > 1 then Alpha = 1

Return to Top

.

Finding The Fractal Dimension, Examples

.

Lets have a look at some theoretical stock prices and the resulting Fractal Dimension:

.

FRAMA, "D" - Example

.

Above are three price curves, now lets calculate the “D” for each where “N” = 100.

D = (Log(HL1 + HL2) – Log(HL)) / Log(2)

So:

FRAMA Calculating "D"

.

For ‘Curve A’ the full range is repeated in both halves of the chart so it exists fully in two Dimensions and D = 2.  For ‘Curve B’ only half of the range is repeated in each half of the chart so it exists in between one and two Dimensions or specifically D = 1.58.  The range for ‘Curve C’ is not repeated at all between the two halves of the chart so it exists in only one Dimension and D = 1.

Return to Top

.

How does the Fractal Dimension “D” affect the Smoothing Period “N”?

.

The FRAMA adapts between being a Fast or Slow EMA based in the Fractal Dimension of stock prices.  Ehlers designed the slowest possible EMA to be approximately 200 periods in duration and the fastest to have a period of one or in other words be equal to the price itself.  So for the three curves from our previous example, lets see how “D” changes “α” and how that affects “N” or the smoothing period of the resulting EMA:

α = EXP(W*(D – 1))

N (EMA) = (2 – α) / α

(Ehlers set “W” as -4.6, but it can be changed. See: Modified FRAMA)

.

How "D" Affects "α" and Resulting "N".

When D = 2 as with ‘Curve A’ the result is an Slow EMA of 198 periods while when D = 1 as with ‘Curve C’ the result is a Fast EMA of one period (the close price itself).

.

“This adaptive structure rapidly follows major changes in price and slowly changes when the prices are in a congestion zone.” – John Ehlers

Return to Top

.

Modified FRAMA

.

Ehlers rigidly set the FRAMA to shift between a Fast EMA of 1 period (lets call it FC) and a Slow EMA of 198 days (lets call it SC).  But because we are going to be entering the FRAMA in the ‘Technical Indicator – Fight for Supremacy‘ I wanted to be able to specifically define the “FC” and “SC” of my choice.

Special thanks to Prospectus – “Real Rocket Scientist, Wanna-be Trader” for his help on this section, be sure to subscribe to his blog and follow him on twitter.

So instead of setting “W” as -4.6 as Ehlers did, lets make W = LN(2 / (SC + 1)).  This results in a FRAMA that shifts between a “FC” of 1 and a “SC” of your choice.  For example where SC = 200, W = -4.61015.  Ehlers obviously rounded this off hence his setting of -4.6.

What is LN and why do we use it to find “W”?

LN is an abbreviation for ‘Natural Logarithm’ and is the inverse of EXP; so if EXP(1) = x then LN(x) = 1.  Because EXP is used to relate the Fractal Dimension to Alpha, LN is used to find “W”.

Now in order to set the Fast MA or “FC” of your choice simply take the resulting EMA period “N” and adjust it to fit the new range.  For example if SC = 100 and the resulting N = 50 but instead of the standard SC = 1 we want to change it to SC = 20, the following formula will reveal the “New N”:

New N = ((SC – FC) * ((Origional N – 1) / (SC – 1))) + FC

New N = ((100-20) * ((50 – 1) / (100 – 1))) + 20

New N = (80 * (49 / 99)) + 20

New N = 60

This is then easily converted back into Alpha:  New α = 2 / (New N + 1)

Modified FRAMA additional rules:

SC = Your choice of a Slow moving average > FC

FC = Your choice of a Fast moving average < SC

If Alpha < 2 / (SC + 1)  then Alpha = 2 / (SC + 1)

If Alpha > 1 then Alpha = 1

FRAMA(N-1) = SUM(CLOSE, H)/H

H = EVEN( ((SC – FC) / 2) ) + FC

If N-1 < EVEN( ((SC – FC) / 2) ) + FC then H = N-1

Return to Top

.

FRAMA Excel File

.

We have put together an Excel Spreadsheet containing the FRAMA and made it available for FREE download.  It contains a ‘basic’ version of John Ehlers FRAMA and our Modified version along with a ‘fancy’ one that will automatically adjust to the settings that you specify.  Find it at the following link near the bottom of the page under Downloads – Technical Indicators: Fractal Adaptive Moving Average (FRAMA).  Please let me know if you find it useful.

.

FRAMA and a Simple Moving Average

.

FRAMA and a Simple Moving Average

Return to Top

.

Fractal Adaptive Moving Average Test Results

.
We tested the FRAMA through 300 years of data across 16 global markets, see the results now – Is the FRAMA Effective?
.
.
.

Michael Stokes explains why – Fat Tails

Technical Indicator – Fight for Supremacy

Which Technical Indicators are Best?There are a vast number of technical indicators out there but which ones are best?  Are any of them suitable for use in a mechanical trading model?  Do any of them actually provide value over a buy and hold approach?  In my experience most of the publicly available technical indicators are of little, if any value.  All of our best performing models are build on completely new ideas that deviate from conventional approaches to technical analysis almost entirely.

But questions remain: what length of moving average provides the best signals?  Is it better to use a simple or exponential moving average?  Quality answers to these questions are few and far between and often the process people use to establish such answers are majorly flawed.

.

Common Flaws in Testing Technical Indicators and Systems

.

  • Curve Fitting – Only Testing On One Stock or Index (usually the S&P 500) Even if a test period covers many years of data to only test one index will produce results that fit that curve.  Also the US market has been one of the top performers over the last 100 years but will it be a top performer over the next 100?  Japan has experienced a bear market over the last 20 years so vicious that it has seen the the Nikkei 225 down over 80% from its peak.  To get an accurate idea of the effectiveness of an indicator it must be tested on several unrelated securities across the full spectrum of performance possibilities..
  • Testing A Range Of Individual Securities There are several misleading factors that come from testing a range of individual securities, the most troublesome one being the survivor-ship bias.  If I was to test a random selection of stocks then one necessary criteria would be to select from a group of stocks that had been around long enough to provide adequate data for testing.  But by selecting from stocks with enough data I would only be selecting randomly from stocks that had survived over that period and would be ignoring those that failed or had been de-listed.  This is not how things work in the real world and would produce artificially inflated results..Another challenge with testing idividual securities is choosing the sellection criteria for which stocks to include.  At which point should a cut off be made based on price, volume, market cap etc?  Some stocks are going to have an excess or lack of volatility and there may be a large amount of noise in the data.  This will make it difficult for even the best technical indicators to produce profitable signals and to limit losses.

.

A Less Flawed Method

.

There is no perfect way to test an indicator or system using historical data because past performance is no guarantee of future results.  However the markets are driven by human emotion and crowd psychology.  I believe that this behavior follows repeated patters and that effective historical testing can identify these patterns.  In this way we can look to the past for an indication of the likely future.

In an attempt to be more effective at identifying patterns that are likely to repeat as opposed to coincidental repetition of behavior from the past, we will test across several global indexes that have many years of accurate data available.  This way there is no survivor-ship bias and each indicator can be tested through varying market types.  Here is a list of the 16 global indexes that will be used for the testing process along with the data range for each:

.

Technical Indicator Test Periods

.

That is a total 109,539 days or 300 years* of data covering extended bull, bear and crab markets.  I am confident that due to the size of this data sample identifying the best parameters for each indicator through brute force of testing them all will not result in curve fitting and the statistics obtained will provide an accurate platform for a bare knuckle, Technical Indicator – Fight for Supremacy.^

.

Human psychology molds the value system that drives a competitive market economy.  And that process is inextricably linked to human nature, which appears essentially immutable and, thus, anchors the future to the past. – Former Fed Chief Alan Greenspan

.

Technical Indicators On The Fight Card (So far) – more

.

Moving Averages – info

.

 

  • Simple Vs Exponential Moving Averages, CompletedResults
  1. Simple Moving Average (SMA)
  2. Exponential Moving Average (EMA)
  3. Double Exponential Moving Average (D-EMA)

.

  • Double Vs Triple Exponential Moving Average, CompletedResults
  1. Double Exponential Moving Average (D-EMA)
  2. Triple Exponential Moving Average (T-EMA)

.

  • Reduced Lag Moving Averages
  1. Zero Lag EMA (ZL-EMA)
  2. Almost Zero Lag EMA (AZL-EMA)
  3. Zero Lag Error Correcting EMA (EC-EMA)
  4. Hull Moving Average (H-MA)
  5. Modified Moving Average (M-MA)
  6. 3rd Generation Moving Average (3G-MA)

.

  • Weighted Moving Averages, CompletedResults
  1. Weighted Moving Average (W-MA)
  2. Triangular Exponential Moving Average (TriW-MA)
  3. Sine Weighted Moving Average (SW-MA)

.

  • Mixed Moving Averages, CompletedResults
  1. Time Series Forecast or Moving Linear Regression (TSF)
  2. Linear Regression Indicator (LRI)
  3. Wilder’s Smoothing AKA Smoothed MA (WS-MA)
  4. Triangular Simple MA (TriS-MA)

.

Intelligent Moving Averages

.

These require a volatility index or ratio of some kind and we will be testing the following as components:

  1. Standard Deviation Ratio (SDR)
  2. Efficiency Ratio (ER)
  3. Relative Volatility Index (RVI)
  4. Vertical Horizontal Filter (VHF)
  5. Fractal Dimension (D)
  6. Z Score (ZS)
  7. Chaikin’s Volatility (CV) >
  8. Dreiss Choppiness Index (CI) >

> We currently lack High and Low Prices for some test markets.

.

 

  1. Standard Deviation RatioCompletedResults (SDR-VMA)
  2. Efficiency RatioCompletedResults (ER-VMA)
  3. Relative Volatility IndexCompletedResults (RVI-VMA)
  4. Vertical Horizontal FilterCompletedResults (VHF-VMA)
  5. Fractal Dimension CompletedResults (D-VMA) 
  1. Efficiency RatioCompletedResults (ER-AMA)
  2. Fractal DimensionCompletedResults (D-AMA)
  3. Standard Deviation RatioCompletedResults (SDR-AMA)
  4. Relative Volatility IndexCompletedResults (RVI-AMA)
  5. Vertical Horizontal FilterCompletedResults (VHF-AMA) 
  1. Fractal Adaptive Moving Average (FRAMA) CompletedResults
  2. Standard Deviation Ratio
  3. Efficiency Ratio
  4. Relative Volatility Index
  5. Vertical Horizontal Filter

.

  • Other Intelligent Moving Averages
  1. McGinley Dynamic Indicator
  2. MESA Adaptive Moving Average and Following Average FAMA (MAMA)

.

MACD

  1. Moving Average Crossovers – Completed – Golden Cross – Which is the best?
  2. Moving Average Convergence Divergence (MACD) – CompletedResults
  3. ZeroLag MACD (ZL-MACD)
  4. MACD Z Score (MAC-Z)

.

‘Index’ Indicators

  1. Relative Strength Index (RSI) – CompletedResults
  2. Relative Momentum Index (RMI)
  3. Dynamic Momentum Index (DMI)
  4. Relative Volatility Index (RVI)

.

Oscillators

  1. Stochastic Oscillator (SO)CompletedResults
  2. Stochastic Momentum Index (SMI)
  3. Projection Oscillator (PRO)
  4. Ultimate Oscillator (UO)
  5. Rolling EV Ratio (R-EVR)

.

Mixed Indicators

  1. Parabolic SAR (PSAR)
  2. Aroon (AN)
  3. Directional Movement (DM)
  4. Smoothing the Bollinger %b (SB%b)
  5. Vertical Horizontal Filter (VHF)

.

It is going to take a while to work through all of this and compile the data so we will update it regularly with the latest results.  Are there any indicators that you think we should add to the list or trading systems that you want tested? To be suitable for testing they must be able to produce clear entry and exit signals and not require volume data (we don’t yet have access to enough historical volume).  If you have any of the formulas that we are missing or wish to add an indicator to the fight card then the formula would be preferred in excel format.

And now… for the 1000s in attendance and the millions watching around the world, Ladies and Gentlemen, LLLLLET’S GET READY TO RUMBLE!

.

 

 

  • * Unless otherwise stated 104 weeks of data for each index has been ‘left in’ as lead time for indicators that require a lot of data to get their first signal such as a 50 week double exponential moving average.  On some occasions this lead time may not be enough and this could negatively affect the results for an indicator with a massive lead in time because the additional down time (the early 90s) was typically a bullish period globally.
  • ^ All testing has and will be performed mechanically and every effort is made to ensure accuracy but there is the possibility that some errors have over looked.  Please do your own research and remember that the information provided here is for entertainment purposes only.
Log Normal Moving Average