Summary

Top  Previous  Next

 

Initial Sizing (introduction) 

nPosition sizing is a strategic trading tool that can help you enhance the performance of your system by controlling risk.
nThere are two components to position sizing in Mechanica:

n Initial Size

n Resize

nThe 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

nThe keyword STARTUPCASH specifies initial account equity for use in Portfolio Analysis.
nExample

STARTUPCASH = 25000000

 

nNote that the 1000 separator (,) is omitted.
nIf STARTUPCASH is not specified, the default is 100000 ($100,000).
nAt the start of a simulation, before the first trade is taken:

STARTUPCASH = CLOSEDEQUITY = TOTALEQUITY

 

NEWCONTRACTS / NEWSHARES

nThese keywords specify the number of contracts or shares to trade.
nThe 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.
nThe 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.
nIt is good practice to have your Initial Size code assign NEWCONTRACTS only once. Use MEMORY[n] variables to hold multiple sizing criteria values.

NEWRISK

nThe 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.

nKeyword like NEWRISK (containing the word RISK) are only meaningful when your systems 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.
nIf a value has been assigned to USERDEFINEDRISK, then NEWRISK will return that value, instead.

Initial Sizing of positions

nThe 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.

Heres one way to accomplish this with Mechanica Basic:

NEWCONTRACTS = (.01 * TOTALEQUITY) / NEWRISK

 

In the statement above, NEWRISK might carry Mechanicas 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

nAfter 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 AltP, R

nWhen the Position Sizing Rules run is complete, the Portfolio Performance window will appear.

Passing data from Signals to Sizing

nThere 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 systems 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 

nThe keyword USERDEFINEDRISK is intended for use as a global substitute for Mechanicas internal definition of risk.
nOnce 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.
nUSERDEFINEDRISK is assigned a value in the Signal Rules code; it is legal on all three SIG pages.
nWhen assigning a value of risk to USERDEFINEDRISK, it should always be expressed in dollars (using the POINTVALUE keyword).
nUnlike NEWRISK, USERDEFINEDRISK does not include slippage and commission charges (unless you add them, in your definition).
nExample:

Resources

COL4 = (CLOSE  SMA_Exit)     'actual risk, in points

COL5 = ABS[COL4]        'abs. value of risk in points

       'Yesterdays actual risk (per contract), in dollars: 

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.

nHeres another example. This code uses a measure of volatility to define risk:

Resources

COL4 = ATR[30]             'volatility risk, in points

       'Yesterdays volatility risk, in dollars: 

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, yesterdays 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] 

nSIZING[n] variables are used to pass numerical info from SIG code to SIZ code.
nOnce 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).
nThe parameter [n] in the variable SIZING[n] can assume the values 1 to 8. Thus, there are 8 different SIZING[n] variables available.
nThere 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.
nUnlike 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.

ThumbTack2

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

nX-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.
nX-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.
nIn 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.

nUse the XRAYSTARTDATE and XRAYENDATE keyword combination to instruct the Position Sizing Rules to prepare data for output to X-Ray.
nOutputting data from the SIZ file to X-Ray is processor intensive; keep the time periods you examine as short as possible.
nTo view the output, click the X-Ray Results tab in the Results Window.

Rejected trades 

nThere 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 

nWhen 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.
nTo 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.
nWhen 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.
nUsing 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.
nUsing 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

nInclude Today YES        

When Include Today = Yes, Mechanicas 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.

nInclude Today NO        

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 todays trading decisions on the various figures available as of yesterdays close.

SortList Manager

nSORTLIST[n];  n = 1 to 4
nSortList defines the order in which trades are considered for Initial Sizing.
nSortLists can be user-defined on the Resources tab.
nSortList 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.
nThe SortList Manager dialog is accessed via the Position Sizing menu.

Sysparam Manager

nSYSPARAM[n];  n = 1 to 15 
nThe System Parameters dialog is accessed via the Position Sizing menu (Sysparam Manager). It is also available as an option under the Signals menu.
nThe 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.
nSYSPARAM[n] is legal anywhere on the Initial Size or Resize pages.
nThe value for each instance of SYSPARAM[n] is assigned in the System Parameters dialog box under the Sysparam Manager option.
nThe 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.
nMechanica internally tracks and associates which SYSPARAM[n] value(s) is/are associated with the currently processing system.