Tomasz:
Thank you for taking the time to share this.
Unfortunately, I have a lot of studying to do with the custom backtester to even
begin to see if this can help me. I was successful in running the code and
looking at the output, but the output seems like it needs a bunch more
processing, either within the backtester (which I do not know how to do yet) or
outside the backtester (in Excel) which is what I am trying to avoid (for labor
savings). Here is what I specifically am trying to get
to.......
What I
need to achieve is equivalent to using the Excel Function RANK, which allows the
specification of a Range (a column for say, stochastics for 100 funds), then
getting in another column the Ordinal Position of that ticker relative to all
others for the result of stochastics. Then, another column might have an
indicator, say RSI14, and another column using RANK that shows the Ordinal
Position of each RSI value for all tickers. I then take a final column and
say, sum the two ordinal values for each ticker to get a Master Ranking
column. My situation is more complex than this (more columns and a more
complex combining method) but this is the basic idea.
This
can all be done in Excel, but a tremendous labor saving step is to accomplish it
all in AB. Imagine trying to do this on 1000s of stocks on a daily or even
hourly basis.
Can
you whip up an AFL function called RANK which operates exactly like the Excel
RANK function? <smile>
The
backtester "seems" like it might be able to do this, although because of
inexperience, I am not sure. You once said "AFL/AB can do anything".
If you tell me it can do this, I will dive in and try and learn enough
about the various commands and usage in order to make it happen. Can it do
it?
Ken
Ken,
Sorting and ranking is part of portfolio backtest. You can use
this process not only to do actual backtest
but also to output ranking/sorting results.
All you need is to assign your score to
PositionScore variable.
Then, run backtest. All your signals will be ranked and sorted
according to absolute value of position score.
The code below shows how. It also generates "myoutput.txt"
Comma Separated Values (CSV) file with Symbol, Score
lines. Lines are in chronological order, within same date/time
the lines are sorted according to absolute value of score.
It also outputs the same into DebugView.
Buy=1; Sell=0; SetBacktestMode( backtestRegularRaw );
PositionScore = 100 -
RSI(); // anything you like (will be sorted/ranked according to absolute
value of pos score)
SetCustomBacktestProc("");
OutputFileName =
"myoutput.txt";
if( Status("action" )
== actionPortfolio ) { bo = GetBacktesterObject();
bo.PreProcess();
dt = DateTime();
fh =
fopen( OutputFileName,
"w" );
fputs(
"Symbol, Score\n", fh );
for( i = 0; i
< BarCount; i++ ) { strdt = DateTimeToStr( dt[ i ] );
Line = "\nDate : " + strdt + "\n"; _TRACE( Line ); fputs( Line, fh );
for( sig
= bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i) ) {
Line = sig.Symbol + "," + sig.PosScore + "\n";
_TRACE( Line ); fputs( Line, fh ); }
bo.ProcessTradeSignals( i ); }
fclose( fh );
bo.PostProcess(); }
Best regards, Tomasz
Janeczko amibroker.com
----- Original Message -----
Sent: Friday, May 09, 2008 7:38 PM
Subject: [amibroker] Greybeard Topic -
Sorting and Ranking Arrays
It has been fun to
search the yahoo archives back to 2002 and see names of a lot of the original
folks who got on the Amibroker bandwagon back in the early days, many of whom
are no longer around (at least not posting like they used to). Boy, how
the program has evolved and improved over these many
years.
I was looking back
there in the archives for messages on the Osaka Plugin (which is still on my
hard drive since 2002 but which I have never used). Maybe
now......
I have a need to
take a watchlist and position rank several columns of calculations and
determine the postion rank of the ticker for that calculation; then do the
same for another column (calculation), get the position rank for that
additional column, and then combine the position ranking numbers for the
columns for each ticker, sort of to get a Master ranking
parameter.
My question is:
what new features in AB might help accomplish this? Surely the Osaka
Plugin (2002 vintage) is not the only way to do what I want. I have not
really studied nor used Static and Dynamic variables---is this the set of
commands that I would use with looping to get position ranks of a
watchlist?
I did find and
just tested some code from the Library which used just these tools (variables
and looping) and it was painfully slow and would not really work for the
application I have in mind. I am uncertain if the code in that example
can be modified to make it faster.
Any suggestions
about this age-old question/problem, given the many advances of Amibroker
since 2002??
Thanks for any
ideas (the more specific the better).
Ken
No virus found in this incoming message. Checked
by AVG. Version: 8.0.100 / Virus Database: 269.23.14/1425 - Release Date:
5/9/2008 12:38 PM
__._,_.___
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
__,_._,___
|