Sunteți pe pagina 1din 7

Up until recently the only way to the loop: one system applied to

test a system was to apply it to one market bar-by-bar, the loop


one market at the time, and in needs to be: one system applied
so doing, in a bar-by-bar fashion bar-by-bar on the whole portfolio
on the historical data. Money of markets. That is, instead of
management possibilities have applying a system to all bars of
been rudimentary to say the least, market 1, then repeat with market
as has portfolio operations, such 2, and so on, a better way to do
The Future of System Development – Part 1 as ranking and filtering. These it would be to: apply systems 1 to
days, though, more and more TA n to markets 1 to n on bar 1, then

Additional Data – programs offer these features


and more, even at a relatively low
cost.
repeat on bar 2, and so on.
In the old way of doing things
all system-market combos act in

Better Performance The easiest and most intuitive


way for the user to handle
multiple data streams would be
isolation from one another and
none of them have any clue what
the others are up to in regards to
to simultaneously have access to indicator values, imminent trades,
As computers are becoming faster and faster almost by the day and the amount of data they can handle increases the price data for all markets in a current open positions, etc. With
almost at an exponential rate every few years, the type of research a technical trader in general and a systems portfolio, no matter which market the newer approach all system-
developer in particular can perform also becomes more sophisticated and computationally intense. A few developers currently happens to be the active market combos are updated bar-
of TA software are picking up on this, offering their customers new and improved ways of developing strategies. In one in the TA software. For this to by-bar on everything that goes
this article I will explore how to handle parallel multiple data streams, such as other similar markets, indexes and be possible the testing procedure on within all the other combos,
interest rates. The programming code is available at the end of this article. needs to follow a completely with each combo having access
different path. Instead of the not only to the price data of the
order logic being a repetition of other markets, but also current
16
TRADERS´ insights

and historical indicator values, three percentage points annually,


open and closed positions within which, over a 20-year period
all systems, other mutually shared would have doubled the account
data streams, etc. equity, everything else between
One TA program that does all the two tests held constant.
this really well at a reasonable The system is a basic volatility- F1) Trading without an Interest
price is TradingBlox, although breakout system, applied to 49
other, even cheaper programs, futures markets, an average of
such as TradersStudio, also 0.2 per cent of total equity risked
continuously improve and add to per trade, approximately $50
the list of these more advanced deducted per contract traded for
features. slippage and commission. You
will find some sample code for
Add Dividend Income TradingBlox on how to do this on
One basic example of an added our website.
data stream, shared across all In the above example, the
markets and systems within a dividend rate data stream is
larger strategy, would be the not applied to any individual
addition of a short-term interest system-market combination, but The equity growth in this chart does not include any accrued diidend
rates, which makes the final net profit considerably lower than that in
rate income stream added to the rather to the strategy itself and Figure 2.
account equity. Another basic the cumulative equity stream Source: TradingBlox
Thomas Stridsman example would be an index generated by all markets. With
applied to a portfolio of markets, the possibility to add this extra
Mr Thomas Stridsman is a in combination with a trading layer of instructions to the
partner of Alfakraft Fonder, rule that could state, “Trade only strategy itself, you also could F2) Trading with an Interest
where he manages two those markets that fluctuate the apply some general constants
funds (Alfa Commodity and most relative to the index, re- and parameters. Table 3 shows
Alfa Energy). He has been evaluate daily (weekly/monthly) the results from the same system,
developing strategies for which markets should belong to this time net of a 1 per cent
model-based investing since this sub-group”. From a strategy- management fee and 20 per
the early 1990s. Prior to joining testing perspective both these cent performance fee, deducted
Alfakraft Fonder, Mr Stridsman data streams should be viewed monthly and quarterly from the
managed client money in as added more to the strategy cumulative total equity.
the FX markets. He also is a itself rather than to any individual
freelance analyst and author market or system. Trade against an Index
of the two books Trading Tables 1 and 2, and Figures 1 A second example of a shared
Systems That Work (2000) and and 2 illustrate the difference in data stream could be the addition
Trading Systems and Money performance between a system of an un-traded market index Adding the possibility of earning dividend income on your account
equity will not only increase your return, it also will lower your
Management (2003). that will not consider dividend against which all other markets drawdowns and decrease time in drawdown.
income, vs. one that will. In this compare and trade. In this case Source: TradingBlox
case the difference is close to the short-term momentum of all

