Title: Re: [amibroker] Re: Inline Backtester Metrics
Thank you Brian for your ideas and efforts.
It looks indeed as if it could be used as a general approach however I am so committed to my own ways of doing things that it wouldn't pay off for me to change. I also use loops to calculate equities, a GF, etc. I find this easier since I can control priorities and can see exactly what is happening. The equity() is nice if everything you do is traditional however if you don't, it can be very difficult to verify the results. I don't like using it as a black box. It has happened that I would spend more time analyzing trade lists than it would have taken to write a simple loop with some Trace statements.
I can write metric functions however if you want to experiment it can be too time consuming to write the whole lot of them, especially since they are already coded and debugged inside AB. Metric functions have more applications than just apply them to equity arrays - but very few users seem to be aware of that. I cannot understand why they have been exclusively reserved for BT Reports.
Best regards,
herman
Friday, August 1, 2008, 6:49:00 AM, you wrote:
> Herman and Al,
> I took the scissors to my first effort.
> It isn't an inline backtester, rather an inline RootCauseMetrics
> indicator (possibly it could be used for calculating the common
> Performance Metrics 'on the fly', including with lookback periods).
> This is the basic starting module.
> It should be possible to modify it to allow for concurrent signals,
> open trade interest, although it gets a bit harder from here for me
> (maybe not for others).
> I have checked it over a few charts and so far it stands up O.K
> I haven't used in the line of fire though.
> Any potential in it for you guys?
> FTR
> This is a continuation of discussion at topic:
> "How To Save Metrics In Composite For Indidual BT's"
> A little background discussion about the idea behind the code is at
> message # 127383 and # 127420 in the above thread.
> //P_InLineMetrics
> //Monday is used as the example because it is an unambiguous Buy
> //Typically most markets have Mon or Fri public holidays so it allows
> for checking code response to duplicate buys and sells (signal errors)
> //BarIndex() is added as a buy condition to workaround the
> propogating of {empty} values that can arise in the first few bars
> //A latch is used so that only one trade can be entered at a time and
> every Sell must have a corresponding Buy
> //Plots the trade series, as GrowthFactor, which is equivalent to %
> //No trades are accounted for and recorded as GF 1
> //The code doesn't identify break even trades i.e. GF == 1 but it can
> be modified to do so
> //since commissions aren't considered the Eq outcome for break even
> trades is correct
> //the progressive product of the GF is equivalent to the Equity Curve
> for a fixed capital investment
> //if the intitial Equity is 1 the EQ is the standardised Equity Factor
> //Equity == Initial Equity * EF
> //the product of individual GF's, sumbol by symbol, is the Portfolio
> Growth Factor the progessive product of which produces the Portfolio
> Equity Factor
> //same bar entry/exits are not allowed but the code can be modified
> for that if required
>
> //PART IA TRADE SERIES MODULE (CLOSED TRADES - ONLY ONE TRADE PER
> SYMBOL OPEN AT A TIME)
> M = DayOfWeek() == 1;
> F = DayOfWeek() == 5;
> BI = BarIndex()== 0;
> B = M;//Buy on Monday
> S = F OR BI;//first bar set to sell and then sell on Friday's
> thereafter
> B = Flip(B,S);//latches the Buy signal to prevent concurrent buys
> BP = SP = C;//BuyPrice, SellPrice
> //Plot(B,"Buy",5,1);//FFP - fault finding plot used when writing the
> code
> //Plot(S,"Sell",2,1);//FFP
> //Plot(BP,"BuyPrice",5,1);//FFP
> //Plot(SP,"SellPrice",2,1);//FFP
> TradeSeries = IIf(S ==1 AND Ref(B,-1) == 1,SP/ValueWhen(B == 1 AND Ref
> (B,-1) == 0, BP,1),1);//
> Plot(TradeSeries,"TradeSeries",1,1);//as GrowthFactor
> EF = 1;//initialises EquityFactor to 1
> for (i = 1; i < BarCount; i++)
> {
> EF[i] = EF[i-1] * TradeSeries[i];
> }
> Plot(EF,"EquityFactor",5,1);
> --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@xxx> wrote:
>> Herman,
>> IBM PartI
>> I am not sure if this is along the lines that you are investigating.
>> It might be a starting point.
>> Sophisticated functions can be built from the concept.
>> Example of using single symbol equity function to back calculate
> the
>> trade series.
>> I used buy Tues(C) and sell Thurs(C) with one month of data to test
>> the code as I went along (this gave me unambiguous signals with
> only
>> one signal at a time - I believe you can use an eq flag to dump
> dual
>> signals for real life use).
>> Note: some weeks don't have Mons or Fris so I wanted to avoid no
>> signals, caused by short weeks, during testing
>> I used barindex() > 4 to cut out the first week in the month so
> that
>> I started with no signals for a few bars before the first buy.
>> I left the plot code in there but commented out (I plotted each
> line
>> to test the veracity of the code).
>> Note that when the trade series is used to recreate the eq curve
> (as
>> a cross check) it only matches on the exit bars for each trade.
>> I tried it on 10 years of Yahoo data and the final eqs matched to 2
>> decimal places (rounded off).
>> //P_InLineEquity
>> //code to reverse engineer the trade series from the equity curve
>> //it is reversed at the end to check the accuracy of the method
>> InitialEq = 10000;//input required
>> SetOption("InitialEquity", InitialEq );
>> Buy = BarIndex() > 4 AND DayOfWeek() == 2;//use your own
>> Sell = BarIndex() > 4 AND DayOfWeek() == 4;//use your own
>> BuyPrice = C;//use your own
>> SellPrice = C;//use your own
>> Plot(Equity(),"Equity",5,1);
>> Entry = IIf(Equity() == Ref(Equity(),-1) AND Equity() != Ref(Equity
>> (),1),1,0);
>> //Plot(Entry,"Entry",1,1);
>> Exit = IIf(Equity() != Ref(Equity(),-1) AND Equity() == Ref(Equity
>> (),1),1,0);
>> //Plot(Exit,"Exit",2,1);
>> TradeSeries = IIf(Exit ==1,ValueWhen(Exit == 1,
> SellPrice,1)/ValueWhen
>> (Entry == 1, BuyPrice,1),1);
>> //Plot(TradeSeries,"TradeSeries",1,1);
>> GF = 1;//GrowthFactor
>> for (i = 1; i < BarCount; i++)
>> {
>> GF[i] = GF[i-1] * TradeSeries[i];
>> }
>> //codesters might be able to make the above loop better/prettier?
>> //Plot(GF,"GrowthFactor",5,1);
>> Plot(InitialEq * GF,"CalculatedEquity",1,1);
> ------------------------------------
> 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/
__._,_.___
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
__,_._,___
|