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

Re: [amibroker] Walk forward doubt



PureBytes Links

Trading Reference Links

> Hello
> It's very interesting the walk forward optimization. I use it with a
> 2 months In-sample period, and 1 month Out of sampple period, this
> is, 12 steps every year to see if my systems are good.
> But i have a doubt: After processing several years of the
> optimization, I have a chart with the out of sample equity, but ..
> How could I obtain the exact trades of all the out of sample equity?

I don't think that's possible. TJ might add that in future versions of 
AB.

> and if it's not possible, is there any way to calculate the Draw
> Down, Sharpe etc, of the out-of-sample results?
>
> Any answer would be very much appreciated
>

Try the attached AFL file that calculates some metrics and more.

Greetings,

Thomas


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

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

*********************
TO GET TECHNICAL 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/

SetChartBkColor( colorWhite ); 
SetChartOptions( 0, chartShowDates|chartWrapTitle ); 


iseq=Foreign("~~~ISEQUITY", "C");
oseq=Foreign("~~~OSEQUITY", "C");

x = SelectedValue(BarIndex());


function FirstBarIndex(Condition)
{
     TotalBarsIndex = x;
     a = 0;
     Counter = 0;
     for (a = 0 ;a < TotalBarsIndex; a++)
     {
       Counter = Counter+1;
       if (
           IsTrue(Condition[a])
          )
       a = TotalBarsIndex;
       }
     result = Counter-1;

     return result;
}


isfirst=FirstBarIndex(iseq);
osfirst=FirstBarIndex(oseq);

isTotalBars=x-isfirst;
osTotalBars=x-Osfirst;

isSlope = LinRegSlope(iseq,istotalbars);
osSlope = LinRegSlope(oseq,ostotalbars);

/*lastbar = BarIndex();
al = LastValue( ValueWhen( lastbar, LinRegSlope( iseq, isTotalBars  ) ) );
bl = LastValue( ValueWhen( lastbar, LinRegIntercept( iseq, isTotalBars ) ) );
isLr = al * ( BarIndex() - isfirst ) + bl;


a2 = LastValue( ValueWhen( lastbar, LinRegSlope( oseq, osTotalBars ) ) );
b2 = LastValue( ValueWhen( lastbar, LinRegIntercept( oseq, osTotalBars ) ) );
osLr = a2 * ( BarIndex() - osfirst ) + b2;*/



//R-squared
isR2=(Correlation(Cum( 1 ),iseq,istotalbars))^2;
osR2=(Correlation(Cum( 1 ),oseq,ostotalbars))^2;


//K-Ratio
iskratio=100000*isSlope/(StdErr(iseq,istotalbars)*istotalbars);
oskratio=100000*osSlope/(StdErr(oseq,ostotalbars)*ostotalbars);

//CAR
isCAR=100*((iseq/iseq[isfirst])^(252/isTotalBars) -1);
osCAR=100*((oseq/oseq[osfirst])^(252/osTotalBars) -1);
benchCARis=100*((C/C[isfirst])^(252/isTotalBars) -1);
benchCARos=100*((C/C[osfirst])^(252/osTotalBars) -1);

//RelativeCAR (%)
//isRelCAR=100*((isCAR/benchCARis)-1);
//osRelCAR=100*((osCAR/benchCARos)-1);
isRelCAR=isCAR/benchCARis;
osRelCAR=osCAR/benchCARos;




//Drawdown
isdr=iseq-Highest(iseq);
osdr=oseq-Highest(oseq);

ismaxdr=Lowest(isdr);
osmaxdr=Lowest(Osdr);

isdrperc=100*(iseq/Highest(iseq)-1);
osdrperc=100*(oseq/Highest(oseq)-1);

ismaxdrperc=Lowest(isdrperc);
osmaxdrperc=Lowest(Osdrperc);


//CAR/MaxDD
iscarmdd=-isCAR/ismaxdrperc;
oscarmdd=-osCAR/osmaxdrperc;

