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

[amibroker] Re: More on Database Structure and Local Storage



PureBytes Links

Trading Reference Links

Very interesting code by Paul.  Thanks for sharing it.

Thinking about how it works, here's how I explain it to myself:

Internally, AB will sort/order the backtester's 'Signal' objects
according to absolute value of PositionScore.  Later in the code, we
will retrieve from these objects by stepping thru them sequentially. 
Since the 'Signal' objects have already been sorted by AB into
PositionScore order, the order in which they will be encountered when
we step-thru them _is_ the ordinal order of the ranking metric.

Anybody care to confirm or correct this?


--- In amibroker@xxxxxxxxxxxxxxx, Ken Close <ken45140@xxx> wrote: 
> For those interested in the code written for this test by Paul Ho,
here it is.  

run = Optimize("run", 1, 1, 2, 1);

function ranking(Ordinal)

{

    switch(Ordinal)

    {

    case 1:

        res = ROC(C, 14) + 1000;

        break;

    case 2:

        res = RSI(14);

        break;

    default:

        res = EMA(C, 50);

        break;

    }

    return res;

}

PositionScore = ranking(run); // WHAT YOU WANT TO RANK

 

SetOption("MaxOpenPositions", 50 ); //AB only keeps 2* maxpos top rank
signals

SetBacktestMode( backtestRegularRaw );

Buy=1;

Sell= Short = Cover = 0;

ab = CreateObject("broker.Application");

target = ab.Stocks(Name());

target.isDirty = True;

SetCustomBacktestProc("");

if( Status("action")==actionPortfolio )

{

    bo = GetBacktesterObject();

    bo.PreProcess();

    dt = DateTime();

//  fh = fopen("output.csv", "w"); uncomment these if you want to save
it to a csv file as well

//  fputs("Symbol,Date,Rank\n", fh);

    for( i = 0; i < BarCount; i++ )

    {

        k = 1;  

        for( sig = bo.GetFirstSignal( i ); sig; sig =
bo.GetNextSignal( i ) )

        {

//         Line = sig.Symbol + "," + DateTimeToStr(dt[i]) + "," + k +
"\n";

//         fputs(Line, fh);

           target = ab.Stocks(sig.Symbol);

           qt = target.Quotations(DateTimeToStr(dt[i]));

           if(qt)

           {

               if(run == 1)

                   qt.OpenInt = k;

               else

                   qt.OpenInt += k;

           }

           target.isDirty = True;

       k++;

        }

    }

    bo.PostProcess();

//  if(fh)fclose(fh);

}




------------------------------------

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/