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

[amibroker] Re: Detecting In-Smaple and Out-of-Sample Walk Forward


  • Date: Sat, 30 Jan 2010 05:38:30 -0000
  • From: "grahamj42" <graham.johnson@xxxxxxxxxxxxx>
  • Subject: [amibroker] Re: Detecting In-Smaple and Out-of-Sample Walk Forward

PureBytes Links

Trading Reference Links

Hi Bruce

I'm making use of these techniques to output a list of OOS trades to a file.

By using a StaticVar for control, I've output a header row to the first line of the file.

All is great except that I can't find a means of determining the last OOS pass so that the StaticVar can be reset for subsequent WalkForward runs.

Any suggestions please.

Graham

--- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@xxx> wrote:
>
> Bruce - just wanted to report that your code worked like a charm!
> You're my new hero. :-)
> 
> I was in the process of sketching out an OLE project to simulate a
> multi-variable Walk-Forward tester. Given my mediocre programming
> abilities, that probably would have taken me a couple of months to get
> right. Now, thanks to your code, I can just use the normal
> Walk-Forward engine, and achieve what I wanted.
> 
> In the future, it would be nice if AB had this IS/OOS, and other
> flags, readily built-in. I will suggest as much to the official
> suggestions webpage.
> 
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@> wrote:
> >
> > Bruce, thanks a bunch. That's a nifty solution.
> > 
> > It will take me a few days to play around with it, and I will post any
> > questions here should they come up. But it looks like it will do
> > exactly what I was hoping for!
> > 
> > Thanks again.
> > 
> > 
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "bruce1r" <brucer@> wrote:
> > >
> > > Part II -
> > > 
> > > I mentioned that I had needed to detect IS/OOS in walk-forward testing
> > > for signal work.  It is actually needed for several applications, and
> > > again I hope that Tomasz adds the status property.  Below is a brief,
> > > demo example that might be of use.  Side note - Yahoo really sucks for
> > > doing this !  At least, I've met my yearly posting target for 2009 :-)
> > > 
> > > It is a very simple 2MA crossover optimization that was used to
> > > initially test OptSampleType().  It is NOT meant to be practical.  It
> > > can be run, for example, on the SP500 in "Easy mode" as follows -
> > > 
> > > Start - 12/31/2001
> > > End - 12/31/2002
> > > Last - 9/30/2003
> > > Step - 3 months
> > > NOT anchored
> > > Optimization target - CAR/MDD
> > > 
> > > These parameters don't have to be used, but this example shows some
> > > interesting tidbits.  For example, it show the limitations in
> > > transitioning from a bear to a bull period with limited lookback.  It
> > > also shows some boundary effects in the walk-forward mode.  But these
> > > are stories for another day.
> > > 
> > > Anyway, here's a snippet of the _Trace output -
> > > 
> > > Name = SP-CP , ActionEx = 14 , From = 6/30/2003 , To = 9/30/2003 ,
> > > OptSampleType = 3
> > >   Fast = 45 , Slow = 49
> > >   Signals - 
> > >     BUY  - 6/30/2003
> > >     SELL - 8/15/2003
> > >     BUY  - 8/27/2003
> > >     SELL - 9/10/2003
> > >     BUY  - 9/17/2003
> > > Name = SP-CP , ActionEx = 14 , From = 9/30/2003 , To = 12/31/2003 ,
> > > OptSampleType = 3
> > >   Fast = 97 , Slow = 75
> > >   Signals - 
> > >     SELL - 9/30/2003
> > > 
> > > Finally, the code -
> > > 
> > >
> >
> //--------------------------------------------------------------------------------------------------
> > > //
> > > //  Simple 2MA Optimization.afl - 1/18/09
> > > //
> > > //  Example to show use of OptSampleType() function.  Note that this
> > > is meant as a
> > > //  non-practical example that demonstrates a special case and a
> > > boundary condition
> > > //  related to signals in a walk-forward optimization.
> > > //
> > >
> >
> //--------------------------------------------------------------------------------------------------
> > > 
> > > #include <OptSampleType.afl>
> > > 
> > > //  Get the optimization pass type - this must be outside of any
> > > conditionals
> > > samptype			= OptSampleType( );
> > > 
> > > //  Test routine for OptSampleType
> > > 
> > > //  Choose an engine and set a simple, short optimization
> > > OptimizerSetEngine( "spso" );			//  cmae, trib
> > > OptimizerSetOption( "Runs", 2 );
> > > OptimizerSetOption( "MaxEval", 500 );
> > > 
> > > //  Simple 2 MA crossover system
> > > fast			= Optimize( "Fast MA", 13, 1, 100, 1 );
> > > slow			= Optimize( "Slow MA", 55, 1, 100, 1 );
> > > Buyimp			= Cross( MA( C, fast ), MA( C, slow ) );
> > > Sellimp		= Cross( MA( C, slow ), MA( C, fast ) );
> > > Short 			= Cover = 0;
> > > 
> > > //  Handle a signal in progress at the start of the period - note that
> > > //  this will introduce a few redundant signals (if first signal
> of OOS
> > > //  period is the same as the last signal of the last OOS period). 
> > These
> > > //  will have to be filtered later, but it is the easiest way for this
> > > demo
> > > Buystate		= Flip( Buyimp, Sellimp );
> > > Sellstate		= NOT Buystate;
> > > fbir			= Status( "firstbarinrange" );
> > > Buy			= Buyimp OR fbir * Buystate;
> > > Sell			= Sellimp OR fbir * Sellstate;
> > > 
> >
> //--------------------------------------------------------------------------------------------------
> > > 
> > > //  Debug output
> > > if ( samptype == 3 )
> > > {
> > > 	_TRACE	( "Name = " + StrLeft( Name( ) + "     ", 5 )
> > > 				+ " , ActionEx = " + Status( "actionex" )
> > > 				+ " , From = " + NumToStr( DateTimeConvert( 2, Status(
> > > "rangefromdate" ) ), formatDateTime )
> > > 				+ " , To = " + NumToStr( DateTimeConvert( 2, Status( "rangetodate"
> > > ) ), formatDateTime )
> > > 				+ " , OptSampleType = " + samptype
> > > 	 		);
> > > 	_TRACE( "  Fast = " + fast + " , Slow = " + slow );
> > > }
> > > 
> > > //  Show the signals for the out-of-sample period
> > > if ( samptype == 3 )
> > > {
> > > 	bi			= BarIndex( );
> > > 	bi			= bi - bi[ 0 ];
> > > 	dt			= DateTime( );
> > > 	fbi			= LastValue( ValueWhen( Status( "firstbarinrange"), bi ) );
> > > 	lbi			= LastValue( ValueWhen( Status( "lastbarinrange" ), bi ) );
> > > 	_TRACE( "  Signals - " );
> > > 	for ( i = fbi; i <= Lbi; i++ )
> > > 	{
> > > 		if ( Buy[ i ] )
> > > 			_TRACE( "    BUY  - " + NumToStr( dt[ i ], formatDateTime ) );
> > > 		if ( Sell[ i ] )
> > > 			_TRACE( "    SELL - " + NumToStr( dt[ i ], formatDateTime ) );
> > > 	}
> > > }
> > > 
> > >
> >
> //--------------------------------------------------------------------------------------------------
> > >
> >
>




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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/