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

[amibroker] Re: Perfect Profit and DOF



PureBytes Links

Trading Reference Links

I have re-defined the peak or tsp as the highest value of H over 
bars/2 before and after the exit signal, where bars is the Average 
bars held per trade.
Similarly, tbp as the lowest value of L over bars/2 before and after 
the entry signal.
I have avoided using zigzag because I'm afraid that troughs and peaks 
defined by zigzag might not be anywhere near the trades entry and 
exit points, making it not a very useful comparsion.

...
bo = GetBacktesterObject(); 
bo.Backtest(); 
Profits = 0; tprofits = 0;
st = bo.GetPerformanceStats(0); 
barsheld = st.GetValue("AllavgBarsHeld");
Halfbars = int(barsheld/2);
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )   
{
	ticker = trade.Symbol;
	SetForeign(ticker);
	Lp = L;
	Hp = H;
	RestorePriceArrays();
	LLVarray = Ref(LLV(Lp, barsheld), halfbars);
	HHVarray = Ref(HHV(Hp, barsheld), halfbars);
	tbp = LastValue(ValueWhen(DateTime() == trade.EntryDateTime, 
LLVarray)); 
	tsp = LastValue(ValueWhen(DateTime() == trade.ExitDateTime, 
HHVarray)); 
	tprofits = tprofits + (tsp - tbp)* trade.Shares;  
	Profits = Profits + trade.GetProfit();
......
}
efficiency = Profits/tprofits;
I have tried it on one of my systems, I'm get 22%

--- In amibroker@xxxxxxxxxxxxxxx, "Paul Ho" <paultsho@xxx> wrote:
>
> Just realise that there is a flaw in this method that I outlined in 
> that it is based on the assumption that MAE occurs before MFE which 
> is not always the case
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Paul Ho" <paultsho@> wrote:
> >
> > Thomas
> > I think the model efficency can be calculated in the CBT without 
> > directly getting PP, This can be done by obtaining the 
Theoretical 
> > buy point (tbp) around the actual buy point, and obtaining tsp 
> around 
> > the sell point.
> > The tbp can happen either before or just after the buy point. 
> > first look at the before scenario, you can either use trough or 
LLV 
> > function. the problem with the trough function is that the low 
> > obtained from Trough() could be quite far away. Lets say we use 
LLV
> > (L, pds) where pds is half the average bars held obtained 
directly 
> > from CBT metrics
> > so tbp_before = LLV(L, bars/2)
> > To find tbp_after we can use the mae metrics from backtest 
directly
> > tbp_after = (1 + mae)*buyprice;
> > tbp = min(tbp_before, tbp_after);
> > The cbt code for tbp could be as follows:
> > ....
> > bo = GetBacktesterObject(); 
> > bo.Backtest(); 
> > st.bo.GetPerformanceStats(0);
> > bars = st.GetValue("AllavgBarsHeld");
> > me = 0; //stores the sum of model eff per trade
> > for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade
> () )   
> > {
> >    sym = trade.Symbol;
> >    mae = trade.GetMAE();
> >    lp = foregin(sym, "L");
> >    tbp_before = lastvalue(valuewhen(datetime()== 
> trade.EntryDateTime, 
> > LLV(lp,bars/2)));
> >    tbp_after = (1+mae)*trade.EntryPrice;
> >    tbp = min(tbp_before, tbp_after);
> >    ........
> >    tsp = max(tsp_before, tsp_after);
> >    theoreticProfitratio = tsp/tbp;
> >    realprofitratio = trade.ExitPrice/trade.EntryPrice;
> >    me += realprofitratio/theoreticProfitratio;
> > }
> >  .... // do the same with open position
> >    mean_me = me/st.GetValue("AllQty");
> > There are a number of variations depending on your perference
> > 1. You can use trough and peak instead of LLV and HHV
> > 2. instead of average ME, you can go for accumulated ME by 
dividing 
> > real profit / theoretical profit. Not sure the figure would be 
too 
> > small to make a lot of sense.
> > 3. you can use geometric average instead of arithmetic average
> > 
> > Now a few questions to both Thomas and Dennis
> > What kind of insights can one obtain with this comparsion? and 
How 
> do 
> > you intend to use it? And would you mind post some of your 
findings?
> > 
> > Cheers
> > Paul.
> > --- In amibroker@xxxxxxxxxxxxxxx, Dennis Brown <see3d@> wrote:
> > >
> > > Thomas,
> > > 
> > > That is what I do.  Though I also add all the trading overhead 
as 
> > if  
> > > it were real trades, then adjust the % change to the maximum 
> total  
> > > profit which gives you a lot more insights.
> > > 
> > > BR,
> > > Dennis
> > > 
> > > On May 16, 2008, at 1:35 PM, Thomas Ludwig wrote:
> > > 
> > > > Hi all,
> > > >
> > > > Rober Pardo suggests in his book "The Evaluation and 
> Optimization 
> > of
> > > > Trading Strategies" the calculation of "Perfect Profit" (PP) 
> > which "is
> > > > the sum total of all of the potential profit that could be 
> > realized by
> > > > buying every bottom and selling every top". By comparing Net 
> > Profit of
> > > > your trading system with PP you can calculate the "Model 
> > Efficiency"
> > > > (ME).
> > > >
> > > > I think PP can be easily calculated as a stand-alone code by  
> > > > applying a,
> > > > say, 1% Zigzag. But how can it be done if I want to add ME as 
an
> > > > additional metric in the Custom Backtester? The Equity() 
> function 
> > is
> > > > used for your trading system and cannot be used for the 
Zigzag 
> > system
> > > > at the same time in order to compare both, IMHO. So the only  
> > > > solution I
> > > > can think of is to loop through all Zigzag signals and 
> calculate 
> > the
> > > > profit programmatically. Or am I overlooking something?
> > > >
> > > > Pardo also suggests to calculate the Remaining Percentage of 
> > Degrees  
> > > > of
> > > > Freedom (through Used Dgrees of Freedom and Original Degrees 
of
> > > > Freedom). Any idea if and how they can be counted in AFL?
> > > >
> > > > Regards,
> > > >
> > > > Thomas
> > > >
> > > > ------------------------------------
> > > >
> > > > 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
> > > >
> > > >
> > > >
> > >
> >
>



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

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/