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

[amibroker] Equity Curve Analysis of Portfolio Trading



PureBytes Links

Trading Reference Links







I have made a simple modification to the EquityLine indicator that I wrote to handle portfolios (See Attached)

In order to use this save it as a custom indicator NOT over the original or modified EquityLine.

There is probably a simpler way to do this that doesn’t require the extra steps below but I’m not there yet.

In your AA you must have a statement like the following

AddToComposite(Equity() - 500000, "~CompEquity","X",15);

Where you need to replace the 500000 with whatever your initial equity is.

In the indicator itself you must again replace the 500000 with whatever your initial equity is.

CmpEq    = Foreign("~CompEquity", "X") + 500000; 

You can then apply the indicator to a chart once you have run your scan / backtest etc. and get results for your portfolio trading.

The system I used was again a simple KST type system as follows with position sizing in this case being 100,000 or 20% of initial equity.  The portfolio had in it 3 stocks GE / GM / IBM for testing purposes to see that the calculations worked.  Preliminary testing shows that it appears to be accurate. 

Let me know what you think …

Fred

PositionSize = 100000;

KST =  (MA(ROC(Close,10),10) * 1) +

       (MA(ROC(Close,15),10) * 2) +

       (MA(ROC(Close,20),10) * 3) +

       (MA(ROC(Close,30),15) * 4);

Buy = Cross(KST ,  MA(KST, 109));

Sell = Cross(MA(KST , 120) , KST);

AddToComposite(Equity() - 500000, "~CompEquity","X",15);

 <<...>> 










Yahoo! Groups Sponsor


  ADVERTISEMENT









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 the Yahoo! Terms of Service.



CmpEq    = Foreign("~CompEquity", "X") + 500000;

MaxGraph    = 10;
GraphZOrder =  1;
GraphXSpace = 20;
GraphYSpace = 10;

BIR      = IIf(Status("BarInRange") > 0, 1, 0);

MaxEq    = Highest(CmpEq);
CurDD    = 100 * (MaxEq - CmpEq) / MaxEq;
MaxDD    = Highest(CurDD);
FlatEq   = IIf(BIR, BarsSince(MaxEq > Ref(MaxEq,-1)),0);
MaxFlat  = Highest(FlatEq);
LMaxFlat = LastValue(MaxFlat) * (1 + GraphYSpace / 100);
LogEq    = log10(CmpEq);

CurDD    = IIf(BIR, 100 * (MaxEq - CmpEq) / MaxEq, 0);
RCurDD   = round(CurDD * 100) / 100;
MaxDD    = Highest(CurDD);
RMaxDD   = round(MaxDD * 100) / 100;
LMaxDD   = LastValue(MaxDD) * (1 + GraphYSpace / 100);
CumDD    = Cum(CurDD);

