Regardless of whether an integrated or component-based simulator is employed, the trading logic of the user’s system must be programmed into it using some computer language. The language used may be either a generic programming language, such as C+ + or FORTRAN, or a proprietary scripting language. Without the aid of a formal language, it would be impossible to express a system’s trading rules with the precision required for an accurate simulation. The need for programming of some kind should not be looked upon as a necessary evil. Programming can actually benefit the trader by encouraging au explicit and disciplined expression of trading ideas.
For an example of how trading logic is programmed into a simulator, consider TradeStation, a popular integrated product from Omega Research that contains an interpreter for a basic system writing language (called Easy Language) with bistorical simulation capabilities. Omega’s Easy Language is a proprietary, tradingspecific language based on Pascal (a generic programming language). What does a simple trading system look like when programmed in Easy Language? The following
code implements a simple moving-average crossover system:
( Simple moving average crossover system in Easy Language)
Inputs: k”(4) ; (length parameter )
rf (close > Average~close, Led 1 And
(Close [II c= Average ~ClOm?, Len) [II ) Then
myc ‘A”, 1 contract At Market; (buys at open of next bar)
If (Close <= Average (Close, Len), And
(Close L1, > *"verage (Close. ILen) [II, Then
Sellc"B"J 1 ContraCt At Market; (sells at open Of next bar
This system goes long one contract at tomorrow’s open when the close crosses above its moving average, and goes short one contract when the close crosses below the moving average. Each order is given a name or identifier: A for the buy: B for the sell. The length of the moving average (Len) may be set by the user or
optimized by the software.
Below is the same system programmed in Cf + using Scientific Consultant Services’ component-based C-Trader toolkit, which includes the C+ + Trading Simulator:
Except for syntax and naming conventions, the differences between the Cf + and Easy Language implementations are small. Most significant are the explicit references to the current bar (cb) and to a particular simulated trading account or simulator class instance (ts) in the C+ + implementation. In C+ +, it is possible to explicitly declare and reference any number of simulated accounts: this becomes important when working with portfolios and merasystems (systems that trade the accounts of other systems), and when developing models that incorporate an implicit walk-forward adaptation.
No comments:
Post a Comment