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

Some code for a couple of extra performance stats



PureBytes Links

Trading Reference Links

Here's a quick doodah I wrote that presents a couple of performance stats
that the TS2000i Performance Report doesn't give, like the Buy & Hold annual
compound growth rate and the compound rate of growth while your strategy is
in the market (potentially helpful if your strategy is in the market only
40-50% of the time for example).  By default the results are printed on your
chart at the beginning of 2002, and appear like this:

"Hold:  10.8%
Actu: 7.7%
Equi: 21.6%"

Print position can effectively be displaced by changing the two input
parameters.

All the best
Rhetus

{**************************************************************************}
{This module calculates the annual compound growth performance
for (a) Buy & Hold, (b) strategy over the period of testing, and
(c) strategy for the times it is in the market (figure represents
rate at which strategy performs whilst in a position)}
{***************************************************************************
}

Inputs: _PrintDate(1020101),{Date by which to calculate & print compound
results}
  _VertDisp(0),  {Vertical displacement for printing of compound results}

Vars: FirstOpen(0),  {Holds Open price of first ever bar after MaxBarsBack}
  Years1(0),   {Holds # years of data being considered}
  Years2(0),   {Holds equiv # years strategy was in market}
  TotalReturn1(0), {Holds % total return in buy $ hold strategy}
  TotalReturn2(0), {Holds % equiv total return for strategy wrt % time in
market}
  AnnualReturn1(0), {Holds Cmpd annual rate return of stock if buy & hold}
  AnnualReturn2(0), {Holds Cmpd annual rate return for strategy wrt % time
in market}
  AnnualReturn3(0), {Holds actual Cmpd annual rate return for strategy}
  FirstBarDate(0), {Holds Date of first ever bar after MaxBarsBack}
  DaysInMarket(0), {Holds total # days strategy is in market}
  PrintFlag(0);  {Flag to indicate whether compound results have been
printed}

{************BUY & HOLD ANNUAL COMPOUND RATE OF RETURN**************}
If CurrentBar = 1 then Begin
 FirstBarDate = Date;
 FirstOpen = Open[CurrentBar];
End;

If MarketPosition <> 0 then DaysInMarket = DaysInMarket + 1;

If Date > _PrintDate AND PrintFlag = 0 then Begin

 PrintFlag = 1;
 Years1 = CurrentBar / 252;
 Years2 = DaysInMarket / 252;
 TotalReturn1 = ((Close-FirstOpen) / FirstOpen);
 TotalReturn2 = ((GrossProfit + GrossLoss)/10000);

 {Calculate compound performance rates}
 AnnualReturn1 =
  100*(ExpValue(log(1+TotalReturn1) / Years1) - 1);

 {Avoid processing a negative value}
 If TotalReturn2 > -1 then Begin
  AnnualReturn3 =
   100*(ExpValue(log(1+TotalReturn2) / Years1) - 1);
  AnnualReturn2 =
   100*(ExpValue(log(1+TotalReturn2) / Years2) - 1);
 End;

 {Print values at end of chart}
 Value1 = Text_New (_PrintDate, 0001, High*1.14 + _VertDisp,
  "Hold: "+NumToStr(AnnualReturn1, 1)+"%");
    Value1 = Text_New (_PrintDate, 0001, High*1.12 + _VertDisp,
  "Actu: "+NumToStr(AnnualReturn3, 1)+"%");
 Value1 = Text_New (_PrintDate, 0001, High*1.10 + _VertDisp,
   "Equi: "+NumToStr(AnnualReturn2, 1)+"%");

End;