Risk control: Examples

Top  Previous  Next

 

SECTORPOSITIONS

Now that weve explored the behavior of Category-related keywords using simple scenarios to introduce the concept, this section is dedicated to presenting some real-world examples.

Initial Size

STARTUPCASH = 25000000

IF SECTORPOSITIONS < 4 THEN MEMORY[1] = .02 _

ELSE MEMORY[1] = .01

 

NEWCONTRACTS = (TOTALEQUITY * MEMORY[1]) / NEWRISK

 

First, recall, that SECTORPOSITIONS returns the number of open positions currently held in the same (commodity or stock) SECTOR as the trade being presented for Initial Sizing.

Note also that the NEWCONTRACTS statement (above) appears to be of the typical fixed-fractional variety; a measure of equity is multiplied by a percentage, and divided by the dollar risk on the trade.

In this example, the fixed-fraction is “un-fixed” by use of a memory variable whose value is controlled by a Category-related keyword: the risk per trade is cut in half when SECTORPOSITIONS returns a value greater than 4.

Initial Size

STARTUPCASH = 25000000

MEMORY[1] = (.02 / SECTORPOSITIONS)

NEWCONTRACTS = (TOTALEQUITY * MEMORY[1]) / NEWRISK

 

In this example, a constant (2%) is divided by the number of SECTORPOSITIONS.

The effect is that, as more and more positions come on line (in the energy sector, for instance), each subsequent position is sized smaller and smaller.

ThumbTack white

Its good practice to have your Initial Size code assign NEWCONTRACTS / NEWSHARES only once. This is far cleaner than having separate NEWCONTRACTS statements on separate lines. For instance, the logic on the previous page could have been expressed as: 

IF SECTORPOSITIONS <= 4 THEN NEWCONTRACTS = _

(TOTALEQUITY *.02) / NEWRISK 

IF SECTORPOSITIONS > 4 THEN NEWCONTRACTS = _

(TOTALEQUITY *.01) / NEWRISK 

If you use multiple sizing criteria, it is better from a coding perspective to employ MEMORY[n] variables, or user-named variables (Lesson 3) to hold values, as we did above, and as is shown, below:

IF SECTORPOSITIONS < 4 THEN MEMORY[1] = .02 _

ELSE MEMORY[1] = .01

NEWCONTRACTS = (TOTALEQUITY * MEMORY[1]) / NEWRISK

 

#8913.siz

Initial Size

STARTUPCASH = 25000000

'risk no more than 4% of equity...

MEMORY[1] = (.04 * TOTALEQUITY) / NEWRISK

'...or 3 times volatility

MEMORY[2] = (TOTALEQUITY * .03) / (SIZING[1] * 3)

IF MEMORY[1] < MEMORY[2] THEN MEMORY[2] = MEMORY[1] 

'don't trade too much size

IF MEMORY[2] > 100 THEN MEMORY[2] = 100

NEWCONTRACTS = MEMORY[2] 

 

This example is excerpted from the sample rules file #8913.siz.

The first three statements work together to set the value of MEMORY[2] to the lesser of 4% of equity, or 3 times (3%) of volatility. If MEMORY[2] is greater than 100 contracts, then the value of MEMORY[2] is set equal to 100. And finally…

NEWCONTRACTS puts on the number of contracts specified by MEMORY[2].

 

ThumbTack white

All the keywords with the TOTAL prefix are both category-related and category-legal. Thus, they are used in the same form on the Initial Size page, as they are on the Resize page.

Examples include:

nTOTALEQUITY
nTOTALCLOSEDEQUITY
nTOTALDRAWDOWN
nTOTALRISK