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

RE: [amibroker] Help - Portfolio Backtester Issues



PureBytes Links

Trading Reference Links

Hi Ed

 

Compare the output of the trade list to the output from this version.  I have continued the thread under,

Work in Progress - Tradesim - Universal text Trade Database Version 1.1

 

Cheers

 

Regards

 

Dave

 

/* Tradesim - Universal text Trade Database Version 1.2 - Work in Progress

 

Adapted from sample code in PBI Collected Documentation, 'How to create a Trade List By ShortFox'

 

Requirements:  To generate YYYYMMDD output, declare it in your regional settings

 

Revision 1.1 Remove separators / from Date format

Revision 1.2 Add Portfolio Backtester Parameters to generate complete trade list

 

Current Issues

- does NOT produce full trade list - all individual trades - workaround Revision 1.2

- Initial stop value not yet used. Currently set to 0

 */

 

Buy = 0; Sell = 0; Short = 1; Cover = 0;

 

SetCustomBacktestProc("");

 

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

{

    fh = fopen( "C:\\TestFile.trt", "w" );

 

    bo = GetBacktesterObject();

    bo.BackTest(); // High-Level backtest

 //   dt = DateTime();

 

    Initial_Stop = "0";

    // if Initial Stop data is not available then 0 placeholder should be used.

 

    for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )

    { // iterate through closed trades

        if ( trade.IsLong )

        {

            Long_Short = "L";

        }

        else

        {

            Long_Short = "S";

        }

 

// Revision 1.1 Fixup date format for Tradesim - remove date separators

EntryDate =  NumToStr(trade.EntryDateTime,formatDateTime);

entryyyyy=StrLeft(EntryDate,4);

entrymm=StrMid(EntryDate,5,2);

entrydd=StrRight(EntryDate,2);

TSEntryDate = entryyyyy+entrymm+entrydd;

 

ExitDate =  NumToStr(trade.ExitDateTime,formatDateTime);

Exityyyy=StrLeft(ExitDate,4);

Exitmm=StrMid(ExitDate,5,2);

Exitdd=StrRight(ExitDate,2);

TSExitDate = exityyyy+exitmm+exitdd;

 

        String =  trade.Symbol + " " + Long_Short + " " + TSEntryDate + " " + TSExitDate

        + " " + Initial_Stop + " " + trade.EntryPrice + " " + trade.ExitPrice;

       if ( fh )

          fputs( string + "\n", fh );

    }

 

    fclose( fh );

}

 

// Tradesim Complete Tradelist Parameters - Do not remove - Revision 1.2

SetOption("InitialEquity", 10000000000000000 );

SetPositionSize( 1, spsShares );

SetOption("MaxOpenPositions", 1000 );

 

// Your trading system here...

 

Buy = C > EMA(C,20);

Sell = C < EMA(C,20);

 

 


From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of emp62
Sent: Saturday, 17 September 2005 7:12 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Help - Portfolio Backtester Issues

 

hi,

 

concerning question 1.1,    I do not see that happening, or maybe I misunderstood your question. I used your code and added a simple system (see below). It will write all trades to the file, not just the last ones. According to the "manual" you will get all trades.

 

rgds, Ed

 

 

SetCustomBacktestProc("");

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

   fh =
fopen( "C:\\TestFile.trt", "w" );

    bo =
GetBacktesterObject();
    bo.BackTest();
// High-Level backtest
    dt =
DateTime();

    Initial_Stop =
"0";

    
// if Initial Stop data is not available then 0 placeholder should be used.

   
for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) { // iterate through closed trades

      
if ( trade.IsLong ) {
      
         Long_Short =
"L";

        }
else {

            Long_Short =
"S";

        }

        String =  trade.Symbol +
" " + Long_Short + " " + NumToStr(trade.EntryDateTime,formatDateTime) + " " + NumToStr( trade.ExitDateTime, formatDateTime )
        +
" " + Initial_Stop + " " + trade.EntryPrice + " " + trade.ExitPrice;

      
if ( fh ) {
      
         
fputs( string + "\n", fh );
        
        }
          
     }

   
fclose( fh );

}



// Your trading system here...
SetOption("MaxOpenPositions", 50 );
PositionSize = -
15;
SetTradeDelays(1,1,1,1);
PositionScore =
50 - Ref(StochK(15),-1);