04/2011 www.tradersonline-mag.com
17
TRADERS´ insights

individual markets is compared to of two average true ranges is also momentum should work well with
the longer-term momentum of the applied. any look-back period between
GSCI index. The trading rule for Figure 3 shows a so-called five and 20 days for the traded
the long trades (reverse the logic surface chart of the Sharpe markets. F3) Surface Chart of the Sharpe Ratio
for the short trades) is to go long ratio for several parameter In this case we made no
when the short-term momentum combinations. The red-coloured deductions for commission,
for the traded market is below area, which represents a slippage and fees.
the long-term momentum of the Sharpe ratio above 1, indicates Figure 4 and Table 4 show the
index, on the assumption that the the most profitable parameter equity curve and performance
general trend is with the index combinations. It reveals that summary for a version of the
and the traded market therefore a 100-day look-back period system with a 15-day look-back
will reverse itself. A trailing stop (the vertical axis) for the index period for each traded market
and a 100-day look-back period
for the GSCI index, applied to
T1) Trading without Dividend Income (see Figure 1) a portfolio of 49 markets over
the last plus ten years. In this
Modified Annual Max Total Longest case the result is net of a $5
Test Ending Balance CAGR% MAR # Trades
Sharpe Sharpe Equity DD Drawdown
commission and $35 slippage The Sharpe ratio as a function of the look-back periods for two
indicators. The value of the Sharpe ratio is given by the colours in the
1 276,430,515.91 17.48% 0.63 0.95 1.10 27.9% 21.7% 8,691
per contract traded. Again, you chart. Red is high, blue is low.
will find some sample code for Source: TradingBlox
how to do this as well in the
T2) Trading with Dividend Income (see Figure 2) TradingBlox software on our
website.
Modified Annual Max Total Longest
Test Ending Balance CAGR% MAR # Trades F4) Using an Index for the Entry and Exit Rules
Sharpe Sharpe Equity DD Drawdown
Position Sizing
1 458,081,676.64 20.39% 0.78 1.09 1.18 26.1% 17.2 8,691
We can modify the above system
a bit by using the relationship
between the traded market
T3) Results Net of Management and Performance Fees and the index as a position-
sizing mechanism instead of an
Modified Annual Max Total Longest absolute trading rule. The original
Test Ending Balance CAGR% MAR # Trades
Sharpe Sharpe Equity DD Drawdown
trading rule will be substituted
1 233,418,369.85 16.52% 0.61 0.92 1.15 27.1% 21.1% 8,691
with a dual-moving average
crossover system with the two
moving averages applied only to
T4) Testing a Look-back Combo of 15 and 100 Periods (see Figure 4) the traded markets.
First, let us decide on the Using a 15-day look-back period for the primary period together with
a 100-day look-back period for the secondary period produces a
Modified Annual Max Total Longest look-back periods for the reasonable steady equity growth. The look-back periods are derived
Test Ending Balance CAGR% MAR # Trades
Sharpe Sharpe Equity DD Drawdown from the surface chart in Figure 3.
moving averages. Figure 5,
1 49,428,388.39 16.24% 0.61 0.88 0.80 26.5% 20.5% 5,935
which is a 3D version of a Source: TradingBlox
surface chart, indicates that

04/2011 www.tradersonline-mag.com
18
TRADERS´ insights

