This is a larger than normal download
8-7-2006
Welcome and hope you find these files of use to you
This zip files includes the following:
FIR2a.afl
8/6/06
Bruce Robinson-
I isolated the
coefficients and the FIR() routine in the AFL that you posted on 8/1. Then, I
added a faster FIR2() routine, and some TRACE output for timing. I explained it
in the comments. What is posted below is a standalone test program.
Anyway, it is a strict adaptation of the original with no assumptions. For
example, note that the filter coefficient array is symmetrical - IOW, entries 0
= N-1, 1 = N-2, etc. But, I reversed it anyway in another array for the FIR2()
technique so as to not depend on that assumption.
The only exception is that I changed the original variable "L" to "LP". I think
that it is from Dave's original and it isn't a good idea to use a reserved array
variable (L = Low) for a program scalar .
I believe that the result differences are attributable to round-off error and
that the original works backward with descending subscripts to get a sum of
products. FIR2() works forward using the Cum() function. This kind of thing
should really be done with double precision floats !
Should be 10x+ faster. Good luck.
Cycle Etch-a-Sketch.afl
& Cycle Etch-a-Sketch.png
8/8/06
Fred Tonnetti-For
the Cycle oriented folks out there ... and maybe some who aren't.
Quickly draw up 6 to cycle periods and amplitudes forwards and backwards from
whatever reference point ( typically a bottom or top ) on the chart as well as a
composite based on the 6 individual cycles and their amplitudes.
Each cycles periodicity and amplitude can be individually controlled ( Via
Sliders ) by setting Length Factor and Amplitude Factor to 0 or All Length and
Amplitudes can be increased / decreased proportiantely together using the
sliders for Length and Amplitude Factor.
This allows one for example to produce curves like the one below ( bottom pane )
relatively quickly which doesn't look totally unlike the chart in the top pane.
PS The keyboard Left and Right arrow keys work better ( smoother ) on the
sliders then the mouse does
FIRZ.afl , FIR coef1a.zip, FIR coef2a.zip, FIR coef1b.zip, FIR coef2b.zip,
FIR coef1c.zip, FIR coef2c.zip, Cycle predictions.xls
8/8/06
David Howarter-
FIR Cycle
Analysis –
We have made some major improvements to the FIR cycle analysis approach that I
posted on July 31, 2006.
First, Bruce
suggested a better way to implement the loop that was consuming a lot of time
and that resulted in a significant increase in processing speed. Thanks Bruce!
Next, Fred Tonetti has been collaborating with me and he has implemented several
good improvements on my first approach to using the FIR filter. He had a number
of good ideas for improvements and he did the majority of the work in
implementing them into AB. The second version I am posting below started with my
original ideas but now is at least 50% Fred’s work and ideas. I really
appreciate what he as contributed to this as that has included both very
important ideas on the basic approach and some clever AB programming that I
would never have come up with.
So the changes from the version that I previously posted include the following:
-- use external filter coefficients so one .afl can be used for all filters
-- VBS file to create all the required filter coefficients in one run
-- improved graphical display
-- automatically iterate and calculate best target period for each FIR filter to
replace the manual method I had been using.
-- speed improvement using code designed by Bruce Robinson
This is still a work in progress and we have not yet done backtesting or
walk-forward testing of the approach, but I want to post the current version, as
I think it is quite a bit better than the previous version. Part of the reason
for these changes was to set it up so that backtesting and walk-forward testing
could be done, so hopefully we will get that going soon.
The steps to use the current version are as follows:
1. I am going to attach two files FIR_coef1.zip and FIR_coef2.zip that together
include all the coefficients to make FIR filters with target periods from 2 to
550 days. Actually the current AB .AFL searches on either side of the initial
target period to find the target period that matches the average period of the
last three complete sinusoidal cycles, so in practice these filters are good for
filter targets from about 6 to 450, which gives enough extra on each end for the
AFL to find the best filter period. If you stay within that range you don’t need
to use SciLab to create coefficients as I had documented in my previous post.
You must manually create a directory C:\temp\ on your computer and unzip all the
coefficient files from these two zip files into that directory. The AFL will
pick up the values from these files.
2. If you do want to create more filter coefficients for other periods than the
above contains, Fred has created a nice file FIRZ.VBS that will automate calls
to SciLab and create as many filter coefficients as you want in a short period
of time. Fred is in the process of updating this to tweak the user interface and
will post it within a day or two.
3. I am attaching a file FIRZ.AFL. This is the file used to create the FIR chart
panes. It must be moved into your C:\Program Files\Formulas\Custom\ directory.
Then you want to open six or seven chart panes each with this file. After you
get a chart pane open, right-click on it and then left click on “Parameters”.
The first parameter box, “Cycle Period”, is used to set the initial target
period of the FIR filter. The other parameters that can be set from the
parameter box are for special testing and can all be left at their default
values. The AFL code will then iterate around this and find the target period
which produces the most stable results for the three cycles leading to the last
day of data. I suggest you start with target periods of 13, 25, 50, 100, 200,
350, and 450 days.
4. I am attaching a new screenshot, fir_red_green_blue, which is the output of
the filters for data to 8/4/06. There are seven panes of FIR output and each
shows the final target period that the FIR filter was centered on. The new
output contains only one plot per pane, which is the FIR output. It is colored
green when the cycle is increasing and red when it is decreasing, so it is easy
to see the current status. At the right hand edge, the AFL code attempts to
extrapolate for 20 days beyond the current day to show what the cycles are
likely to do in the near future. This part of the plot is colored blue. In order
to see these you must have an option set in AB. Under the Tools pulldown, and
“preferences”, “blank bars in right margin” must be set to 20 or higher. Also
after you set that you may need to scroll the screen to the right to see the
blue plot. This extrapolation is a guess based on past data and at times may be
significantly wrong if the cycles have been inconsistent in the preceding days,
so use it with caution. The plot also marks the location of each cycle valley
and the number of periods from the previous cycle valley, so you can easily see
how regular the cycles are or aren’t.
5. Fred convinced me that the periods determined by measuring valleys were more
reliable than those by measuring peaks, so I changed the cycles_prediction.xls
file that I had created to help me visualize what the cycles were likely to do
in the near future so that the predictions were based on the last valley. I will
attach a copy of that file and a screenshot of the current status. It is
interesting that it is now predicting an upswing in the market about August 21
or 22, which I believe is the same time frame as some of Selim’s work predicts
one. However, the longer period cycles are still going downhill at that time and
the Prez2 cycle may overwhelm all of the shorter cycles, so use your own
judgment on this.
Although I have not
yet done backtesting of this concept, I have seen it produce enough regular
sinusoidal cycles, that I think the cycles are real and can provide some
significant predictive capability. It is not perfect for several reasons. First,
the cycles change at times due to influences of other cycles or of external
non-cyclic events. Secondly, when the input does not contain perfect sinusoids,
the filters will introduce some time shifting of the waveform, so you can’t 100%
trust the output sinusoidal waveform to be where it appears to be. We introduced
the automatic searching of the FIR to find the best period for the waveform to
try to minimize this shifting, but there will always be some degree of error due
to this. My testing indicates that the measurement of the periods of the cycles
found is pretty accurate, even if the cycle’s location in time is shifted some.
Therefore, I trust that the cycles found do represent some inherent cyclical
action that one can make use of. If you look at the cycle waveforms versus past
turns in the markets, I think you will find some definite correlations. And
since the waveform is a sinusoid, you can make a prediction when it is
approaching a peak or a valley and potentially get a faster entry or exit than
you get from other methods that have to wait until some of your money has
disappeared before the signal fires.
One of the points that the filter outputs is indicating is that the inherent
cycles do follow a pattern of approximately doubling in period, as Hurst stated,
but the filter outputs indicate that the relationship of the periods shorten
some when the period is about 100 or larger, so instead of doubling, the filters
are finding periods of 49, 91, 176, 312, and 497. Also the fact that it finds
consistently 21 or 22 days, rather than the 25 days Hurst used is interesting
since that is approximately the number of trading days in a month and may match
the monthly seasonality.
I am sure there will be more to come on this in the near future.
Dave H.