Risk control: Sets and categories

Top  Previous  Next

 

Introduction        

Through the years, weve been exposed to all sorts of common wisdom that advises us, for example, to never risk more than X percent of equity on a single trade, or face the risk of being labeled a gunslinger.

Others warn us to never risk more than Y percent of an account on currently open trades (cumulative open risk).

Will sizing trades at 2% of equity (initial risk) on 16 markets, produce results that are equally volatile as sizing trades at 1% of equity on a 32 market portfolio? And how do you measure risk?

Ed Seykota and Dave Druz state that, “In portfolio management, we call the distributed bet size the heat of the portfolio. A diversified portfolio risking 2% on each of five instruments has a total heat of 10%, as does a portfolio risking 5% on each of two instruments.” Determining Optimal Risk. Stocks & Commodities V. 11:3 (122-124).

Are they right? Probably so!

But when its your fund or your reputation on the line, what anyone else thinks should only motivate you to conduct your own research.

As Mechanica author Bob Spear wrote some time ago about Mechanicas predecessor, “it is the result of the years I spent seeking answers to mostly the wrong questions.” He continues:

Users find that they are able to make great things happen when they can visualize, model, or simulate a complete trading plan, and my job was to design the software to be as non-restrictive in this process as I could possibly make it.

Of the many questions I asked, precious few proved to be good ones. If you are like me though, once you do find a good question, that's just the beginning of a series of questions: Is it better to trade one market with one system…or a lot of markets with one system? Or a lot of markets with a lot of systems?

Isn't Risk Control really just Profit Control? What sort of day-to-day ride can I expect?
…If I can smooth out my equity curve, then can I turn up the heat a little and not pay for it with larger drawdowns? Will I get into trouble having half my equity at risk today? Is it a bad idea to have a lot of my money at risk in the grains? Or should I spread out more evenly into different sectors?

These are exactly the kinds of scenarios that Mechanica is uniquely designed to allow you to test. 

 

Understanding Categories and Sets

Overview

As we mentioned at the top of this lesson, position sizing is a strategic trading tool that can help you enhance the performance of your system by controlling risk; dynamically managing risk via conditional sizing and resizing operations is exactly what Mechanica is designed to do.

Mechanica allows you to view your portfolio in layers, through multiple sizing and resizing category windows, so that you can methodically control risk at every level of every system, or across all systems universally.

Mechanica Basic allows you to discretely address each of the various interrelated risk components in a portfolio, as well as the relative importance of each individual risk component to the whole. Once these risk components and their relationships have been defined and organized, you can begin to manipulate them to accomplish your goals.

We started by identifying the logical relationships that naturally exist among the various components in a portfolio. Then, we broke these relationships down into categories that view risk from the perspective of sets.

With regard to Initial Sizing, Mechanica allows you to accept or reject new trades, and determine the number of contracts or shares to put on, based on any combination of the following metrics:

nstart up capital
nclosed, open and total equity
ntotal drawdown
nmarket volatility
nactual market risk
nthe additional risk incurred if a position under consideration were executed
nvarious views of portfolio risk (categories and sets)

It is this last item that well be exploring in detail in the following pages.

Before getting started, there is an important distinction to make.

On the Initial Size page, the work we do (the action we take) is applied to a single new position, and by extension to the set(s) into which it seeks membership. By referencing set-level properties, we can allow or disallow membership in a set, and determine the size at which a new trade is to be placed, if indeed, membership is allowed.

On the Resize page, we reference various properties to make decisions about how to modulate the size of positions.

In both instances, the goal is to control risk and reward by controlling position size.

Keywords

To initialize the Position Category in Mechanica, simply type in POSITION on the Resize page, and precede it with the tilde character (“~”). Once initialized in this manner, Mechanica assumes that all code that follows is specific to  positions. There are various category-legal keywords that are designed for use following a Category designation.

They are:

CONTRACTS / SHARES

EQUITY

RISK

TOTAL-prefix words like TOTALRISK

 

These category-legal keywords return values that you will reference when developing risk-control strategies. They return values for the specific position which Mechanica is currently processing.

Here is an example of the correct syntax as it would be employed on the Resize page:

~POSITION    ' initializes POSITION category

IF RISK > TOTALRISK * .02 THEN MULTIPLIER = .75  ' resize statement

 

In pseudo-code this means:

IF PositionRISK > TOTALRISK * .02 THEN MULTIPLIER = .75 

 

 