a short look-back period of RPT = BR * IM / MM, where: side we have a slightly larger
around 45 days combined with RPT = Risk per Trade, in maximum drawdown of 48
a long look-back period of percentage terms of current per cent. Again, some sample
three times the length should account equity TradingBlox code for how to alter F5) 3D Version of a Surface Chart
be a profitable and robust BR = Base Risk (= the original the trade size by varying the risk
enough solution. Figure 6 and 0.35 per cent constantly risked per trade can be found on our
Table 5 show the cumulative per trade) website.
equity curve and performance MM = Market Momentum Naturally, a drawdown of 48
summary net of slippage and IM = Index Momentum per cent, as in this last example,
commission for this system is too much for most of us to
version when tested on the Both momentum series will be handle, so this particular system
49-market portfolio. calculated as Close(t) / Close(t-n), and money management idea
The initial amount to be risked where (t) denotes today's close still needs some more research.
per trade was set to 0.35 per and (t-n) the close n days ago. But the task at hand here was
cent of total account equity for A totally flat market will have not to develop a turn-key trading
all trades on all markets. Now, a momentum of 1.0, while a strategy, but rather to illustrate
let us add a money management market in an uptrend will have a how new research techniques,
component to this system. momentum greater than 1.0. The literally impossible to implement In this case the secondary period is calculated as a multiple of the
primary period. Setting the look-back periods to 45 and 135 (= 3 x 43)
Money management will be above formula indicates that if just a few years ago, now have days respectively seems to work the best.
based on the previous relative- MM is greater than IM, RPT will become accessible to most Source: TradingBlox
momentum system. It will strive become smaller than BR. For a traders at quite modest costs,
to put on larger positions for market in a downtrend it follows thanks to faster computers and
those markets that are currently the momentum will be less better software.
lagging behind the broader than 1.0 but greater than zero. F6) System with a Basic Position-sizing Algorithm
index, while limiting the positions Therefore the formula for how Conclusion
for those markets running better much to risk in a short position The possibility of adding
than the index. The reasoning will be: additional data streams to the
behind this logic is that we strategy itself – rather than to
believe that markets that have RPT = BR * MM / IM individual markets or systems –
been lagging the index will move makes your testing results more
stronger in the immediate future Comparing Figures 6 and lifelike and directly comparable
and therefore warrants a larger 7, and Tables 5 and 6 we can to those that you would have
risk than the original 0.35 per see that this crude position- obtained had you invested with
cent of equity. Markets that are sizing mechanism managed to a professional manager. This is
already strong, on the other increase the annual return with especially true when it comes to
hand, we believe will move more approximately 1.5 percentage issues such as adding income
slowly than the index in the near points per year (from 14.9 to via dividend rates, which also The equity growth of an ordinary dual moving average cross over
system with a basic position-sizing algorithm. The look-back periods
future, and therefore should not 16.4), which in turn resulted in help you limit your drawdowns for the moving averages are derived with the help of the surface chart
in Figure 5.
be traded as aggressively. an additional $8 million in final and shorten your flat periods.
For long positions the risk per equity. The Sharpe ratio also The possibility to deduct various Source: TradingBlox
trade will be calculated as: increased a bit. On the negative management fees also comes

04/2011 www.tradersonline-mag.com
19
TRADERS´ insights

Info 1: Script Type: Before Test Info 2: Script Type: After Trading Day Info 4: Script Type: Update Indicators