FirstBar = ValueWhen(ExRem(CmpEq != Ref(CmpEq, -(Cum(1) -  1)),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;

BAHEq    = ValueWhen(BIR > 0, log10(Ref(CmpEq, -(BarNo - 1)) * (C / Ref(C, -(BarNo - 1)))));
CAR      = ValueWhen(BIR > 0, 100 * ((CmpEq / Ref(CmpEq, -(BarNo - 1))) ^ (1 / (BarNo / BPD / 252)) -1));
Ann      = ValueWhen(BIR > 0, 100 * ((CmpEq / Ref(CmpEq, -(252 * BPD)) - 1)));
MAR      = ValueWhen(BIR > 0, CAR / MaxDD);
UI       = ValueWhen(BIR > 0, sqrt(CumDD / BarNo));
UPI      = (CAR - 5.4) / UI;
TPI      = UPI / MaxDD;

b0       = LastValue(LinRegIntercept(Ref(LogEq, -(TotBars - LastBar)), NoBars));
m        = LastValue(LinRegSlope(Ref(LogEq, -(TotBars - LastBar)), NoBars));
y        = m * BarNo + b0;

BarsCum  = ValueWhen(BIR > 0, Cum(BarNo));
AvgBar   = LastValue(BarsCum) / NoBars;
SRDevSQ  = ValueWhen(BIR > 0, sqrt(Cum((BarNo - AvgBar) ^ 2)));
ErrEq    = LastValue(StdErr(Ref(logEq, -(TotBars - LastBar)), NoBars));
KRatio   = ValueWhen(BIR > 0, m * SRDevSQ / ErrEq / sqrt(NoBars));

Title = EncodeColor(colorGrey50) + "Equity  = " + EncodeColor(colorWhite)       + WriteVal(CmpEq, 3.1) + " " +
        EncodeColor(colorGrey50) + "CurFlat = " + EncodeColor(colorYellow)      + WriteVal(FlatEq, 3.0) + " " +
        EncodeColor(colorGrey50) + "CAR% = "    + EncodeColor(colorBrightGreen) + WriteVal(CAR, 3.1) + "% " +
        EncodeColor(colorGrey50) + "CurDD% = "  + EncodeColor(colorRed)         + WriteVal(-CurDD, 3.1) + "% " +
        EncodeColor(colorGrey50) + "MAR = "     + EncodeColor(colorBrightGreen) + WriteVal(MAR, 3.1) + " " +
        EncodeColor(colorGrey50) + "KRatio = "  + EncodeColor(colorPaleGreen)   + WriteVal(KRatio, 3.1) + " " +
        EncodeColor(colorGrey50) + "UPI = "     + EncodeColor(colorPaleGreen)   + WriteVal(UPI, 3.1) + " " +
        EncodeColor(colorGrey50) + "UI = "      + EncodeColor(11)               + WriteVal(UI, 3.2) +
        "\n" +
        EncodeColor(colorGrey50) + "LinReg = "  + EncodeColor(colorLightBlue)   + WriteVal(10 ^ y, 3.1) + " " +
        EncodeColor(colorGrey50) + "MaxFlat = " + EncodeColor(colorDarkYellow)  + WriteVal(MaxFlat, 3.0) + " " +
        EncodeColor(colorGrey50) + "Ann% = "    + EncodeColor(colorBrightGreen) + WriteVal(Ann, 3.1) + "% " +
        EncodeColor(colorGrey50) + "MaxDD% = "  + EncodeColor(colorDarkRed)     + WriteVal(-MaxDD, 3.1) + "% " +
        "\n" +
        EncodeColor(colorGrey50) + "B & H   = " + EncodeColor(colorGrey50)      + WriteVal(10 ^ BAHEq, 3.1);


Plot(IIf(BarNo > 0, -RCurDD, -1e10), "CDD%",   colorRed,         styleOwnScale | styleHistogram, -LMaxDD, LMaxDD);
Plot(IIf(BarNo > 0, -RMaxDD, -1e10), "MDD%",   colorDarkRed,     styleOwnScale,                  -LMaxDD, LMaxDD);
Plot(IIf(BarNo > 0, FlatEq, -1e10), "CF",     colorYellow,      styleOwnScale | styleHistogram, -LMaxFlat, LMaxFlat);
Plot(IIf(BarNo > 0, MaxFlat,-1e10), "MF",     colorDarkYellow,  styleOwnScale,                  -LMaxFlat, LMaxFlat);

MinEq1 = LLV(Y, NoBars);
MinEq2 = LLV(BAHEq, NoBars);
MinEq3 = LLV(logEq, NoBars);
MinEq4 = Min(MinEq1, MinEq2);
MinEq5 = Min(MinEq4, MinEq3);
MinEq6 = LastValue(MinEq5);

MaxEq1 = HHV(Y, NoBars);
MaxEq2 = HHV(BAHEq, NoBars);
MaxEq3 = HHV(logEq, NoBars);
MaxEq4 = Max(MaxEq1, MaxEq2);
MaxEq5 = Max(MaxEq4, MaxEq3);
MaxEq6 = LastValue(MaxEq5);

MinEq7 = MinEq6 - ((MaxEq6 - MinEq6) * GraphYSpace / 100);
MaxEq7 = MaxEq6 + ((MaxEq6 - MinEq6) * GraphYSpace / 100);

Plot(IIf(BarNo > 0, y,      -1e10), "L/R Eq", colorBlue,        styleOwnScale | styleNoLabel, MinEq7, MaxEq7);
Plot(IIf(BarNo > 0, BAHEq,  -1e10), "BAH Eq", colorGrey50,      styleOwnScale | styleNoLabel, MinEq7, MaxEq7);
Plot(IIf(BarNo > 0, LogEq,  -1e10), "Sys Eq", colorWhite,       styleOwnScale | styleNoLabel, MinEq7, MaxEq7);