//UPI
CumISdr=Cum(isdrperc^2);
CumOSdr=Cum(osdrperc^2);
isUI=sqrt(CumISdr/(x-isfirst));
osUI=sqrt(CumOSdr/(x-osfirst));
isUPI=(isCAR-5.4)/isUI;
osUPI=(OsCAR-5.4)/osUI;

//Walk-Forward Efficiency
WFE=OsRelCAR/isRelCAR;

InitialEquity = GetOption("InitialEquity");

//IS Buy&Hold performance
gainIS=C/C[isfirst];
bhis=InitialEquity*gainis;
if( ParamToggle("Show IS Equity and Buy + Hold?", "No|Yes", 1 ) ) 
{
PlotForeign("~~~ISEQUITY","In-Sample Equity", colorRed, styleLine|styleThick);
Plot( bhis, "Buy&Hold IS", colorOrange); 
}

//OOS Buy&Hold performance
gainOS=C/C[osfirst];
bhos=InitialEquity*gainos;
if( ParamToggle("Show OOS Equity and Buy + Hold?", "No|Yes", 1 ) ) 
{
PlotForeign("~~~OSEQUITY","Out-Of-Sample Equity", colorGreen, styleLine|styleThick); 
Plot( bhos, "Buy&Hold OOS", colorTurquoise ); 
}

/*//Linear Regression Lines
if( ParamToggle("Show lin. reg.", "No|Yes", 0 ) )
Plot( isLr , "Linear Reg",colorRed, styleThick ) 
AND Plot( osLr , "Linear Reg", colorGreen, styleThick );*/

//Relative Performance
isrelperf=iseq/bhIS;
osrelperf=oseq/bhOS;
if( ParamToggle("Show IS Rel. Performance?", "No|Yes", 0 ) )
Plot( isrelperf , "IS Rel. Performance",ColorRGB( 220, 128, 128 ) , styleThick|styleOwnScale|styleNoTitle );
if( ParamToggle("Show OOS Rel. Performance?", "No|Yes", 0 ) )
Plot( osrelperf , "OOS Rel. Performance",ColorRGB( 128, 220, 128 ), styleThick|styleOwnScale|styleNoTitle );

//DD
if( ParamToggle("Show IS Drawdown", "No|Yes", 0 ) ) Plot(isdr, "IS Drawdown", colorDarkRed, styleArea );
if( ParamToggle("Show IS Max. Drawdown?", "No|Yes", 0 ) ) Plot(ismaxdr,"IS Max. Drawdown",colorBlue);


if( ParamToggle("Show OOS Drawdown", "No|Yes", 0 ) ) Plot(osdr, "OOS Drawdown", colorDarkGreen, styleArea );
if( ParamToggle("Show OOS Max. Drawdown?", "No|Yes", 0 ) ) Plot(osmaxdr,"OOS Max. Drawdown",colorBlue);




Title = "{{NAME}} - {{INTERVAL}} {{DATE}} {{VALUES}}"
+"\n \\c04IS       R2: " + WriteVal(isR2)+"   K-Ratio: "+WriteVal(iskratio)+"   CAR(%):  "+WriteVal(isCAR,1.1)+"  BenchmarkCAR(%):  "+WriteVal(benchCARis,1.1)
+"   RelativeCAR:   "+WriteVal(isRelCAR,1.1)
+"   Max DD(%):  "+WriteVal(ismaxdrperc,1.1)+"   CAR/MDD: "+WriteVal(iscarmdd,1.2)+"   UPI: "+WriteVal(isUPI,1.2)
+"\n \\c27OOS  R2: " + WriteVal(OsR2)+"   K-Ratio: "+WriteVal(oskratio)+"   CAR(%):  "+WriteVal(osCAR,1.1)+"  BenchmarkCAR(%):  "+WriteVal(benchCARos,1.1)
+"   RelativeCAR:   "+WriteVal(osRelCAR,1.1)
+"   Max DD(%):  "+WriteVal(osmaxdrperc,1.1)+"   CAR/MDD: "+WriteVal(oscarmdd,1.2)+"   UPI: "+WriteVal(osUPI,1.2)
+"\n \\c-1Walk-Forward Efficiency(%):   "+WriteVal(WFE,1.1);