;-------------------------------------------------------------------------------------------
;
;     This is an experiment with composites of Don Bell's thrust signals and RUT
;     price oscillator
;
;     Bruce Robinson - 10/8/03
;
;     Run as -
;
;          tradefr thrustcomposite.ini r2oscsg nyvt0 nybt0 nynhts 1
;
;-------------------------------------------------------------------------------------------


[Expression]

;  Parameters

DELAY           = |4|
FUND            = dfscx
INDEX           = ptldx

;  Set the default delay to 1

If (|4| - 4)
        DELAY           = 1
EndIf

;  Get vectors for family operation

_|0|            = Vector(|0|)
_|1|            = Vector(|1|)
_|2|            = Vector(|2|)
_|3|            = Vector(|3|)

;  Get the composite signal

Composite.Buy      = |0| Or
                        (
                         |1| Or
                         |2| Or
                         |3|
                        )
Composite.Sell     = |0| Or 
                        (
                         |1| Or
                         |2| Or
                         |3|
                        )

WriteFile(Composite, ThComp)

_Composite      = Vector(Composite)

;  Put it all in a family

vectfam = Family(
                 _|0|, 
                 _|1|,
                 _|2|,
                 _|3|,
                 _Composite
                )

sigfam          = Signal(vectfam)

;  Trade it
                
res             = SignalPairTrade(FUND, INDEX, sigfam, DELAY)

;  Get a bunch of stat's

riskfree        = .05
fmdays          = Last(Sum(res / res))
WINDOW          = fmdays
tot             = Last(res) / First(res) - 1
ann             = Pow(10, Log(res / First(res)) / ((fmdays - 1) / 252)) - 1
sdf             = Stdev(Roc(res, 1), WINDOW) * Pow(252, 0.5)
sharpe          = (ann - riskfree) / sdf

peak            = Max(res, WINDOW)
cdd             = (peak - res) / peak
mdd             = Last(Max(cdd, WINDOW))
ui              = Pow(Sma(Pow(cdd, 2), WINDOW) * WINDOW / WINDOW, 0.5)
upi             = (ann - riskfree) / ui

;  Get the percentage of days on buy

daysin          = Sum(vectfam + 0.5) + res - res
totdays         = Sum(vectfam - vectfam + 1) + res - res
pcntin          = daysin / totdays

;  Output

FamPrint(       
;                tot * 100,              "TOTAL%",
;                totdays,                "TOT DAYS",
                ann * 100,              "CAR%",
                mdd * 100,              "MDD%",
                upi,                    "UPI",
                pcntin* 100,            "%DAYS IN"
        )



;[SignalPairTrade]

;Delay = |4|
;Signal = rutvol
;Fund =  DFSCX
;Index = PTLDX
;HoldMinDays = 1
;StartDate = 1/1/96 ;4/1/00
;FnuFile = thcm2



[SignalPairTrade]

Delay = |4|
Signal = ThComp
Fund =  DFSCX
Index = PTLDX
HoldMinDays = 1
StartDate = 1/1/96 ;4/1/00
FnuFile = THCMP