Controlling risk with Category-related keywords

This exercise is designed to increase your understanding of category-related keywords, and at the same time,  expand on the differences between the two modes of Include Today (Yes / No). 

Light Bulb

Include Today is designed to emulate how a trader who watches the markets during the session might size trades based on knowledge of trades that were previously entered during the same session.  As such, this is a postdictive process. So INCLUDETODAY = TRUE and Include Today - Yes (Position Sizing menu) should be used with caution.  Why?  Though this works fine for historical simulation, when it comes time to create actual trading orders, Mechanica will have no way of knowing which trades will actually be entered (or in what order) during the new session for which orders are being created.  So the sizes reported for new orders can include no information about other trades.  The assumption is that you are not putting orders on the floor and you are managing them and sizing them yourself as they come up during the session.

Include Today - No, INCLUDETODAY = FALSE is the default.

Include Today only affects the behavior of category-related keywords.

We suggest that if you use Include Today - Yes in your historical testing and any of this is unclear, you should probably turn it off for OM operations:

Include Today - No in the Position Sizing menu

-OR-

INCLUDETODAY = FALSE in your SIZ code.

In the following example, a fixed number of contracts is traded. While this is not reflective of real world trading, it keeps things simple and makes the concepts easier to grasp.

1Open a new Signal Rules file (click the white page icon on the Signals toolbar).
2Save this file as Lesson5d.sig.
3Type in the code shown:

Resources

SYSTEM = 5

STARTDATE = 20010101

COL1 = OPEN

COL2 = CLOSE

 

Trade Entry

IF DATE = 20011211 THEN BUYOPEN  

 

Trade in Progress & Exit

IF DATE = 20011217 THEN SELLCLOSE

 

4Save your work.
5Choose Symbol Manager from the Data menu.
6Make sure that the Pinnacle_Futures Data Page is still selected. Tag it, if it is not, and untag any other Data Pages that are currently tagged.
7Under the Tag Symbols tab, press Unselect All, to untag any other Symbols that may be currently tagged.
8Then, tag the following symbols:
nAD_REV

Australian Dollar

nBP_B_REV

British Pound

nCD_REV        

Canadian Dollar

nJY_REV        

Japanese Yen

nSF_REV

Swiss Franc

9Before closing the Symbol Manager, click on the Edit Symbol Properties tab.
While it may be obvious that the selected symbols are all currency futures (Australian Dollar, British Pound, Canadian Dollar, Japanese Yen, and Swiss Franc), for this exercise…it is important to verify that they all share the identical sector designation ( in this case, “4” ), as shown:                

Note  The setup of historical data will be one of the most time consuming and important tasks you will perform. While the Pinnacle Data that ships with Mechanica has already been set up for you, but regardless, its always a good idea to double-check everything.
10Now, close the Symbol Manager.
11Run the system.
12Please look at the Grid.
13Using the drop-down list box and edit-text box (top left), add the following Grid-column aliases:
nCol1 = Open_
nCol2 = Close_
As discussed in Lesson 3, it is illegal to use Mechanica Basic keywords as aliases, so be certain that you add the trailing underscore.
14Scroll to the bottom of the Grid. This is what you should see:

Discussion

This is the first time weve run Signal Rules on multiple symbols. Note that Mechanica processes multiple symbols in alphabetical order, and displays in the Grid the data for the last symbol (instrument) processed. In this case, that is SF_REV. Note that the symbol for this instrument is displayed on the Signal Results tab (red circle).
Adding the two Grid-column aliases (Open_, Close_), makes it easy to verify that our trades entered and exited at the correct prices, on the specified dates.
15Open a new Position Sizing Rules file (click the Create New icon on the Position Sizing toolbar).
16Save this file as Lesson5d.siz.
17Type in the code shown, and save your work.

Initial Size

INCLUDETODAY = TRUE 

XRAYSTARTDATE = 20011211

XRAYENDATE = 20011217

STARTUPCASH = 25000000

IF SECTORPOSITIONS < 3 THEN NEWCONTRACTS = 8

 

Discussion

Before running the Position Sizing Rules, lets discuss the code: The first line sets the INCLUDETODAY mode to TRUE. This accomplishes the same thing as selecting Include Today YES under the Position Sizing menu. Since this feature can significantly alter the behavior of the Initial Size rules, it is better to place it in the code, where it will serve as a reminder of which mode you are operating in.  