Variables: ErrorCount, FileLoaded_OK Type: Integer Variables: EarnedInterest Type: Money If Min(Instrument.Bar, GSCI_Index.Bar) > RequiredLookBack Then
Variables: sSymbol, sErrorMkts Type: String \\ Declares the variable EarnedInterest to be stored within the PrimaryMom = PrimaryMom[1]
software, expressed in currency units (i.e. Dollars, Euros, etc.) \\ SecondaryMom = SecondaryMom[1]
ErrorCount = 0
If IncludeInterestRate = Yes Then If Instrument.close[PrimaryPeriod] > 0 Then
sErrorMkts = „“
PrimaryMom = Instrument.close / Instrument.
sSymbol = „F:MM0“ EarnedInterest = (InterestRate.Close * 0.01)^(1/250) *
close[PrimaryPeriod]
\\ Find the symbol MM0, which holds the time series for the short- (Test.TotalEquity[1] * 0.9)
\\ Calculate the momentum for the market (PrimaryMom) by
term interest rate, in annual percentage form on the computer used \\ Calculate the daily earned interest as a function of the interest dividing the close of the market today (Instrument.close) by the
for this article. For this article we use the 90-day American T-bill. rate expressed in annual percentage and the total equity close of the market n-days ago. The look-back period for the
You might have to change the symbol name to combine with your generated so far by the strategy. In this test we assume 90% of momentum calculation is denoted by the variable PrimaryPeriod. \\
data. \\ the total equity can be placed in T-bills at all times. \\ EndIf
FileLoaded_OK = InterestRate.LoadSymbol( sSymbol ) Test.UpdateOtherExpenses(-EarnedInterest) If GSCI_Index.close[SecondaryPeriod] > 0 Then
\\ Update the internal variable UpdateOtherExpenses, built into the SecondaryMom = GSCI_Index.close / GSCI_Index.
\\ Load the located symbol and assign it the variable name
software, to keep track of this income stream for further analysis. close[SecondaryPeriod]
InterestRate. \\
\\ Calculate the momentum for the GSCI index (SecondaryMom)
If FileLoaded_OK < 1 Then \\
by dividing the close of the GSCI index today (GSCI_Index.
ErrorCount = ErrorCount + 1 EndIf
close) by the close of the GSCI index n-days ago. The look-back
sErrorMkts = sSymbol period for the momentum calculation is denoted by the variable
Print sSymbol + „ - Failed to Load.“ SecondaryPeriod. \\
EndIf
Info 3: Script Type: Before Test EndIf
If ErrorCount > 0 Then LongStopLine = Instrument.close - 2*AverageTrueRange
GSCI_Index.LoadSymbol(„F:GI“) \\ Calculate where to place a stop loss in case of a long trade and
Test.AbortSimulation( „File Loading Found: „ _
\\ Find the symbol GI, which holds the time series for the GSCI place that value in the variable LongStopLine. \\
+ AsString(ErrorCount, 0) _
index on the computer used for this article, and assign it the ShortStopLine = Instrument.close +
+ „ Errors“ + Chr(10) _
variable name GSCI_Index. You might have to change the symbol 2*AverageTrueRange
+ „ Create Indices Was Not Successful“ + Chr(10) _
name to combine with your data. \\ \\ Calculate where to place a stop loss in case of a short trade and
+ „ These Symbols Failed: „ + sErrorMkts + Chr(10) _
place that value in the variable ShortStopLine. \\
+ „ - Simulation will terminate!“ )
EndIf
EndIf

04/2011 www.tradersonline-mag.com
20
TRADERS´ insights

Info 5: Entry Orders Info 6: Script Type: Before Instrument Day Info 7: Script Type: Unit Size

If Min(Instrument.Bar, GSCI_Index.Bar) > RequiredLookBack Then If Min(Instrument.Bar, GSCI_Index.Bar) > RequiredLookBack Then Variables: EquityAmount, ContractAmount Type: Money
If Instrument.Position <> Long and PrimaryMom < SecondaryMom AdjustLongRisk = 1 Variables: TradeSize Type: Integer
Then AdjustShortRisk = 1 If Order.Position = Long Then
\\ Check whether it is possible to go long. The market should not If UseRelativeMomentum = Yes Then AdjustedRiskPercent = RiskPercent * AdjustLongRisk
be long already and the momentum of the market needs to be less MarketMom = MarketMom[1] \\ Calculate how much to risk, in percentage terms, for the next
than the momentum of the GSCI index. \\ IndexMom = IndexMom[1] long trade, as a function of the original risk (=0.35%, as stated in
Broker.EnterLongOnOpen(LongStopLine) If Instrument.close[MarketLookback] > 0 Then the article) times the adjustment factor for the next long trade.\\
\\ Instruct the software to initiate a long position and pass on the MarketMom = Instrument.close / Instrument. Else
price for where to take a loss. \\ close[MarketLookback] If Order.Position = Short Then
EndIf \\ Calculate the momentum for the market (MarketMom) by AdjustedRiskPercent = RiskPercent * AdjustShortRisk
If Instrument.Position <> Short and PrimaryMom > dividing the close of the market today (Instrument.close) by \\ Calculate how much to risk, in percentage terms, for the next
SecondaryMom Then the close of the market n-days ago. The look-back period short trade, as a function of the original risk (=0.35%, as stated in
\\ Check whether it is possible to go short. The market should not for the momentum calculation is denoted by the variable the article) times the adjustment factor for the next short trade. \\
be short already and the momentum of the market needs to be MarketLookback. \\ EndIf
greater than the momentum of the GSCI index. \\ EndIf EndIf
Broker.EnterShortOnOpen(ShortStopLine) If GSCI_Index.close[IndexLookback] > 0 Then ContractAmount = Order.EntryRisk * Instrument.
\\ Instruct the software to initiate a short position and pass on the IndexMom = GSCI_Index.Close / GSCI_Index. BigPointValue
price for where to take a loss. \\ Close[IndexLookback] \\ Calculate how much one contract will risk in the next trade,
EndIf \\ Calculate the momentum for the GSCI index (IndexMom) by given the distance to the trade’s stop loss and the big-point value
EndIf dividing the close of the GSCI index today (GSCI_Index.close) of the contract (as specified by the exchange). \\
by the close of the GSCI index n-days ago. The look-back EquityAmount = System.TradingEquity * AdjustedRiskPercent
period for the momentum calculation is denoted by the variable \\ Calculate how much to risk in currency terms (Dollars, Euros,
IndexLookback. \\ etc.) in the next trade as a function of the current available equity
EndIf and the adjusted risk per trade. \\
AdjustLongRisk = Min(Max(IndexMom / MarketMom, 0), 2) If ContractAmount = 0 Then
\\ Calculate, in percentage terms, the riks-adjustment factor Order.SetQuantity(0)
for the next long trade. \\ Else
AdjustShortRisk = Min(Max(MarketMom / IndexMom, Order.SetQuantity(EquityAmount / ContractAmount)
0), 2) \\ Set the number of contract to buy or sell, as a function of how
\\ Calculate, in percentage terms, the risk-adjustment factor much to risk of the equity and how much to risk per contract. \\
for the short long trade. \\ EndIf
EndIf

