[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Aronson Detrending Market {Was Detrending... log}



PureBytes Links

Trading Reference Links

You are using too old version of AmiBroker. Upgrade to 5.0

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
Sent: Sunday, March 02, 2008 3:41 PM
Subject: Re: [amibroker] Re: Aronson Detrending Market {Was Detrending... log}

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 = "" == 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@xxxxxxxxx>:

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, "louisprefontaine" <rockprog80@xxx>
wrote:
>
> Anybody can help?
>
> Thanks,
>
> Louis
>
> --- In amibroker@xxxxxxxxxxxxxxx, "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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___