Professional Documents
Culture Documents
Optimization Seminar PDF
Optimization Seminar PDF
Optimization Seminar PDF
Bruce Robinson
brobinson@zwave.net
Presentation Overview
Model
Back-test
Optimize
Back-testing
???
2001
2003
TODAY
BACKTEST AND
OPTIMIZE
Other issues
Back-testing
Survivorship bias
Bad performing stocks fold, or merge
Good funds record is bought
Bad funds record is buried
Selection bias
AI optimization
Keywords
Near optimal
Robust
Out of sample, walk-forward
Near optimality -
Robustness -
1998
2000
2002
TODAY
1998
2000
2002
TODAY
Fitness is UPI
UPI of solution point = 2
CAR = 15, CAR goal = 20
Fitness adjustment is .75 * 2 = 1.5
Sensitivity
Signal Forms
Amibroker signals
Data by
Impulse form
What is state ?
Example 2 of state
requirement
Data by
Example 2 of state
requirement
Data by
Backtester(s)
Functional
considerations
Automatic
Analysis
Code
Back-Tester
RESULTS
All
Current
Stocks
Stock
Filter
Portfolio backtester
www.amibroker.com/gifs/bt_regular.gif
Boilerplate 1 settings
code //EnableRotationalTrading();
BuyPrice = SellPrice = ShortPrice =
CoverPrice = Open;
SetTradeDelays( 1, 1, 1, 1 );
SetFormulaName("TEST");
Boilerplate 2 settings
code SetOption(
SetOption(
SetOption(
);
SetOption(
);
"InitialEquity",
"MinShares",
"MinPosValue",
1000 );
.0001 );
0
SetOption(
SetOption(
);
SetOption(
SetOption(
"AllowPositionShrinking",
"ActivateStopsImmediately",
True
);
True
"ReverseSignalForcesExit",
"AllowSameBarExit",
True
True
);
);
"FuturesMode",
False
Boilerplate 2 code
considerations
Boilerplate 3 settings
code SetOption(
);
SetOption(
0
);
SetOption(
0
);
SetOption(
100
);
SetOption(
);
SetOption(
);
SetOption(
True );
SetOption(
);
"CommissionMode",
"CommissionAmount",
"InterestRate",
"MarginRequirement",
"MaxOpenPositions",
"WorstRankHeld",
"PriceBoundChecking",
"UsePrevBarEquityForPosSizing",
True
Boilerplate 3 code
considerations
Boilerplate 3 code
considerations
Boilerplate 4 settings
code MaxPos
= 100 * 100 /
RoundLotSize
TickSize
MarginDeposit
PointValue
= 0;
= 0;
= 0;
= 1;
GetOption("MarginRequirement");
PositionSize
= -MaxPos /
GetOption("MaxOpenPositions");
// 0 for Funds, 100 for Stocks
// 0 for no min. size
// For futures
ExitAtTradePrice
= 0;
ExitAtStop
= 1;
ExitNextBar
= 2;
ApplyStop( stopTypeLoss, stopModeDisable, 0,
ExitAtTradePrice );
ApplyStop( stopTypeProfit, stopModeDisable, 0,
ExitAtTradePrice );
ApplyStop( stopTypeTrailing, stopModeDisable, 0,
ExitAtTradePrice );
ApplyStop( stopTypeNBar, stopModeDisable, 0,
Boilerplate 4 code
considerations
For example
x = Optimize( X, 5, 1, 10, 1 );
y = Optimize( Y, 50, 100, 1000, 100 );
Passes
( 1, 100 )
( 1, 200 )
etc.
Parameters to functions
True/False (1/0) to gate a condition
Comparison to Status(stocknum) to choose
from watchlist
SetOption() parameter
PositionSize
Guidelines
For example
( 2, 200 )
( 3, 200 )
( 2, 300 )
etc.
IO Directives and
Options
Disable the
directive
// Remove in final "production" run
//xIO: FitnessTime: 300
5 minute
//xIO: SenFinalTests: 1000
limit
1000 samples for
sensitivity
Penalize result < 85%
//IO: SenOptGoalPct: 85
sensitivity
//IO: SenOptTests: 10
10
samples to determine
//IO: Fitness: UPI
sensitiviy
CAR goal to prevent high
//IO: Goal: CAR: 15
UPI, low CAR
//xIO: BegISDate: 01/01/1995
//xIO: EndISDate: 01/01/2001
Walk-forward directives
//xIO: EndOSDate: 9/15/2005
disabled
//xIO: WFAuto: Anchored: Every: Year
Sector Trading
Elevator pitch
Buy a sector fund when it reaches its
N day low
Hold for a minimum of H days
Take profits when it reached P percent
ProfitStop
LowDays
= IIf( LLV( C, NumDays ) == C, 1, 0 );
Buy
= LowDays;
Sell
= 0;
// Will be exited by N-bar stop or by
Profit target
Short
= Cover = 0;
Sector Trading.afl
Example os a Portfolio
Optimization System
A solution
A solution
= 70;
Why it works
= -fund1pcnt;
= -fund2pcnt;
= -fund3pcnt;
= -fund4pcnt;
= -fund5pcnt;
PortHedge2IO.afl
Designed to use IO
Uses FastTrack symbols
Hedging mode uses FastTrack based
signals
Methodology and
Conclusions
Steps of the
Methodology
Conceptualize
Code
Steps of the
Methodology
System Lifetime
Steps of the
Methodology