I have been trying to reproduce and understand the Hurst (Ormsby) Band-pass filter example as described in The Profit Magic of Stock Transaction Timing book (page 178). I am not as strong at mathematics as I would like to be, however I am trying to learn and understand more as I explore the mathematical approach of cycles demonstrated by Hurst.
I started in Excel and migrated the process to a Metatrader 4 indicator. However I am not sure if I have understood the design process, calculation and the interpretation of the filter output correctly.
I will outline the process I have taken and reach out to those that may understand filters better than I to assist with some questions I have.
Building the bandpass example in Excel (p.181)
t=7 (time spacing in weeks)
n=Odd Number of weights = 199
Midpoint weight = (n-1)/2 = (199-1)/2 = 99
wn = (104*pi) / t = 46.6750908533341
Presumably as the filter w1->w4 parameters were in rad/yr 104 is the number of data points on weekly chart per year (52) * 2 ?
Lambda1 L1 = w1/wn = 0.85/46.6750908533341 = 0.018210998
Lambda2 L2 = w2/wn = 0.02678088
Lambda3 L3 = w3/wn = 0.043920643
Lambda4 L4 = w4/wn = 0.052490525
Lambda5 L5 = L1-L2 = -0.008569882
Lambda6 L6 = L4-L3 = 0.008569882
RadLambda1 RL1 = 2PIL1 = 0.114423077
RadLambda2 RL2 = 2PIL2 = 0.168269231
RadLambda3 RL3 = 2PIL3 = 0.275961538
RadLambda4 RL4 = 2PIL4 = 0.329807692
RadLambda5 RL5 = 2PIPIL5 = -0.169162681
RadLambda6 RL6 = 2PIPIL6 = 0.169162681
Calculating the Weights
Calculating the weights (p.182)
weight 1A = (COS(RL3)-COS(RL4)) / (RL6) = 0.094932
weight 1B = (COS(RL2)-COS(RL1 / (RL5) = 0.044836797
weight 1 (A-B) = 0.050096
weight 2A = (COS(RL3WeightNo)-COS(RL4WeightNo)) / (RL6WeightNoWeightNo) = 0.09057818
weight 2B = (COS(RL2WeightNo)-COS(RL1WeightNo) / (RL5WeightNoWeightNo) = 0.044373564
weight 2 (A-B) = 0.046204616
Repeat until weight 99 (midpoint)
Midpoint Weight 100
100A = L3+L4 = 0.096411167
100B = L1 +L2 = 0.044991878
100 A-B = 0.051419289
Then weights 101-199 is a mirror of the first 99, so use weight no 99 for weight 101, no 98 for 102 etc.
Total of all weights = 0.004160528
Total weight / no of weights = 0.00002090717486445620
Then subtract that (0.00002090717486445620) from each of the 199 weights for final weight values.
Weight 1 Final = 1AB (0.050095536) - 0.00002090717486445620 = 0.05007462833448080000 etc…
Application of the Filter:
I migrated the above logic to Metatrader and created a indicator to plot the filter output. To help aid in checking the output, I created a utility to compute sine wave(s) with an offset, amplitude and frequency and write to Metatrader History files which can be opened as offline charts and the filter indicator is applied.
I created a weekly chart with price data (wavelength) that was 234 bars (4.5 years) long with offset of $10.00 and an amplitude of $10.00.
Observed the filter output that the first 99 and last 99 bars were 0 which I understand is to the expected as that is the midpoint of the weights. The filter output showed an oscillating sine wave the same wavelength with peaks at approx. -0.1595 and troughs at approx. -1.3482 (amplitude of 1.1887)
What I was expecting however was an amplitude of 10 oscillating +5 and -5 around the 0 line.
I then tested adding an additional smaller cycle of 20 weeks and $3 amplitude to the chart.
The filter output still appears to have passed the short 20 week cycle which I didn’t expect.
Can anyone who has attempted the bandpass filter comment if I have made the calculations in Excel correctly?
Page 181 says:
These design choices provide 50% or more filter response across a pass-band of frequencies corresponding to sinusoidal components with periods of 2.8 to 6.0 years. Such a filter is suitable for investigation of oscillations of the order of four and a half years’ duration-a dominant element of the price-motion model.
How do the values of the example bandpass (w1 = 0.85, w2 = 1.25, w3 = 2.05, w4 = 2.45) as radians/yr equate to passing cycles of 2.8 and 6.0 years when used on a weekly chart using 7 periods. i.e. if I wanted a bandpass filter on a weekly chart the passed between 30 and 50 weeks, how do I calculate the w1,w2,w3,w4 values as radians/yr ?
I am not sure if I have not calculated the filter weights correctly or if I have made a coding error in the computation of the filter output correctly int MT4.
Should I expect to see the full $10 amplitude of my 4.5 yr price cycle data shown in the output of the filter?
i.e. if the 4.5 years is between w2 and w3 then the amplitude should be pass as 1.0 (ie unchanged).
And if so, should the filter output oscillate evenly around the 0 line, eg $5 peak and -$5 trough, even if the raw data starting price was $10 with the cycle ranging between $10 and $20.
Should I expect the filtered output to have filtered out the $3 amplitude 20 week data that was combined with the 4.5 yr data in the output? (ie if 20 weeks was less than w1 of the filter design it should have been reduced to amplitude to 0.)
Thanks in advance.