PureBytes Links
Trading Reference Links
|
Louis,
I have no argument against using price in your logic. I've simply
said that that is not what Aronson is describing. Use any of the
price detrending already posted by others for that (e.g. moving
average).
No, I don't treat a 10% drop on a $200 stock any differently than a
10% drop on a $2 stock. 10% is 10% any way you look at it. If your
position size is $1000, you've lost $100 in both cases. In both cases
you've got 90% of your investment left.
More important is the typical price variance. Setting a fixed 10%
stop loss on a stock that regularly swings up and down by 12% is a
good way of losing 10%.
What do you care if your strategy has a long or short bias? There's
nothing wrong with a position bias so long as it is proven to be
stable and profitable.
The only reason Aronson does what he does is to seperate the
performance related to the interaction of your position bias with the
prevailing trend of the market vs. the purely predictive value of
your strategy.
To use a simplistic example; In a market that always sets higher
highs every single day, any long only strategy that takes a position
will be profitable.
When the market is not always rising, how much of that long only
performance is based on predictive ability and how much is just lucky
for landing on the days that happened to be higher than the previous.
That is what Aronson is attempting to answer.
Finally, don't confuse "random walk" with "walk forward".
--- In amibroker@xxxxxxxxxxxxxxx, "Louis Préfontaine"
<rockprog80@xxx> wrote:
>
> Hi Mike,
>
> I understand what you say, an 95% of times you will be correct.
However,
> sometimes a rule can be based on the price alone. As an example, I
want to
> set different stoploss % depending on the price of the stock. I
think you
> will agree with me that 10% on a 2$ stock is not like 10% on a 200%
stock.
> So my rules might be different depending on the price of the
stock. I don't
> know if this is a correct strategy (maybe this is dumb, but I don't
think
> so, so far, because I can tolerate more volatility with penny
stocks then
> with stocks over 50$), but I think you understand that any rule
with this
> kind of stuff would not get to the validation point in the
detrending
> processus. That is why I was looking for some kind of way to
subtract the
> ALR from the daily stock prices. But again, maybe this is stupid,
I don't
> know. But I think it can make things work better.
>
> Basically, at the end of it, if you want to know if your rules have
a
> positive/negative bias, you simply calculate manually the numbers
of days in
> which you are long versus the number of days which you are short,
and if you
> get a result too far away from each other then you might have a
problem. Is
> this right?
>
> I see that my AB seems to recognize the RWI function. Is there any
easy way
> to use that random walk?
>
> Thanks,
>
> Louis
>
>
> 2008/3/3, Mike <sfclimbers@xxx>:
> >
> > Louis,
> >
> > I think that you need to re-read the book (or maybe I do!).
> >
> > It sounds like you are confusing detrending prices for use with
> > strategy *logic* vs. detrending daily price _changes_ for use with
> > strategy *validation*.
> >
> > Again, this is all based on my understanding of the book...
> >
> > The intention is not to have adjusted _prices_. The intent is to
have
> > adjusted price _changes_. A detrended market _change_ array will
have
> > an average price change of zero.
> >
> > You then multiply your strategy _signal_ against the detrended
> > changes to see whether you would end up with a non zero result.
> >
> > You do *not* use the detrended data in any way when writing your
> > strategy logic. It is the _output_ of your logic that gets
combined
> > with the detrended price changes for validation.
> >
> > The Detrend script has already subtracted the average daily change
> > from each individual daily market change. The Results script
simply
> > multiplies your strategy signal by the detrended market change
> > results.
> >
> > As per my original Results.afl post, the code provided attempts to
> > implement Aronson's example which takes signals based on the price
> > activity of the transportation index, and trades those signals
> > against the SP-500. If your strategy does not refer to a different
> > symbol when deciding whether or not to trade, then you don't need
> > SetForeign/RestorePriceArrays.
> >
> > --- In amibroker@xxxxxxxxxxxxxxx <amibroker%
40yahoogroups.com>, "Louis
> > Préfontaine"
> > <rockprog80@> wrote:
> > >
> > > Hi Mike,
> > >
> > > I might have trouble to understand something, because so far
all I
> > see in
> > > the detrend are the daily log differences (as shown in the
image I
> > sent).
> > > You say there is nothing more to do, but I just don't understand
> > why you say
> > > that, because I believe that the only way there would be nothing
> > more to do
> > > would be if there was a way to subtract the ALR (average log
> > return) from
> > > the actual stock prices. e.g. instead of having 0.0000x data I
> > would get
> > > the actual price detrended, which would allow me to set my own
set
> > of rules,
> > > which can vary in function of the price (I do not consider 2$
> > stocks the
> > > same way as 200$ stocks). Do you understand what I mean?
> > >
> > > I must be doing something wrong because both return files do not
> > display
> > > anything that seems intelligible to me. I attached the two
> > examples and as
> > > much as I understand the detrented version of comp.x (thought I
> > just don't
> > > understand how to use that stuff) I really have no idea of what
to
> > do with
> > > the spxreturns, which has this strange graph...
> > >
> > > BTW, why did you compare with a foreign symbol? You say I can
> > remove it;
> > > but what was the purpose of it in the first place?
> > >
> > > Random walks sure looks like a very great feature. Would you
> > consider it
> > > even more useful than detrendin the market, or is it possible to
> > begin with
> > > this and move to random walk later, when I will update to AB
5.0+?
> > >
> > > Thanks a lot. I know that's a lot of questions! ;-)
> > >
> > > Louis
> > >
> > >
> > >
> > > 2008/3/3, Mike <sfclimbers@>:
> > > >
> > > > Louis,
> > > >
> > > > The first script (Detrend.afl) will detrend the market.
Nothing
> > more
> > > > to do. If you want to chart the results, open the symbol in a
> > chart
> > > > and plot the Close using line format (i.e. not bar or
> > candlesticks).
> > > > You will see what appears like an oscillator centered on zero,
> > since
> > > > all the values average out. Similarly, if you plotted a
> > histogram, of
> > > > the Close values, you would get a normal distribution
centered at
> > > > zero.
> > > >
> > > > You must code your own strategy into the second script,
replacing
> > the
> > > > example buy/sell/short/cover with your own logic.
> > > >
> > > > If you are not using a separate symbol to base your signals
on,
> > you
> > > > can remove the SetForeign/RestorePrice arrays. The parts that
are
> > > > most important are the setting of trade delays (since the
> > detrended
> > > > market data was produced with that assumption) and the
generating
> > of
> > > > a new composite.
> > > >
> > > > SetTradeDelays(1, 1, 1, 1);
> > > >
> > > > ...
> > > >
> > > > isLong = Flip(Buy, Sell);
> > > > isShort = Flip(Short, Cover);
> > > > market = Foreign("~" + Name(), "C", false);
> > > >
> > > > AddToComposite(IIF(isLong, 1 * market, 0), "~" + Name()
> > > > + "Return", "C", atcFlagDefaults | atcFlagEnableInBackTest);
> > > > AddToComposite(IIF(isShort, -1 * market, 0), "~" + Name()
> > > > + "Return", "C", atcFlagDefaults | atcFlagEnableInBackTest);
> > > >
> > > > Once your buy/sell/cover/short logic is in place, there is
nothing
> > > > more to do, the resulting composite (e.g. ~SP-500Return) will
> > already
> > > > have every thing you need. If you were to plot a histogram of
the
> > > > Close values, you want to see a normal distribution centered
on a
> > > > value greater than zero, indicating better than chance
results.
> > > >
> > > > Since the second script is *your* trading logic, yes, when
> > running it
> > > > the buy/sell signals and all AmiBroker performance data are
> > relevant.
> > > > If the system does not perform well based on your personal
> > criteria,
> > > > then you really don't care whether or not it is statistically
> > > > significant, because you wouldn't want to trade it anyway!
> > > >
> > > > The only thing that you need to do with the two composites is
to
> > > > compare the results.
> > > >
> > > > Take the mean of the detrended market (e.g. use excel to add
all
> > > > Close values found in ~SP-500 and divide by the number of
values)
> > and
> > > > compare it to the mean of your strategy results (again, add
all
> > Close
> > > > values of ~SP-500Results and divide by the number of values).
> > > >
> > > > If a t-test shows them to be statistically significant, you
> > *might*
> > > > be on to something. According to Aronson (by my
interpretation)
> > you
> > > > would then have to correct for data mining bias.
> > > >
> > > > Note that this is just one approach. Others prefer the much
> > simpler
> > > > walk forward analysis and visually evaluating the equity
curve.
> > Walk
> > > > forward and equity curve evaluation will rule out most of your
> > ideas
> > > > long before you ever need to start doing the statistical
> > validation.
> > > >
> > > > Delaying the statistics until after you've got a nice walk
forward
> > > > equity curve will get you on your way much quicker. Though, if
> > > > possible it would still be preferable to do the statistics at
that
> > > > time.
> > > >
> > > > Walk forward is built in to the most recent release of
AmiBroker,
> > and
> > > > also available in the free edition of Intelligent Optimizer
(see
> > IO
> > > > under Files section of this forum). My understanding is that
> > > > AmiBroker and IO treat the handling of trades accross
boundries
> > > > differently, so don't be surprised if you get slightly
different
> > > > results between them.
> > > >
> > > > Again, I'm no statistician, I wrote the code quickly in the
late
> > > > hours of the night, and I may not have understood correctly
the
> > > > process described in the book. So, use all of this as a
starting
> > > > point, but don't accept any of it as Gospel.
> > > >
> > > > Mike
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx <amibroker%
40yahoogroups.com><amibroker%
> > 40yahoogroups.com>, "Louis
> > > > Préfontaine"
> > > > <rockprog80@> wrote:
> > > > >
> > > > > Hi again Mike,
> > > > >
> > > > > Ok I tried the formula without the "setbacktestmode" and it
> > seems
> > > > to work.
> > > > > I did use the first formula to get the log results of spx.xo
> > (S&P
> > > > 500) from
> > > > > January 9 2007 to December 31, 2007. Then I added all the
> > results
> > > > and
> > > > > divided by the number of days. -->But what do I do with this
> > > > number then?
> > > > > (I know it's the number I want to substract from each day
> > result,
> > > > but od I
> > > > > have to do it manually?)
> > > > >
> > > > > Then I applied the second formula to the same spx.xo for the
> > same
> > > > days.
> > > > > When clicking on "backtesting" buying/selling orders were
> > issued.
> > > > Are those
> > > > > relevant, or do I simply need to look at what's in the new
> > > > ~spx.xoReturn?
> > > > > (I changed DTX--X for spx.xo everywhere in the formula). And
> > when
> > > > I open
> > > > > this ~spx.xoReturn I get the detrended results but how to
use
> > them
> > > > with the
> > > > > actual stock? I mean: I get all those 0. 000x numbers; how
can I
> > > > actually
> > > > > use my trading system to test my positive/negative bias with
> > this?
> > > > >
> > > > > Thank you a lot for your help. Your formulas really rock.
> > Thanks!
> > > > >
> > > > > Louis
> > > > >
> > > > >
> > > > >
> > > > > 2008/3/2, Mike <sfclimbers@>:
> > > > > >
> > > > > > I've provided an example of how to use it below. I'm still
> > > > working on
> > > > > > this myself, so take all of this with a measure of
caution. I
> > have
> > > > > > not yet gone through all results to verify that there
aren't
> > any
> > > > > > bugs...
> > > > > >
> > > > > > If I understand Aronson correctly, after you have have
> > detrended
> > > > the
> > > > > > market for the desired period, you then apply your trading
> > > > strategy
> > > > > > to generate new log daily returns by multiplying your
system
> > state
> > > > > > (+1 for long, -1 for short) by the detrended log daily
> > returns.
> > > > You
> > > > > > then take the mean log daily return generated by your
> > strategy and
> > > > > > compare it to the mean log daily return of the detrended
daily
> > > > > > returns (i.e. zero).
> > > > > >
> > > > > > The purpose is to remove the "conjoint effect of position
> > bias and
> > > > > > trend" from your strategy results.
> > > > > >
> > > > > > If the two means are found to be different (i.e. your
strategy
> > > > > > generates non zero mean) with statistical significance
(e.g.
> > using
> > > > > > student's t-test), then you may conclude* that the returns
> > > > generated
> > > > > > by the strategy are not purely by chance.
> > > > > >
> > > > > > I use a "*" there because Aronson continues to say that a
> > simple
> > > > t-
> > > > > > test is NOT sufficient if you have used data mining to
produce
> > > > your
> > > > > > strategy. In that case, your results will still include a
data
> > > > mining
> > > > > > bias that must be removed by applying the Bootstrap method
> > with
> > > > > > White's reality check, or else the Monte Carlo analysis.
> > > > > >
> > > > > > Now for what you're really looking for, a concrete
example :)
> > > > > >
> > > > > > Still in Chapter 1 of the book, Aronson refers to an
example
> > of
> > > > > > taking signals based on the Dow Jones Transportation
Average
> > (DTX-
> > > > -X
> > > > > > by my data provider), and applying those signals to trade
the
> > SP-
> > > > 500.
> > > > > > The strategy has a long bias and is defined as follows:
> > > > > >
> > > > > > Draw a moving average of DTX--X
> > > > > > Draw an upper band 3% above the moving average
> > > > > > Draw a lower band 3% below the moving average
> > > > > > Short the SP-500 when the DTX--X crosses below the lower
band.
> > > > > > Long the SP-500 at all other times.
> > > > > >
> > > > > > I believe that I have captured these rules and added
> > backtesting
> > > > > > support in the script below. After running the backtest,
a new
> > > > symbol
> > > > > > will be added to your system holding the returns in the
Close
> > > > field
> > > > > > (e.g. ~SP-500Returns).
> > > > > >
> > > > > > Aronson does not say what the moving average should be.
It is
> > > > > > actually a bit of a challenge to find a period where the
> > above is
> > > > > > profitable! However, after optimizing for the moving
average,
> > I
> > > > found
> > > > > > that the period 4/27/1998 - 12/31/2000 will show you fully
> > > > invested
> > > > > > for the entire range with a 13.69% CAR.
> > > > > >
> > > > > > Applying my Detrend.afl script (posted in my last note)
> > against
> > > > the
> > > > > > SP-500 over those dates will give a mean log daily return
of
> > > > 2.40265E-
> > > > > > 10 (i.e. zero).
> > > > > >
> > > > > > You can compute the mean log daily return by opening the
Quote
> > > > Editor
> > > > > > (e.g. select ~SP-500 in symbols tree, then use Symbol |
Quote
> > > > > > Editor... menu item) and copying all the data into Excel,
then
> > > > > > summing all the Close values for the given date range and
> > > > dividing by
> > > > > > the number of quotes in that range (678 in this example).
> > > > > >
> > > > > > Running the script below against the SP-500 for the same
dates
> > > > will
> > > > > > will give a mean log daily return of 0.000428057
> > > > > >
> > > > > > Again, copy ~SP-500Returns from Quote Editor into Excel
and
> > > > compute
> > > > > > the mean from the Close data.
> > > > > >
> > > > > > Peforming a Student's T-Test over the two sets of log
daily
> > > > returns,
> > > > > > assuming a shared variance and hypothesizing a shared
mean of
> > > > zero,
> > > > > > returns a one tailed p-value of 0.272346792. This is well
> > above
> > > > 0.05
> > > > > > (the p-value required to reject the hypothesis with 95%
> > > > confidence)
> > > > > > and so we cannot reject the hypothesis.
> > > > > >
> > > > > > In other words, despite a 13.69% CAR over the period
tested,
> > the
> > > > > > strategy is no better than chance alone and thus should
not be
> > > > traded.
> > > > > >
> > > > > > If the p-value had been .05 or less, we still could not
> > conclude
> > > > > > (according to Aronson) that the strategy was any good
because
> > I
> > > > used
> > > > > > Optimization (MA period ranging from 5 to 200 increments
of
> > 5) to
> > > > > > find the best rule (data mining bias) and because I used
the
> > 3%
> > > > band
> > > > > > width suggested in the book (snooping bias - have no idea
how
> > much
> > > > > > optimization was applied to reach that number). Applying
Monte
> > > > Carlo
> > > > > > analysis would remove the data mining bias (my next
effort).
> > > > There's
> > > > > > no getting around the snooping bias.
> > > > > >
> > > > > > 1. Copy paste the script below to a file on your machine
(say
> > > > > > c:\Program Files\AmiBroker\Formulas\Custom\Results.afl).
Make
> > sure
> > > > > > that you correct any formatting that gets messed up from
this
> > > > post,
> > > > > > such that AmiBroker likes everything. Use the Tools |
Verify
> > > > Syntax
> > > > > > menu from the code editor.
> > > > > >
> > > > > > 2. Open a chart on the symbol that you want to detrend.
For
> > > > example;
> > > > > > Aronson used the SP-500 for all his tests.
> > > > > >
> > > > > > 3. Open the Automatic Analysis Window
> > > > > >
> > > > > > 4. Click the "Pick" button and select the script that you
just
> > > > saved
> > > > > > (i.e. Results.afl).
> > > > > >
> > > > > > 5. Select "current symbol" for the Apply To.
> > > > > >
> > > > > > 6. Select "from" for the Range, and enter a from date and
a to
> > > > date
> > > > > > (e.g. from 4/27/1998 to 12/31/2000).
> > > > > >
> > > > > > 7. Click on Backtest
> > > > > >
> > > > > > A new symbol will be added to your system having the same
> > name as
> > > > the
> > > > > > original, but prefixed with a "~" and appended
with "Return",
> > for
> > > > > > example "~SP-500Return". This symbol will appear in Market
> > 253 and
> > > > > > contain detrended performance results for the range
selected
> > and
> > > > > > zeros for all other dates.
> > > > > >
> > > > > > For each bar in the detrended symbol, the information
will be
> > > > > > arranged as follows:
> > > > > >
> > > > > > Close: The detrended log daily return of the strategy
(i.e.
> > Pos0
> > > > x log
> > > > > > (Open2/Open1) - ALR).
> > > > > >
> > > > > > Note: As per Aronson, Pos0 refers to the strategy signal
(+1
> > for
> > > > > > long, -1 for short), Open2 refers to the Open two days
from
> > now,
> > > > > > Open1 refers to the Open one day from now, ALR refers to
the
> > > > average
> > > > > > log daily return of the market (not your strategy results)
> > over
> > > > the
> > > > > > period being detrended.
> > > > > >
> > > > > > As always, comments, corrections and enhancements are
> > welcomed.
> > > > > >
> > > > > > Again, I'm a software developer, not a statistics guy, and
> > this
> > > > is my
> > > > > > interpretation of the book. Do your own research before
> > accepting
> > > > > > taking this as acurate.
> > > > > >
> > > > > > If anyone else has done any work in this area, I would
very
> > much
> > > > like
> > > > > > to hear if their approach agrees with my interpretation.
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Mike
> > > > > >
> > > > > > SetTradeDelays(1, 1, 1, 1); // All trades on next Open
after
> > > > > > EOD signal
> > > > > > SetBacktestMode(backtestRegular); // One symbol, no
redundant
> > > > signals
> > > > > > SetOption("InitialEquity", 100000);
> > > > > > SetOption("AccountMargin", 100);
> > > > > >
> > > > > > Plot(Close, "Close", colorBlue, styleLine);
> > > > > >
> > > > > > SetForeign("DTX--X");
> > > > > > center = MA(Close, Optimize("MA", 40, 5, 200, 5));
> > > > > > upper = 1.03 * center;
> > > > > > lower = .97 * center;
> > > > > >
> > > > > > Buy = Cross(Close, lower);
> > > > > > Sell = Cross(lower, Close);
> > > > > > Short = Sell;
> > > > > > Cover = Buy;
> > > > > >
> > > > > > Plot(Close, "DTX--X Close", colorYellow, styleLine);
> > > > > > Plot(upper, "DTX--X Upper", colorGreen, styleDashed);
> > > > > > Plot(center, "DTX--X MA", colorPink, styleLine);
> > > > > > Plot(lower, "DTX--X Lower", colorRed, styleDashed);
> > > > > >
> > > > > > RestorePriceArrays();
> > > > > >
> > > > > > BuyPrice = SellPrice = ShortPrice = CoverPrice = Open;
> > > > > >
> > > > > > PlotShapes(shapeUpArrow * Buy, colorGreen, 0, Close, -30);
> > > > > > PlotShapes(shapeDownArrow * Sell, colorRed, 0 , Close, -
30);
> > > > > > PlotShapes(shapeHollowDownArrow * Short, colorRed, 0 ,
> > Close, -
> > > > 40) ;
> > > > > > PlotShapes(shapeHollowUpArrow * Cover, colorGreen, 0,
Close, -
> > 40);
> > > > > >
> > > > > > isLong = Flip(Buy, Sell);
> > > > > > isShort = Flip(Short, Cover);
> > > > > > market = Foreign("~" + Name(), "C", false);
> > > > > >
> > > > > > AddToComposite(IIF(isLong, 1 * market, 0), "~" + Name()
> > > > > > + "Return", "C", atcFlagDefaults |
atcFlagEnableInBackTest);
> > > > > > AddToComposite(IIF(isShort, -1 * market, 0), "~" + Name()
> > > > > > + "Return", "C", atcFlagDefaults |
atcFlagEnableInBackTest);
> > > > > >
> > > > > > --- In amibroker@xxxxxxxxxxxxxxx <amibroker%
40yahoogroups.com><amibroker%
> > 40yahoogroups.com><amibroker%
> > > > 40yahoogroups.com>, "Louis
> > > > > > Préfontaine"
> > > > > > <rockprog80@> wrote:
> > > > > > >
> > > > > > > Hi again,
> > > > > > >
> > > > > > > I've searched thru the manual and I think that += is
simply
> > a
> > > > > > shortcut. I
> > > > > > > wrote total = total+ raw[i]; instead and there is no
more
> > error!
> > > > > > >
> > > > > > > I did exactly as you said and got the sign with those
huge
> > bars
> > > > all
> > > > > > topping
> > > > > > > at 0.267615. I think I understand what you say, but
what is
> > OI?
> > > > > > >
> > > > > > > The thing is: I am not sure how to use this. I think
what I
> > need
> > > > > > is to make
> > > > > > > an average of all this data and then subtract this
average
> > from
> > > > > > each day log
> > > > > > > of the actual stock to detrend. Am I correct? Would you
be
> > kind
> > > > > > enough to
> > > > > > > give me some tips about how to use this new information
to
> > > > actually
> > > > > > backtest
> > > > > > > one of my rules and see how it performs when it is
> > detrended?
> > > > > > >
> > > > > > > Thanks a lot!
> > > > > > >
> > > > > > > Louis
> > > > > > >
> > > > > > > 2008/3/2, Louis Préfontaine <rockprog80@>:
> > > > > > > >
> > > > > > > > Hi Mike,
> > > > > > > >
> > > > > > > > Thank you so much for your reply!
> > > > > > > >
> > > > > > > > This is EXACTLY what I am looking for, from the
Aronson's
> > > > book!
> > > > > > > >
> > > > > > > > I can't wait to make it work... Right now there is a
small
> > > > > > problem with
> > > > > > > > the formula... I get an error message for this parti
> > total +=
> > > > raw
> > > > > > [i]; Ln12:
> > > > > > > > col:8:Error 30. Syntax error.
> > > > > > > >
> > > > > > > > I tried to change the += for = or == and it works...
Is it
> > > > > > possible that
> > > > > > > > the AB version that I have doesn't recognize the +=?
Or
> > maybe
> > > > > > there is an
> > > > > > > > error with the +=? Is it possible to get to the same
> > result in
> > > > > > any other
> > > > > > > > way?
> > > > > > > >
> > > > > > > > Thanks a lot!
> > > > > > > >
> > > > > > > > Louis
> > > > > > > >
> > > > > > > > 2008/3/2, Mike <sfclimbers@>:
> > > > > >
> > > > > > > > >
> > > > > > > > > Hi,
> > > > > > > > >
> > > > > > > > > Based on your formula, I assume that you are
referring
> > to
> > > > > > Chapter 1
> > > > > > > > > of David Aronson's book: Evidence Based Technical
> > Analysis.
> > > > > > > > >
> > > > > > > > > That being the case, I am providing a script below.
> > > > > > > > >
> > > > > > > > > However, I believe that the formula that you
originally
> > > > posted
> > > > > > is not
> > > > > > > > > correct. Aronson's formula calls for multiplying
your
> > > > boolean
> > > > > > > > > strategy signal (i.e. +1 for long vs. -1 for short)
by
> > the
> > > > > > detrended
> > > > > > > > > daily returns, *not* the Close by the returns!
> > > > > > > > >
> > > > > > > > > Also, the book does not go into detail for tri-state
> > > > strategies
> > > > > > (i.e.
> > > > > > > > > long/neutral/short) nor for long/neutral or
> > short/neutral
> > > > > > strategies.
> > > > > > > > > I'm assuming that plugging in a signal value of 0
would
> > be
> > > > > > acceptable
> > > > > > > > > for a neutral position, but haven't researched that
> > yet. So,
> > > > > > just be
> > > > > > > > > careful how you use the data once you've detrended
it.
> > > > > > > > >
> > > > > > > > > Anyway, here is a script that I believe will
detrend the
> > > > market
> > > > > > > > > returns as per the book. Currently, the script is
> > intended
> > > > for
> > > > > > > > > detrending a single symbol. I have not yet got
around to
> > > > making
> > > > > > it
> > > > > > > > > work against a watchlist of symbols (coming soon).
> > > > > > > > >
> > > > > > > > > 1. Copy paste the script below to a file on your
machine
> > > > (say
> > > > > > > > > c:\Program
Files\AmiBroker\Formulas\Custom\Detrend.afl).
> > > > Make
> > > > > > sure
> > > > > > > > > that you correct any formatting that gets messed up
from
> > > > this
> > > > > > post,
> > > > > > > > > such that AmiBroker likes everything. Use the Tools
|
> > Verify
> > > > > > Syntax
> > > > > > > > > menu from the code editor.
> > > > > > > > >
> > > > > > > > > 2. Open a chart on the symbol that you want to
detrend.
> > For
> > > > > > example;
> > > > > > > > > Aronson used the SP-500 for all his tests.
> > > > > > > > >
> > > > > > > > > 3. Open the Automatic Analysis Window
> > > > > > > > >
> > > > > > > > > 4. Click the "Pick" button and select the script
that
> > you
> > > > just
> > > > > > saved
> > > > > > > > > (i.e. Detrend.afl).
> > > > > > > > >
> > > > > > > > > 5. Select "current symbol" for the Apply To.
> > > > > > > > >
> > > > > > > > > 6. Select "from" for the Range, and enter a from
date
> > and a
> > > > to
> > > > > > date
> > > > > > > > > (e.g. from 1/1/2007 to 12/31/2007).
> > > > > > > > >
> > > > > > > > > 7. Click on Backtest
> > > > > > > > >
> > > > > > > > > A new symbol will be added to your system having the
> > same
> > > > name
> > > > > > as the
> > > > > > > > > original, but prefixed with a "~", for example "~SP-
> > 500".
> > > > This
> > > > > > symbol
> > > > > > > > > will appear in Market 253 and contain detrended
market
> > > > > > information
> > > > > > > > > for the range selected (e.g. all of 2007 as above)
and
> > zeros
> > > > > > for all
> > > > > > > > > other dates.
> > > > > > > > >
> > > > > > > > > For each bar in the detrended symbol, the
information
> > will
> > > > be
> > > > > > > > > arranged as follows:
> > > > > > > > >
> > > > > > > > > Open: The unadjusted log daily return (i.e. log
> > > > (Open2/Open1)).
> > > > > > > > >
> > > > > > > > > High: The total sum of all unadjusted log daily
returns.
> > > > > > > > >
> > > > > > > > > Low: The average of all unadjusted log daily returns
> > (i.e.
> > > > ALR).
> > > > > > > > >
> > > > > > > > > Close: The detrended log daily return (i.e. log
> > > > (Open2/Open1) -
> > > > > > ALR).
> > > > > > > > >
> > > > > > > > > OI: The number of bars over which the data has been
> > > > detrended.
> > > > > > > > >
> > > > > > > > > Note: As per Aronson, Open2 refers to the Open two
days
> > from
> > > > > > now,
> > > > > > > > > Open1 refers to the Open one day from now, ALR
refers
> > to the
> > > > > > average
> > > > > > > > > log return over the period being detrended.
> > > > > > > > >
> > > > > > > > > Note: I have used the natural logarithm in my code
(i.e.
> > > > ln), as
> > > > > > > > > opposed to the base 10 logarithm (i.e. log10). I
don't
> > know
> > > > if
> > > > > > that
> > > > > > > > > makes a difference.
> > > > > > > > >
> > > > > > > > > Note: To find your detrended strategy results, you
still
> > > > must
> > > > > > write
> > > > > > > > > your own code to calculate which of the detrended
daily
> > > > returns
> > > > > > your
> > > > > > > > > strategy would pick up, and which sign to use (+/-)
when
> > > > > > multiplying
> > > > > > > > > by the detrended return for that day.
> > > > > > > > >
> > > > > > > > > Note: I ran this script against SP-500 for the
entire
> > year
> > > > of
> > > > > > 2007.
> > > > > > > > > With my data source, the average detrended log daily
> > return
> > > > > > (i.e. all
> > > > > > > > > the Close values of ~SP-500 divided by 251 actual
> > trading
> > > > days)
> > > > > > ended
> > > > > > > > > up being -6.00797E-10 which is effectively zero.
So, I'm
> > > > > > assuming
> > > > > > > > > that it works.
> > > > > > > > >
> > > > > > > > > Corrections and enhancements welcomed :)
> > > > > > > > >
> > > > > > > > > Mike
> > > > > > > > >
> > > > > > > > > procedure Detrend(compositeName) {
> > > > > > > > > local range; range = Status("barinrange");
> > > > > > > > > local raw; raw = log(Ref(Open, 2)/Ref(Open, 1));
> > > > > > > > > local total; total = 0;
> > > > > > > > > local count; count = 0;
> > > > > > > > > local offset; offset = 0;
> > > > > > > > >
> > > > > > > > > for (i = 0; i < BarCount; i++) {
> > > > > > > > > if (range[i]) {
> > > > > > > > > if (NOT IsNull(raw[i])) {
> > > > > > > > > count++;
> > > > > > > > > total += raw[i];
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > if (count > 0) {
> > > > > > > > > AddToComposite(IIF(range, raw, Null), "~" +
> > > > compositeName, "O",
> > > > > > > > > atcFlagDefaults | atcFlagEnableInBackTest);
> > > > > > > > >
> > > > > > > > > offset = total/count;
> > > > > > > > > raw = IIF(IsNull(raw), offset, raw);
> > > > > > > > >
> > > > > > > > > AddToComposite(IIF(range, raw - offset, Null), "~" +
> > > > > > > > > compositeName, "C", atcFlagDefaults |
> > > > atcFlagEnableInBackTest);
> > > > > > > > > AddToComposite(IIF(range, total, Null), "~" +
> > > > > > compositeName, "H",
> > > > > > > > > atcFlagDefaults | atcFlagEnableInBackTest);
> > > > > > > > > AddToComposite(IIF(range, offset, Null), "~" +
> > > > > > > > > compositeName, "L", atcFlagDefaults |
> > > > atcFlagEnableInBackTest);
> > > > > > > > > AddToComposite(IIF(range, count, Null), "~" +
> > > > > > compositeName, "I",
> > > > > > > > > atcFlagDefaults | atcFlagEnableInBackTest);
> > > > > > > > > } else {
> > > > > > > > > AddToComposite(Null, "~" + compositeName, "X",
> > > > atcFlagDefaults |
> > > > > > > > > atcFlagEnableInBackTest);
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > Buy = Sell = Short = Cover = 0;
> > > > > > > > > Detrend(Name());
> > > > > > > > >
> > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx<amibroker%
40yahoogroups.com><amibroker%
> > 40yahoogroups.com><amibroker%
> > > > 40yahoogroups.com><amibroker%40yahoogroups.com>,
> > > > > > > > > "louisprefontaine" <rockprog80@>
> > > > > > > > > wrote:
> > > > > > > > > >
> > > > > > > > > > Anybody can help?
> > > > > > > > > >
> > > > > > > > > > Thanks,
> > > > > > > > > >
> > > > > > > > > > Louis
> > > > > > > > > >
> > > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx<amibroker%
40yahoogroups.com><amibroker%
> > 40yahoogroups.com><amibroker%
> > > > 40yahoogroups.com><amibroker%
> > > > > > 40yahoogroups.com>, "Louis
> > > > > > > > > Préfontaine" <rockprog80@>
> > > > > > > > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > I am trying to build a formula to "detrend" the
> > market.
> > > > > > > > > > >
> > > > > > > > > > > What I want to set is something like this
> > > > > > > > > > >
> > > > > > > > > > > Close of day 0 * ( log (open day2/open day 1) -
> > average
> > > > log
> > > > > > > > > > return of
> > > > > > > > > > > every day of the data available.
> > > > > > > > > > >
> > > > > > > > > > > Anybody can do that?
> > > > > > > > > > >
> > > > > > > > > > > Thanks,
> > > > > > > > > > >
> > > > > > > > > > > Louis
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > >
> >
> >
> >
>
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|