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

Re: [amibroker] Re: Custom Metric not working in Alpha 5.27.1



PureBytes Links

Trading Reference Links



Thanks for your help Mike.  It's a lot to digest.  I'll see if I can get it to work more effectively with your code and suggestions.

Wade

--- On Wed, 8/5/09, Mike <sfclimbers@xxxxxxxxx> wrote:

From: Mike <sfclimbers@xxxxxxxxx>
Subject: [amibroker] Re: Custom Metric not working in Alpha 5.27.1
To: amibroker@xxxxxxxxxxxxxxx
Date: Wednesday, August 5, 2009, 4:56 PM

 

Correction,

"Note that since you passed in Ref(..., -1) as 'eq', this array will not have a final element (i.e. index of BarCount - 1) since tomorrow hasn't happened yet so today's value is unknown. This means that if a trade's entry date is the last bar in the range, you will be trying to reference a non existent equity value."

Should read

"Note that since you passed in Ref(..., -1) as 'eq', this array will not have a *first* element (i.e. index of 0) since day prior to first day is unknown. This means that if a trade's entry date is the *first* bar in the range, you will be trying to reference a non existent equity value."

http://www.amibroke r.com/guide/ h_understandafl. html

Mike

--- In amibroker@xxxxxxxxx ps.com, "Mike" <sfclimbers@ ...> wrote:
>
>
> Hi,
>
> Your code is somewhat overly complex. If BarCount is zero, 'found' will
> be -1, which is an invalid index. If 'Value' does not match any element
> in 'dt' then found will be BarCount, which is also an invalid index.
>
> Note that since you passed in Ref(..., -1) as 'eq', this array will not
> have a final element (i.e. index of BarCount - 1) since tomorrow hasn't
> happened yet so today's value is unknown. This means that if a trade's
> entry date is the last bar in the range, you will be trying to reference
> a non existent equity value.
>
> At any rate, your FindEquityAtDateTim e function can be simplified to a
> single line as follows:
>
>
> function FindEquityAtDateTim e(eq, dt, Value) {
> return LastValue(ValueWhen (dt == Value, eq));
> }
>
>
> Also, it is highly redundant to fetch the performance stats and
> calculate 'pratio' at each trade. The value will never change, so just
> do it once either before or after looping through the trades, not inside
> the loop.
>
> Finally, be wary of using summary measures such as WinnersPercent and
> PayoffRatio. These are based on the assumption that open trades have
> been closed at their current price (i.e. assumes that all open trades
> get closed based on final bar's closing price). If you have more than a
> few open trades, they can really throw off the summary statistics.
> Better to calculate the stats yourself based only on closed trades.
>
> Mike
>
>
> --- In amibroker@xxxxxxxxx ps.com, "wadebullock" <wadebullock@ > wrote:
> >
> > Hi all,
> >
> > In previous beta versions the following custom metrics were working
> fine. Now I get message Error 10...it also is below. If anyone sees a
> problem with the code I would greatly appreciate the help. I pieced it
> together from several examples but still have difficulty understanding
> it. Thanks
> >
> > SetCustomBacktestPr oc("");
> > function FindEquityAtDateTim e( eq, dt, Value )
> > {
> > found = -1;
> > for( i = 0; i < BarCount AND found == -1; i++ )
> > {
> > if( dt[ i ] == Value ) found = i;
> > }
> > return IIf( found != -1, eq[ found - 0 ], Null );
> > }
> > if( Status("action" ) == actionPortfolio )
> > {
> > bo = GetBacktesterObject ();
> > bo.Backtest( 1);
> > dt = DateTime();
> > eq = Ref(Foreign( "~~~EQUITY" , "C" ),-1);
> >
> > for( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
> > {
> > EquityAtEntry = FindEquityAtDateTim e( eq,dt,trade. EntryDateTime );
> > PctLossGain = (trade.GetProfit( )/EquityAtEntry) *100;
> > trade.AddCustomMetr ic("Equity at Entry", EquityAtEntry );
> > trade.AddCustomMetr ic("% Gain/Loss of Equity", PctLossGain );
> > st = bo.GetPerformanceSt ats(0);
> > pratio=(st.GetValue ("WinnersPercent "
> )/100)*st.GetValue( "PayoffRatio" );
> >
> > }
> > bo.ListTrades( );
> > bo.AddCustomMetric( "Performance Ratio", pratio );
> >
> > }
> >
> >
> > Error 10 Message///// ///////// ///////// ///////// ///////// ///////// ///
> > {
> >
> > if( dt[ i ] == Value ) found = i;
> >
> > }
> >
> > return IIf( found != -1, eq[ found - 0
> > ------------ --------- --------- --------^
> >
> > Error 10.
> > Subscript out of range.
> > You must not access array elements outside 0..(BarCount- 1) range.
> >
>



__._,_.___


**** 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/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___