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

RE: [amibroker] Exploration and Max Sys DD% Question?



PureBytes Links

Trading Reference Links

I will offer you the code I use to create the same kinds of parameters
that are listed in the Title of Fred Tonetti's Equity plot but to show
them in an Explore.  I use the Tonetti code but have modified it to use
AddColumn. I find this a handy way to evaluate a system on a number of
stocks in a watchlist.  Explore on a list and you get the output shown
in the attachment.

The code is copied into the message below as I am just copying it out of
a system file.  I am leaving commented out lines in as well as I do not
want to get into troubleshooting them if I erase them.  You can play
around with the thing to your hearts content.

You have to do some modifications if you use this with a Long only
system.

You asked about MaxDD and this is one of the parameters.

The standard disclaimer applies about watching out for word wrap, extra
carriage returns etc.

Obviously, you add these lines after your system lines.

I remember FredT telling me that if I had a long only system, then to
just enter the following above these lines:

Short=0;
Cover=0;

I have not tried this so no guarantees.  Try it first on a Long/Short
system.

Notice the commented-out part of the Filter statement; you can filter
thru a long list and just get the better ones to show up.  The way it is
set now, it shows them all.

Hope this helps,

Ken
-------


////////////////////////////////////////////
E = Equity(1);
//
//     Calculate Expectance
//
dBuy   = Ref(  Buy,-1);
dSell  = Ref( Sell,-1);
dShort = Ref(Short,-1);
dCover = Ref(Cover,-1);

LongProfit = IIf(dSell,E - ValueWhen(dBuy,E),0);
ShortProfit = IIf(dCover,E-ValueWhen(dShort,E),0);
Winnings = Cum(IIf(LongProfit>0,LongProfit,0) +
IIf(ShortProfit>0,ShortProfit,0));
Losses   = Cum(IIf(LongProfit<0,LongProfit,0) +
IIf(ShortProfit<0,ShortProfit,0));
NumWinTrades = Cum((LongProfit>0) OR (ShortProfit>0) AND
Status("BarInRange"));//
NumLosTrades = Cum((LongProfit<0) OR (ShortProfit<0)  AND
Status("BarInRange")) ;//
TotalTrades   = Cum(dSell OR dCover);
WinningTrades = Cum((LongProfit > 0) OR (ShortProfit >0));
LosingTrades  = Cum((LongProfit < 0) OR (LongProfit < 0));
AveWinTrade   = Winnings / WinningTrades;
AveLosTrade   = Losses / LosingTrades;
PercentWinners = WinningTrades / TotalTrades;
Expectation = ( 1 + AveWinTrade/abs(AveLosTrade)) * PercentWinners - 1;
Ex = LastValue(expectation);

//K-Ratio in afl
BIR      = IIf(Status("BarInRange") > 0, 1, 0);
FirstBar = ValueWhen(ExRem(Buy , 0), Cum(1));
LastBar  = LastValue(ValueWhen(Status("LastBarInRange") > 0, Cum(1)));
TotBars  = LastValue(Cum(1));
BarNo    = ValueWhen(BIR > 0, Cum(1) - FirstBar + 1);
NoBars   = LastValue(BarNo);

Dates    = DateNum();
Days     = ValueWhen(BIR > 0, IIf(Dates != Ref(Dates,-1), 1, 0));
TotDays  = Cum(Days);
BPD      = BarNo / TotDays;