We instructed the Signal Rules to enter five trades on the same day, 20011211 (Dec 11, 2001), and exit those same five trades, five days later, on 20011217. Note that the XRAYSTARTDATE / XRAYENDATE keyword combination brackets that same period of time.
STARTUPCASH - starting account balance.
Next, the NEWCONTRACTS statement:

IF SECTORPOSITIONS < 3 THEN NEWCONTRACTS = 8

 

The statement above is logically equivalent to:

IF SECTORPOSITIONS < 3 THEN NEWCONTRACTS = 8 ELSE _

NEWCONTRACTS = 0 

 

Please note the underscore at the end of the line. It is simply used as a line continuation character in this documentation to indicate that this code belongs all on a single line in your program.

ThumbTack white

1.Since many users employ multiple systems, each trading a unique basket of symbols (instruments), it is important to note that the term “portfolio,” when used in a sizing or resizing context, refers to all instruments traded by all systems under consideration.
2.If only a single system is active, then the term “portfolio” is synonymous with the basket of instruments or symbols traded by that one system.

       The sizing code we typed in for Lesson5d.siz appears below for the sake of convenience in discussion:

Initial Size

INCLUDETODAY = TRUE

XRAYSTARTDATE = 20011211

XRAYENDATE = 20011217

STARTUPCASH = 25000000

IF SECTORPOSITIONS < 3 THEN NEWCONTRACTS = 8

 

Recall that we (a) instructed the Signal Rules to enter five trades on the same day, and that (b) all five symbols were Currency futures.

Now, please look at the statement containing the category-related keyword SECTORPOSITIONS. This keyword returns the number of open positions currently held in the same sector as the trade currently under consideration for Initial Sizing. In plain English, it means: If the number of positions in the Currency SECTOR is less than three, then NEWCONTRACTS = 8, else NEWCONTRACTS = 0.

18Now, run the Position Sizing Rules.

ThumbTack white

Since multiple trades are being presented for sizing all on the same day, Mechanica must have a rule for the order in which they are processed, and it does so according to the SortList selected in the Initial Sizing section of the SortList Manager (Position Sizing menu, Sortlist Manager). We used the default Initial Sizing SortList for this example, which processes trades in alphabetical order, by system. So given the logic above, and knowledge of the processing order, AD, BP and CD will be sized at 8 contracts each; JY and SF will be sized at 0 contracts each.

In order to see what actually happened, click the Daily Detail tab under the Portfolio Performance window, and look in the Open Positions column. This is what you should see:

In the Open Positions column under the Daily Detail tab, the first position you will see is AD_REVL8s5. This notation means:

AD_REV

Symbol name (Pinnacle data file name) for Australian Dollar

L

Trade in the long direction

8

Position size; eight (8) contracts

s5

System 5 (SYSTEM = 5 assigned on Resource page of SIG file)

As you can see in the screen shot above, the first three positions (AD, BP and CD), were sized at eight (8) contracts each, while the remaining two positions (JY and SF) were sized at zero (0) contracts each, as the logic in the NEWCONTRACTS statement specified.

INCLUDETODAY = TRUE

IF SECTORPOSITIONS < 3 THEN NEWCONTRACTS = 8

 

Had the INCLUDETODAY statement been set to False instead of True, the outcome would have been quite different.  

The positions were sized as they were, because with INCLUDETODAY set to True, the values for all category-related keywords are updated throughout the trading day, each time a position was entered. So once the Canadian Dollar position was put on, the SECTORPOSITIONS condition became false, and subsequent positions were sized at zero (0) contracts.

19Now, in the file Lesson5d.siz, set INCLUDETODAY to False, as shown below,

INCLUDETODAY = FALSE

IF SECTORPOSITIONS < 3 THEN NEWCONTRACTS = 8

 

20Run the Position Sizing Rules again.
This is what you should see (Portfolio Performance window):

All five trades were sized at eight (8) contracts when INCLUDETODAY was changed from True to False. In this mode, Mechanica looks at the values of all category-related keywords as of yesterday's close, and as of the entry date of our five (5) trades, yesterday's value of SECTORPOSITIONS was zero (0), and the implied limiting condition (IF SECTORPOSITIONS => 3) didnt become true until the close of the entry day, after all positions had already been sized.  

IF SECTORPOSITIONS < 3 THEN NEWCONTRACTS = 8

 