Buy = C >
EMA(C,20); Buy = Ref(Buy,-1); BuyPrice = O;
Short = C <
EMA(C,20); Short = Ref(Short,-1); ShortPrice = O;
Sell =
0;
Cover =
0;

ApplyStop( stopTypeNBar,stopModeBars,4,ExitAtStop = 1,Volatile = False, ReentryDelay = 1 );

SellPrice = C;
CoverPrice = C;

// stop signals are implemented and redundant signals are removed
Equity(1);

SetChartOptions(0, chartShowDates);
GraphXSpace =
5;
Plot(C,"C",1,64);

PlotShapes(IIf(Buy,shapeUpArrow,0),colorWhite, layer = 0, yposition = BuyPrice, offset = 0 );
PlotShapes(IIf(Sell,shapeDownArrow,0),colorYellow, layer = 0, yposition = SellPrice, offset = 0 );
PlotShapes(IIf(Short,shapeHollowDownArrow,0),colorLightBlue, layer = 0, yposition = ShortPrice, offset = 0 );
PlotShapes(IIf(Cover,shapeHollowUpArrow,0),colorGold, layer = 0, yposition = CoverPrice, offset = 0 );

 

 

 

 

 

 

 

 

 

 

 

 

 

 

----- Original Message -----

From: dpweir

Sent: Friday, September 16, 2005 1:14 PM

Subject: [amibroker] Help - Portfolio Backtester Issues

 

Hello

 

I have been working on code to produce output from the backtester which meets a third party tool format, Tradesim’s Universal text Trade Database. Unable to produce this format so far, is the only reason why I have not ditched Metastock all together (I understand there is an exe available to do this but it does not look at an initialstop variable and requires a few too many button clicks for lazy me), so I am anxious to get this working.

 

Also I think this may be a another good example of using the PBI (hint hint Thomas)

 

I have posted the code below. The issues I have, are listed below and any input on how to resolve or work around these would be very much appreciated. Thomas any input appreciated =)

 

  1. Trade List

 

1.1    If I run the individual backtest, I only get the last symbols results.  Can the script be altered so all symbols are listed with their results ?

 

1.2    Portfolio backtest.  If we are unable to get the individual backtester working, what configuration would be required to get all possible trades using the portfolio backtester ?

 

  1. Date

 

I have changed my regional settings so the date is now in the format of yyyy/mm/dd, however there appears to be no option in my regional settings to have the date in the format of yyyymmdd , which is the format requirement.

 

  1. Initial stop value. 

 

I was going to leave this for a separate post,  but I feel like we are on a roll.  Is there also anyway to get the value of atr(period) at the first bar (or bar before) the entry signal ? This value is used for position sizing within Tradesim.

 

Many, many thanks.

 

Now the code,

 

/* Tradesim - Universal text Trade Database Version 1.0

Original sample code from PBI Collected Documentation, 'How to create a Trade List By ShortFox'

 

Requirements:  To generate YYYYMMDD output, declare it in your regional settings */

 

Buy = 0; Sell = 0; Short = 1; Cover = 0;

 

SetCustomBacktestProc("");

 

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

{

    fh = fopen( "C:\\TestFile.trt", "w" );

 

    bo = GetBacktesterObject();

    bo.BackTest(); // High-Level backtest

    dt = DateTime();

 

    Initial_Stop = "0";

    // if Initial Stop data is not available then 0 placeholder should be used.

 

    for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )

    { // iterate through closed trades

        if ( trade.IsLong )

        {

            Long_Short = "L";

        }

        else

        {

            Long_Short = "S";

        }

        String =  trade.Symbol + " " + Long_Short + " " + NumToStr(trade.EntryDateTime,formatDateTime) + " " + NumToStr( trade.ExitDateTime, formatDateTime )

        + " " + Initial_Stop + " " + trade.EntryPrice + " " + trade.ExitPrice;

       if ( fh )

          fputs( string + "\n", fh );

    }

 

    fclose( fh );

}

 

// Your trading system here...

Buy = C > EMA(C,20);

Sell = C < EMA(C,20);

 

 

 






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 other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Real estate investment software Investment property software
Software support Real estate investment analysis software Investment software


YAHOO! GROUPS LINKS