PureBytes Links
Trading Reference Links
|
This is great. I'll try it out.
What I'm after is long/short portfolio equity to use in an indicator. I've never understood why it isn't exposed.
Thanks, Mike!
Joe
--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
>
> Hi,
>
> I have not tested for correctness. But, to do what you are trying to
> do, I believe that you would have to use mid level backtester (i.e.
> PreProcess, ProcessTradeSignals, PostProcess) not the high level
> backtester (i.e. Backtest).
>
> Following your example; Get the stats at each bar and store the values
> in a composite, since indicator mode (i.e. charting) would not see array
> values populated during portfolio mode (i.e. backtest).
>
> Finally, use Foreign to do the plotting.
>
> Mike
>
> SetTradeDelays( 0, 0, 0, 0 );
> SetPositionSize( 5, spsPercentOfEquity );
>
> weekDay = DayOfWeek();
>
> Buy = weekDay == 1;
> BuyPrice = Open;
>
> Sell = weekDay == 2;
> SellPrice = Close;
>
> Short = weekDay == 3;
> ShortPrice = Open;
>
> Cover = weekDay == 4;
> CoverPrice = Close;
>
> SetCustomBacktestProc( "" );
>
> if ( Status( "action" ) == actionPortfolio )
> {
> bo = GetBacktesterObject();
> bo.PreProcess();
>
> totalProfit = longProfit = shortProfit = 0;
>
> for ( i = 0; i < BarCount; i++ )
> {
> bo.ProcessTradeSignals( i );
>
> stats = bo.GetPerformanceStats( 0 );
> stats_long = bo.GetPerformanceStats( 1 );
> stats_short = bo.GetPerformanceStats( 2 );
>
> totalProfit[i] = stats.getValue( "EndingCapital" ) -
> stats.GetValue( "InitialCapital" );
> longProfit[i] = stats_long.getvalue( "EndingCapital" ) -
> stats.GetValue( "InitialCapital" );
> shortProfit[i] = stats_short.getvalue( "EndingCapital" ) -
> stats.GetValue( "InitialCapital" );
> }
>
> bo.PostProcess();
>
> AddToComposite( totalProfit, "~TotalProfit", "X", atcFlagDefaults |
> atcFlagEnableInPortfolio );
> AddToComposite( longProfit, "~LongProfit", "X", atcFlagDefaults |
> atcFlagEnableInPortfolio );
> AddToComposite( shortProfit, "~ShortProfit", "X", atcFlagDefaults |
> atcFlagEnableInPortfolio );
> }
>
> Plot( Close, "Close", colorDarkGrey, styleBar );
>
> Plot( Foreign( "~TotalProfit", "Close" ), "Total Profit", colorBlue,
> styleLeftAxisScale );
> Plot( Foreign( "~LongProfit", "Close" ), "Long Profit", colorGreen,
> styleLeftAxisScale );
> Plot( Foreign( "~ShortProfit", "Close" ), "Short Profit", colorRed,
> styleLeftAxisScale );
>
> --- In amibroker@xxxxxxxxxxxxxxx, "j0etr4der" <j0etr4der@> wrote:
> >
> > Hello,
> >
> > In the User's Guide Backtester Interface section, Stat object is says,
> >
> > "Metrics are usually calculated once backtest is completed but it is
> also possible to calculate metrics during backtest. To calculate current
> metrics and get the access to them simply call GetPerformanceStats
> method of Backtester object. Please note that if you calculate
> statistics in the middle of the backtest they will include only closed
> trades."
> >
> > I was hoping I could get access to the current long and short capital
> stats. The following code produces the correct results in AA window
> following optimization, but does not plot on the chart (values remain 0
> ).
> >
> > Is this feasible in any way? Or do I have to figure out (not likely at
> my skill level) how to control trades in the backtester procedure?
> >
> > TIA,
> >
> > Joe
> >
> > //////////////////////////////////////////////////////////
> > Sp = Lp = 0;
> >
> > SetCustomBacktestProc( "" );
> > if ( Status( "action" ) == actionPortfolio )
> > {
> > bo = GetBacktesterObject();
> > bo.Backtest();
> >
> > stats = bo.GetPerformanceStats( 0 );
> > stats_long = bo.GetPerformanceStats( 1 );
> > stats_short = bo.GetPerformanceStats( 2 );
> >
> > Longprofit = stats_long.getvalue( "EndingCapital" )
> > - stats.GetValue( "InitialCapital" );
> >
> > bo.AddCustomMetric( "Long profit", Longprofit );
> >
> > Shortprofit = stats_short.getvalue( "EndingCapital" )
> > - stats.GetValue( "InitialCapital" );
> >
> > bo.AddCustomMetric( "Short profit", Shortprofit );
> >
> > for ( i = 0; i < BarCount - 1; i++ )
> > {
> > Lp[ i ] = Longprofit;
> > Sp[ i ] = Shortprofit;
> > }
> > }
> >
> > Plot( Lp, "Long profit", colorBlack );
> > Plot( Sp, "Short profit", colorBlack );
> >
>
------------------------------------
**** 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:
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/
|