An introduction to X-Ray
The other way to examine the values of keywords such as SIZING[n] and USERDEFINEDRISK is to use X-Ray, which is an extremely 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. In essence, X-Ray allows you to view your portfolio in layers, through multiple sizing and resizing category windows. (The concept of categories is introduced later in this chapter, and is explored further in the lesson on Resizing.)
|9||This is a continuation of the previous exercise (Lesson 5 > Size as a function..). If you have run another SIG file since then, please (re) run Lesson5c.sig again now. |
|10||Now, open the SIZ file Lesson5.siz. |
|11||Please modify the code on the Initial Size page, as shown below.|
|12||Save this file as (Save As) …Lesson5c.siz.|
XRAYSTARTDATE = 20011011
XRAYENDATE = 20011109
STARTUPCASH = 25000000
NEWCONTRACTS = (.01 * TOTALEQUITY) / SIZING
MEMORY = NEWRISK
Before running the Position Sizing Rules, let’s discuss the modifications we just made, which were undertaken for the purpose of demonstrating how to examine the values of SIZING and USERDEFINEDRISK in X-Ray:
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 is used above, or… |
|n||reference the keyword by assigning it's value to a memory variable, like we’ve done with the reference to NEWRISK|
If we wanted to examine the value of USERDEFINEDRISK, why then, did we instead reference NEWRISK?
USERDEFINEDRISK is not legal on either the Initial Size page or the Resize page, and as discussed previously, the value of USERDEFINEDRISK flows through to all the RISK-related keywords, including NEWRISK.
If you substitute USERDEFINEDRISK for NEWRISK in the SIZ file above, you will get the following error message:
Syntax Error in Line 9: Tab: 4 'USERDEFINEDRISK’ Unknown word, undefined variable or Illegal Usage on This Page.
|•||Go ahead and try it. Mechanica will generate the error message shown.|
|13||Now, run the Position Sizing Rules.|
|14||Click on the X-Ray Results tab in the Results Window (as shown below).|
|•||Note that the dates falling within the range defined by the XRAYSTARTDATE and XRAYENDATE keywords appear on the far left, under column A.|
|15||Click the drop-down list box in the first cell under column B. (It says, Select keyword). Select the option SIZING.|
|16||Then, click the drop-down list box in the second cell under column B, and select S JY_REV s3. This nomenclature means that you are choosing to view all the Short trades (that occur during the specified date range), for JY_REV, which is the Pinnacle data file name (and subsequently the symbol name) for Japanese Yen), in system 3. You can verify that this is the case, by examining these dates in the Grid (blue Signal Results tab).|
|•||If the date range assigned to the XRAYSTARTDATE and XRAYENDATE keywords had been of a sufficient duration, then you would have been presented with the option of viewing either all the Japanese Yen short trades that occurred in system 3 during that time, denoted by S JY_REV s3, as well as all the long trades, which are denoted by L JY_REV s3, as shown below.|
|17||Now, click any cell in column C, and Mechanica will present you with the next drop-down list box. This time select NEWRISK, then select S JY_REV s3.|
|18||Notice that X-Ray presents the keyword TOTALEQUITY as a choice; this is because it is used explicitly in the sizing statement. Click any cell in column D; select TOTALEQUITY, then select 1 Per day.|
|•||Please note the “I” that appears as the first character in row 1 of columns B, C, and D above (I – NEWRISK, for example). This represents the origin of the keyword, which in this case is the Initial Size page. (Keywords that appear in code on the Resizing page are preceded by an “R” …R – POSITIONS, for example).|
|•||Please refer to the graphic above. The trade we’re examining enters on the open, on 20011012 (November 12, 2001). The value of SIZING on that day is $850; the value of NEWRISK is $2108, and TOTALEQUITY is 213377125 ($213,377,125.) |
|•||Now, click the Daily Detail tab in the Portfolio Performance window. Scroll down until you find the date 20011012 (or press the tab key, then press Ctrl + down arrow, and scroll up a little, to the date 20011012), as shown: |
|•||In the Open Positions column for that date, you will see JY_REVS2510s3. This notation means:|
Pinnacle data file name (and symbol name) for Japanese Yen
Short 2510 contracts
System 3 (SYSTEM = 3 assigned on Resource page of SIG file)
|•||Note that the TOTALEQUITY figure displayed in X-Ray for the trade entry date of 20011012 is $213,377,125, yet the TOTALEQUITY figure displayed in the Daily Detail grid for that same date is $213,251,625 (see highlighted cells in graphic above).|
|•||Why the apparent discrepancy? Because X-Ray displays sizing related information, and the TOTALEQUITY figure for the night of 20011011. $213,377,125 is the amount that Mechanica used to size the position that entered on the open of the next trading day, 20011012. |
|•||It’s easy to understand how Mechanica arrives at 2510 contracts for this position. Let’s look at the sizing statement from the Initial Size page:|
NEWCONTRACTS = (.01 * TOTALEQUITY) / SIZING
From the results shown in X-Ray:
NEWCONTRACTS = (.01 * $213,377,125) / $850
NEWCONTRACTS = $2,133,771.25 / $850
NEWCONTRACTS = 2510.32
When sizing positions, Mechanica rounds down to the nearest whole number (both for stocks or for futures), and puts on 2510 contracts.
X-Ray is designed so that each Sizing-related keyword or variable referenced within your Position Sizing Rules can be associated with a date, and clearly displayed and examined in the context of the market position for that date.
Remember, in order for a keyword to be eligible for display in X-Ray, it must be explicitly referenced in your SIZ code.
We’ll revisit the topic of X-Ray more extensively in the lesson on Resizing. For now, it’s sufficient to understand that X-Ray is to Mechanica’s SIZ side, what the Grid is to the SIG side.
The XRAYSTARTDATE and XRAYENDATE keywords instruct the Position Sizing Rules to prepare data for output to X-Ray over the specified date range, and this increases processing time. The increase in processing time is proportional to the date range specified by this keyword combination.
If you have specified a large date range, the additional processing time can become significant. If at all possible, keep the date range small.
The Initial Size and Resize code tracks a lot of different values, and when working with a large number of symbols, an 'Out of Memory’ error may occur. Should this happen, please (a) use a smaller date range, and (b) shut down other programs before re-running the Position Sizing rules.