04/2011 www.tradersonline-mag.com
21
TRADERS´ insights

in handy for those desiring to with the established pros. The Scripts for adding
market their management skills to pros, too, can use techniques an dividend (interest) rate
the public. like this to both add new unique income stream to your system
The same can be said for systems to their portfolio of results
adding the possibility to base existing ones, and to limit their The dividend (interest) rate is
your entries and exits, as well as trading costs through clever loaded into memory from a
money management, on each money management and Before Test script then the daily
market’s performance relative to position sizing. earned interest is calculated and
an index or any other benchmark. added to the equity within an
For example, due to trading Scripting Section After Trading Day script. Have a
costs, the more money you have For all scripts look at Infobox 1 to see the Script
under management, the more The most important lines are type Before Test. Infobox 2 shows
your trading might become an marked in bold text and further the Script type After Trading Day.
issue of relative rebalancing explained with everything inside
between the markets rather than \\ … \\ on the line immediately Scripts for
a matter of finding good entry following. Be sure to delete the trading against an index
and exit signals. Adding a system explanation lines if you intend The GSCI index is loaded into
based on performance relative a to copy the code. Note that memory from a Before Test
benchmark can help you achieve TradingBlox works with several script, then two momentum
this while limiting the costs for types of scripts which you values are calculated within an
slippage and commission. combine to create a complete Update Indicators script, finally
In short, working with third strategy. Therefore, the header the orders are created within an
data streams is not only line, in bold text, of each script Entry Orders script.
invaluable for those private is not a part of the code, but
traders and researchers that are indicates which type of script the Scripts for using
looking to compare themself code should go into. the momentum of
an index for position sizing F7) Using an Index for Position Sizing
The momentum of the market
T5) System with a Basic Position-sizing Algorithm (see Figure 6) and the index is calculated within
a Before Instrument script, which
Modified Annual Max Total Longest also is used to calculate how
Test Ending Balance CAGR% MAR # Trades
Sharpe Sharpe Equity DD Drawdown
much to alter the original per
1 43,837,755.36 14.93% 0.33 0.65 0.52 43.3% 21.6% 2,437
cent risked per trade. A Unit Size
script then calculates the final risk
for the trade and uses that value
T6) Using an Index for Position Sizing (see Figure 7) to set the number of contracts to
buy or sell.
Modified Annual Max Total Longest Adjusting the position size for a traded market based on its strength
Test Ending Balance CAGR% MAR # Trades relative to an index can increase system performance. In this case with
Sharpe Sharpe Equity DD Drawdown
approximately 1.5 percentage points per year.
1 50,369,710.38 16.44% 0.34 0.67 0.64 48.2% 21.5% 2,437
Source: TradingBlox

04/2011 www.tradersonline-mag.com

S-ar putea să vă placă și