GraphZOrder = 1;
CurEq = Equity();
LogEq = log10(CurEq);
MaxEq = Highest(CurEq);
CurDD = 100 * (MaxEq - CurEq) / MaxEq;
MaxDD = Highest(CurDD);
CumDD    = Cum(CurDD);
BarNo = Cum(Status("BarInRange")); // New code
BarNo = BarNo - ValueWhen(Cum(Ref(Buy,-1)) == 0, BarNo); // Start
calculations at the first entry point
NoBars   = LastValue(BarNo);
mm       = LastValue(LinRegSlope(LogEq, NoBars));
bb       = LastValue(LinRegIntercept(LogEq, NoBars));
yy       = mm * BarNo + bb;
BarsTot  = ValueWhen(Status("BarInRange") > 0, Cum(BarNo));
AvgBars  = LastValue(BarsTot) / NoBars;
SRDevSQ  = ValueWhen(Status("BarInRange") > 0, sqrt(Cum((BarNo -
AvgBars) * (BarNo - AvgBars))));
ErrEq    = ValueWhen(Status("BarInRange") > 0, StdErr(LogEq, NoBars));
KRatio   = ValueWhen(Status("LastBarInRange") > 0, mm * SRDevSQ / ErrEq
/ sqrt(NoBars));
CAR      = ValueWhen(BIR > 0, 100 * ((CurEq / Ref(CurEq, -(BarNo - 1)))
^ (1 / (BarNo / BPD / 250)) -1));
ROA      = ValueWhen(BIR > 0, CAR / MaxDD);
UI       = ValueWhen(BIR > 0, sqrt(CumDD / BarNo));
UPI      = (CAR - 5.4) / UI;
TPI      = UPI / MaxDD;

/*Plot(-MaxDD, "Max DD%", colorBlue, styleThick);
Plot(IIf(Status("BarInRange") > 0, -CurDD, -1e10), "DrawDown%",
colorRed, styleHistogram);
Plot(IIf(Status("BarInRange") > 0, yy, -1e10 ), "LinReg", colorBlack,
styleThick | styleLeftAxisScale);
Plot(IIf(Status("BarInRange") > 0 OR BarNo = NoBars, LogEq, -1e10),
"Equity", colorPaleGreen, styleThick | styleLeftAxisScale);
Plot(IIf(Status("LastBarInRange") > 0 OR BarNo = NoBars, KRatio, -1e10),
"KRatio", colorGold, styleDots | styleThick | styleOwnScale, -100, 100);
Filter=MaxDD < 20;
*/
AddColumn(Car,"CAR",1.2);
AddColumn(ROA,"MAR",1.2);
AddColumn(UPI,"UPI",1.2);
AddColumn(TPI,"TPI",1.2);
AddColumn(Kratio,"K-Ratio",1.2);
AddColumn(Ex,"Expectance",1.2);
//AddColumn((Kratio+Ex)/MaxDD^2*MaxEq,"(Kratio+Ex)/MaxDD^2*MaxEq",1.2);
AddColumn(KRatio/sqrt(MaxDD),"K/D",1.2);
AddColumn(E,"Equity",1.2);
AddColumn(MaxDD,"MaxDD",1.2);
AddColumn(100*PercentWinners,"%Accur",1.2);
AddColumn(TotalTrades,"Trades",1.0);
AddColumn(WinningTrades,"Wins",1.0);
GraphXSpace = 5;
Filter= Status("LastBarInTest");// AND MaxDD < 15 AND CAR > 10;

 ///////////////

/////////////////////////////////////////////


-----Original Message-----
From: bvandyke <bvandyke@xxxxxxxxxxxxx> [mailto:bvandyke@xxxxxxxxxxxxx] 
Sent: Thursday, February 27, 2003 2:37 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Exploration and Max Sys DD% Question?

Hi all,

I've struggled with when doing an exploration on a group, over a 
certain time period, is there a way to have it list a column at 
bottom of AA window showing the Maximum System Drawdown% in a Column, 
like when we use the Optimizer?

Any help would be much appreciated. Thanks.

Bill



Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/ 



------------------------ Yahoo! Groups Sponsor ---------------------~-->
New Yahoo! Mail Plus. More flexibility. More control. More power.
Get POP access, more storage, more filters, and more.
http://us.click.yahoo.com/Hcb0iA/P.iFAA/46VHAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


Attachment:
A1.gif

Attachment: Description: "Description: GIF image"