Initial Sizing (introduction)
n | Position sizing is a strategic trading tool that can help you enhance the performance of your system by controlling risk. |
n | There are two components to position sizing in Mechanica: |
n Initial Size
n Resize
n | The position sizing logic in Mechanica is largely independent of the Signal Rules logic. Thus, you can maintain separate Sizing files (*.siz) that contain only position sizing logic. This leaves you free to experiment with Initial Sizing and Resizing strategies, without having to re-run the Signal Rules each time. |
STARTUPCASH
n | The keyword STARTUPCASH specifies initial account equity for use in Portfolio Analysis. |
STARTUPCASH = 25000000
n | Note that the 1000 separator (,) is omitted. |
n | If STARTUPCASH is not specified, the default is 100000 ($100,000). |
n | At the start of a simulation, before the first trade is taken: |
STARTUPCASH = CLOSEDEQUITY = TOTALEQUITY
NEWCONTRACTS / NEWSHARES
n | These keywords specify the number of contracts or shares to trade. |
n | The two keywords are identical in behavior; you can use either. NEWSHARES was added as a convenience for stock traders, many of whom found the concept of dealing with “contracts,” and the keyword NEWCONTRACTS, unfamiliar. |
n | The keyword NEWCONTRACTS automatically rounds down to the nearest integer. For instance, if an initial sizing statement specified 11.83 Swiss Franc contracts, Mechanica would put on 11 contracts. |
n | It is good practice to have your Initial Size code assign NEWCONTRACTS only once. Use MEMORY[n] variables to hold multiple sizing criteria values. |
NEWRISK
n | The keyword NEWRISK is a function that returns the risk of the trade being presented for initial sizing, in dollars per contract, or dollars per share: |
n When the system enters on a stop, NEWRISK is defined internally as the dollar value of the difference between the entry price today and the exit stop today.
n In the case of a system that enters on the open, NEWRISK is defined internally as the dollar value of the difference between the closing price yesterday, and the exit stop today.
n | Keyword like NEWRISK (containing the word RISK) are only meaningful when your system’s exits employ the BUYSTOP and SELLSTOP keywords – or – when risk has been user-defined, using the keyword USERDEFINEDRISK. NEWRISK includes slippage and commission, unless USERDEFINEDRISK has been assigned a value; the value of USERDEFINEDRISK flows through to NEWRISK, and USERDEFINEDRISK excludes slippage and commission. |
n | If a value has been assigned to USERDEFINEDRISK, then NEWRISK will return that value, instead. |
Initial Sizing of positions
n | The general form of the statement that many traders use to size positions as a function of equity and initial trade risk is: |
No. Contracts = (% of Equity) / ($Risk of new trade)
Statements of this form are often referred to as fixed-fractional position sizing, which means simply that a fixed fraction of equity is risked on each trade.
Here’s one way to accomplish this with Mechanica Basic:
NEWCONTRACTS = (.01 * TOTALEQUITY) / NEWRISK
In the statement above, NEWRISK might carry Mechanica’s internal definition of risk, which is a measure of actual trade risk, or it might carry a measure of volatility (risk), the value of which has been passed to NEWRISK by USERDEFINEDRISK. Or, it might be replaced entirely using the variable SIZING[n], which may carry yet a third measure of risk.
To run the Position Sizing Rules
n | After running the Signal Rules: |
n Click the Run arrow icon on the Position Sizing toolbar,
n Choose Run Position Sizing Rules (Position Sizing menu), or
n Press the shortcut keystroke Alt–P, R
n | When the Position Sizing Rules run is complete, the Portfolio Performance window will appear. |
Passing data from Signals to Sizing
n | There are four (4) keywords in the Mechanica Basic language specifically designed to communicate sizing-related data from the Signals side to the Position Sizing side. All three allow you to store numerical values created during Signal Rules operations (when Mechanica is busy processing your system’s trades), that can later be referenced by the Position Sizing rules. |
They are:
n SYSTEM
n USERDEFINEDRISK
n SIZING[n]
n SORTLIST[n]
The SYSTEM keyword has already been covered numerous times in the documentation. USERDEFINEDRISK and SIZING are discussed below.
USERDEFINEDRISK
n | The keyword USERDEFINEDRISK is intended for use as a global substitute for Mechanica’s internal definition of risk. |
n | Once defined on the Signals side, the value assigned to USERDEFINEDRISK flows through to all keywords on the Sizing side that contain the word RISK, including the keyword NEWRISK. |
n | USERDEFINEDRISK is assigned a value in the Signal Rules code; it is legal on all three SIG pages. |
n | When assigning a value of risk to USERDEFINEDRISK, it should always be expressed in dollars (using the POINTVALUE keyword). |
n | Unlike NEWRISK, USERDEFINEDRISK does not include slippage and commission charges (unless you add them, in your definition). |
Resources
COL4 = (CLOSE – SMA_Exit)
COL5 = ABS[COL4]
USERDEFINEDRISK = COL5[1] * POINTVALUE[1]
COL4 defines the risk of the trade being presented for initial sizing, in points. SMA_Exit is a grid-column alias.
It is non-sensical for risk to have a negative value, so COL5 takes the absolute value of COL4.
In the last statement, yesterday's value of COL5 is used in order to prevent a postdictive error. That value (in points) is multiplied by the POINTVALUE to obtain the risk in dollars. That (dollar) value is ultimately assigned to USERDEFINEDRISK, and will be used later, when the trade is presented for Initial Sizing.
In the actual sizing statement on the Initial Size page, NEWRISK is used to reference the value assigned to USERDEFINEDRISK on the Signals side.
n | Here’s another example. This code uses a measure of volatility to define risk: |
Resources
COL4 = ATR[30]
USERDEFINEDRISK = COL4[1] * POINTVALUE[1]
ATR[n] is a built-in function that returns a measure of volatility, which many traders use as a proxy for actual risk. Here, COL4 uses a 30-day ATR to define the risk, in points, of the trade that will later be presented for sizing. The formula for ATR[n] already incorporates absolute value, so there is no need to take that additional step, as was done in the previous example.
In the last statement, yesterday’s value of COL4 is used in order to prevent a postdictive error; it is multiplied by the point value of the trade that will later be presented for sizing, in order to obtain the risk in dollars, and that value is ultimately assigned to USERDEFINEDRISK.
In the actual sizing statement on the Initial Size page, NEWRISK is used to reference the value assigned to USERDEFINEDRISK on the Signals side.
SIZING[n]
n | SIZING[n] variables are used to pass numerical info from SIG code to SIZ code. |
n | Once SIZING[n] has been assigned a value on the Signals side, that value is later available for use in code statements on the Initial Size and Resize tab (pages). |
n | The parameter [n] in the variable SIZING[n] can assume the values 1 to 8. Thus, there are 8 different SIZING[n] variables available. |
n | There are many circumstance where you will use multiple SIZING[n] variables. One example of this is when you define a custom measure of risk with SIZING[1], and use SIZING[2] to pass RANK information from the SIG side to the SIZ side. |
n | Unlike USERDEFINEDRISK, whose value flows through to all keywords containing the word RISK, values assigned to the SIZING[n] variable do not affect the value of any other keyword. |
|
Important
Anytime you pass values from the SIG side to the SIZ side using either SIZING[n] or USERDEFINEDRISK, be sure that they always reference yesterday's information in the SIG code, so that you do not inadvertently create a postdictive error.
|
Introduction to X-Ray
n | X-Ray is a flexible tracing tool that allows you to drill down into the multitude of equity and risk figures that influence your Position Sizing and Resizing operations. X-Ray allows you to view your portfolio in layers, through multiple sizing and resizing Category windows. |
n | X-Ray is designed so that each Sizing keyword or user-named variable referenced within your Position Sizing Rules is automatically associated with a date, and clearly displayed and examined in the context of the market position for that date. |
n | In order for a keyword to be eligible for display in X-Ray, it must be referenced in your SIZ code. That means that you can either: |
n use the keyword in a valid statement, as SIZING[1] is used above, or…
n assign the keyword to a memory variable, so that the keyword is referenced.
n | Use the XRAYSTARTDATE and XRAYENDATE keyword combination to instruct the Position Sizing Rules to prepare data for output to X-Ray. |
n | Outputting data from the SIZ file to X-Ray is processor intensive; keep the time periods you examine as short as possible. |
n | To view the output, click the X-Ray Results tab in the Results Window. |
Rejected trades
n | There are two reasons trades are being rejected during Initial Sizing. Either (a) your system has insufficient capital to accommodate the specified risk per trade, or (b) you have specified too little risk per trade for the capital your system is currently trading. |
STARTDATE
n | When used on the Initial Size page of a SIZ file, the STARTDATE command allows you to slam on all the portfolio's currently open positions on a certain day. |
n | To accommodate the sizing of these slammed on positions, Mechanica looks back in time and stores the dollar risk at the inception of the trade (the initial risk), even if trade entry occurred months prior to the STARTDATE, and returns that initial risk figure via the functions NEWRISK and USERDEFINEDRISK. |
n | When used on the Resources page of a SIG file, STARTDATE behaves in an entirely different manner: It simply specifies the date that Mechanica starts reading data. |
n | Using STARTDATE in a SIG file cuts down on processing time if your data goes back in time significantly more years than you want to test. |
n | Using STARTDATE in a SIZ file slams on all trades in progress as of that date, and allows you to avoid the perils of under-diversification as your portfolio gets up to speed. |
Include Today
When Include Today = Yes, Mechanica’s keyword return values are updated across all Category-related keywords, each time a position is entered during the course of the trading day. This is a postdictive process.
In this mode, risk calculations are updated once, at the end of each trading day. This mode is for use by end-of-day traders, who base all of today’s trading decisions on the various figures available as of yesterday’s close.
SortList Manager
n | SortList defines the order in which trades are considered for Initial Sizing. |
n | SortLists can be user-defined on the Resources tab. |
n | SortList values are created when the Signal Rules are run; these values are later used by Initial Size and Resize statements when the Position Sizing rules are run. |
n | The SortList Manager dialog is accessed via the Position Sizing menu. |
Sysparam Manager
n | SYSPARAM[n]; n = 1 to 15 |
n | The System Parameters dialog is accessed via the Position Sizing menu (Sysparam Manager). It is also available as an option under the Signals menu. |
n | The SYSPARAM[n] keyword associates a specific value with a specific system number; It is in essence a function that returns the value entered in the System Parameters table, and it internally tracks which system it is associated with. |
n | SYSPARAM[n] is legal anywhere on the Initial Size or Resize pages. |
n | The value for each instance of SYSPARAM[n] is assigned in the System Parameters dialog box under the Sysparam Manager option. |
n | The System Parameters dialog box will accommodate multiple SYSPARAM[n] values for a single system, and each system can have up to 15 unique SYSPARAM[n] variables. |
n | Mechanica internally tracks and associates which SYSPARAM[n] value(s) is/are associated with the currently processing system. |
|