PureBytes Links
Trading Reference Links
|
I haven't run the test to verify, but your assertion of Start picking up the previous Close sounds very fishy to me. More likely that particular trading day was not a high and thus had no impact on the result.
Mike
--- In amibroker@xxxxxxxxxxxxxxx, "ta" <tagroups@xxx> wrote:
>
> Thanks a million it seem to work as intended. I do see the logic. As for
> your comment on Start and End being error prone if they fall on a
> non-trading date, I changed the start date to 12/31/2000 which is a non
> trading date and it correctly picked up the close from 12/29/2000. However,
> your point seems to be correct regarding the End date. If I change the end
> date from 12/31/2008 to 01/01/2009 it return 0 for drawdown.
>
>
>
> From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
> Of Mike
> Sent: Friday, March 05, 2010 12:46 AM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Re: Drawdown Calculation
>
>
>
>
>
> Hi,
>
>
>
> Your calculations for Start and End are error prone in that they do not
> handle the case where the given dates are not trading dates.
>
>
>
> However, building on what you've got, you can do something like the
> following. Ideally you would also add code to verify that Start and End are
> less than BarCount.
>
>
>
> /*
> * Return positive scaler value representing the largest percentage drawdown
> * within the given array between the given dates, inclusive.
> *
> * e.g. Largest drawdown of 10 down to 3 would be returned as 70 indicating
> 70%.
> */
> function MaxDDFromTo( Array, From, To )
> {
> Indices = BarIndex();
> Start = LastValue( ValueWhen( DateTime() == StrToDateTime( From ),
> Indices ) );
> End = LastValue( ValueWhen( DateTime() == StrToDateTime( To ), Indices )
> );
> InRange = Indices >= Start AND Indices <= End;
>
> CurVal = IIF( InRange, Array, 0 );
> MaxVal = Highest( CurVal );
> CurDD = IIF( InRange AND CurVal < MaxVal, 100 * ( MaxVal - CurVal ) /
> MaxVal, 0 );
> MaxDD = Highest( CurDD );
>
> return LastValue( MaxDD );
> }
>
> _TRACE("from: " + "12/29/2000" + " To: " + "12/31/2009" + " MaxDD: " +
> MaxDDFromTo(C, "12/29/2000", "12/31/2009") );
>
>
>
> Mike
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "ta" <tagroups@> wrote:
> >
> > I have written the following function to calculate the drawdown between
> two
> > dates. Does anybody know how eliminate the loop or make it run faster? TIA
> >
> >
> >
> > function MaxDDFromTo(Array, From, To)
> > {
> > Last = LastValue(BarIndex());
> > Start = LastValue(ValueWhen(DateTime() == StrToDateTime(From),
> > BarIndex()));
> > End = LastValue(ValueWhen(DateTime() == StrToDateTime(To), BarIndex()));
> >
> > Price = Array;
> > MaxPrice = DD = MaxD = Bars = 0;
> > for( i = Start; i < End; i++ )
> > {
> > Bars = Bars + 1;
> > MaxPrice = Max(MaxPrice, HHV( Price, Bars ));
> > DD = 100 * ( Price[i] - MaxPrice ) / MaxPrice;
> > MaxD = Min(MaxD, LLV( DD, Bars ));
> > }
> > return MaxD;
> > }
> >
> > _TRACE("from: " + "12/29/2000" + " To: " + "12/31/2009" + " MaxDD: " +
> > MaxDDFromTo(C, "12/29/2000", "12/31/2009") );
> >
>
------------------------------------
**** 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:
amibroker-digest@xxxxxxxxxxxxxxx
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/
|