Given the logic of the NEWCONTRACTS statement (above)…

If, for instance, on the day before the entry day of our five Currency trades, the system(s) had been carrying three existing Currency tradesi.e. three trades in the Currencies SECTORthen the five Currency trades that entered on 20011211 would have been sized at zero (0) contracts.

As another example, if on the day before the entry day of our five Currency trades, the system(s) had been carrying two existing trades in the Currencies SECTOR, then the five Currency trades that entered on 20011211 would still have been sized at eight (8) contracts, because the implied limiting condition (IF SECTORPOSITIONS => 3) didnt become true until the close of the entry day…because as of the close last night, there were only two positions open, and that is all we are allowed to see (with Include Today = False).

21This has been a long exercise, so if youve run another SIG file in the interim, or changed symbols, then go into the Symbol Manager (Data menu), and make certain that the original five symbols are still tagged:
nAD_REV
nBP_B_REV
nCD_REV
nJY_REV
nSF_REV
22Run the Signal Rules file Lesson5d.sig.
23Re-open the Symbol Manager (Data menu), ensure that the Pinnacle_Futures Data Page is still tagged and selected, untag any other Data Pages that are currently tagged, and click Unselect All.
24Now, tag the following symbols:
nFX_REV        Euro currency
nMP_REV        Mexican Peso
25Close the Symbol Manager.
26Turn Simultest On (Signals menu).
27Modify the Resources and Trade Entry page in the file Lesson5d.sig, as shown:

Resources

'SYSTEM = 5

SYSTEM = 6        

STARTDATE = 20010101

COL1 = OPEN

COL2 = CLOSE

 

Trade Entry

'IF DATE = 20011211 THEN BUYOPEN

IF DATE = 20011210 THEN BUYOPEN        

 

Trade in Progress & Exit

IF DATE = 20011217 THEN SELLCLOSE

 

28Run the Signal Rules.
29Press Yes, when prompted by the message “Continue with Simultest?”
30Now, in Lesson5d.siz, set the INCLUDETODAY statement back to True.
31Run the Position Sizing Rules.
This is what you should see (Portfolio Performance window):

The symbols FX (Euro currency) and MP (Mexican Peso) entered on 20011210, as specified in the most recent modifications to the Signal Rules, which were run in Simultest mode. Simultest mode allowed us to add these two (2) new currency trades to the existing five (5) trades. Note that the two new trades (green highlight) carry the system designation s6.
Please continue referring to the screen shot on the previous page.
After reviewing the logic behind the code on the Initial Size page, it should be clear what happened, and why.

INCLUDETODAY = TRUE

'     :            :     <- snip

IF SECTORPOSITIONS < 3 THEN NEWCONTRACTS = 8

As of the beginning of the trading day on 20011210, SECTORPOSITIONS returned a value of 0, and FX_REV and MP_REV were sized at 8 contracts each.

At the beginning of the next trading day (20011211) the Position Sizing Rules began sizing the original five (5) currency trades (and does so in alphabetical order, according to the default SortList). AD_REV (the Australian Dollar) was first up, and was sized at 8 contracts, because SECTORPOSITIONS < 3.

Remember when INCLUDETODAY is set to True, the values for all Category-related keywords are updated throughout the trading day, each time a position is entered. Thus, after the Australian Dollar position was put on, the SECTORPOSITIONS condition became false (SECTORPOSITIONS was no longer less than three), and the subsequent trades from System 5 were sized at zero (0) contracts.

 

We introduced the concept of Simultest in this exercise without a lot of explanation, but an entire lesson is dedicated to this important topic Critical Concept: Simultest.

In essence, Simultest simply keeps previous trades from being overwritten, so that multiple Signal Rules files can be run, one after the other, with each systems trades stored in a composite trade database, along with a unique system identifier. These trades can later be accessed by the Position Sizing Rules, with full knowledge of which trades were generated by which system.

Of course, once the Signal Rules have been run and trades have been generated for a systemor for multiple systems, using Simultest mode as we did hereyou are free to experiment with various Initial Sizing and Resizing strategies, without having to re-run the Signal Rules.

At this point, it is sufficient to remember that:

With Simultest Off, the trades in the trade database are overwritten every time a new Signal Rules file is run.
With Simultest On, Mechanica keeps accumulating trades in the trade database until you (a) stop running new Signal Rules files, or (b) until you turn Simultest Off.