Forex Conversion

Top  Previous  Next



Q: How can I get accurate dollar results for markets denominated in foreign currencies?

A: In order for Mechanica to accurately compute dollar-based results for trades taken in instruments denominated in a foreign currency, set up a Forex conversion CMP[n] file (companion file) for each such instrument, and use the Symbol Manager to associate that CMP file with the correct symbol. While end of day profit/loss is calculated using the CMP record from the same date, entry day risk is calculated using the previous days CMP record, since that is the value that must be used when determining position size.

In essence, you will set up a Data Page which points to your forex data. Some forex data is reported as Date, Close. If that is the format of your price conversion data you will need to designate your data type as mutual fund which typically includes only the date and closing price. Otherwise designate the data type as Futures or Stocks. Then, tag all your forex files, run a SIG file with a single line of code to create the associated CMP file, and youre done. You can automate this process by adding a single line to a batch file, and run the batch file daily, after all your data is updated.

To set up Forex conversion data

Here is the process, step-by-step.

1If at all possible, assign a different file extension to your forex files than you do to your market data files, so that they can all reside in the same directory, but will not appear simultaneously in the Tag Symbols and Edit Symbol Properties windows (in Symbol Manager).
2Copy all your forex data files into the target data directory (or instruct your data software to deposit them there for you).
3Open Symbol Manager (from the Data menu).
4Create a Data Page called Forex. (In practice, you can use any name you like.)
5Click on the Edit Page Properties tab, and set it up as shown (above sections), pointing the actual path to your data directory. (Obviously, if your forex data has a format other than that shown, you will need to modify the setup accordingly.)
6If you just deposited your forex files into an existing directory, then press the Refresh Symbols button. This instructs the Symbol Manager to read the directory again.

7In the Data Page List, check the Data Page you just created, called Forex.

Now, click on the Edit Symbol Properties tab, and set up the following fields:

1 Pt. Move The value of a one (1) point move. Set this equal to 1.
Each Tick The smallest amount that price can change by; this value is dependent on the specific forex data file.
FxC Specifies the Forex companion field to which you will write your forex data.

Enter “1” here, to tell Mechanica to look in CMP[1] for the conversion value. (If you enter “13” Mechanica will look in CMP[13] for the conversion value).

CMP[n] parameter values are 132;

Mechanicas companion files automatically handle the task of aligning dates with the associated historical data file.

DPMult Decimal Point Multiplier. Set this equal to 1. If the decimal point in your forex data needs to be moved, please see the DPMult explanation in the previous section, Symbol Property Definitions.
ForexFileName Name of the forex companion file. Do not add the file extension.
R Use Forex Reciprocal? Y/N Reciprocal selection field; Default = N.

When set to N:        Forex price = Forex price

When set to Y:        Forex price = 1 / Forex price

See FAQs at end of this section for a complete discussion on Mechanicas internal calculations when forex data is employed.

8Click on the Tag Symbols tab in Symbol Manager, and tag all your forex files.
9Close the Symbol Manager.
10Open a new Signal Rules file, and place this line of code on the Resources page:



This code instructs Mechanica to place the closing price of the forex data into the 1st column of the CMP[n] file, when the SIG file is run.

If you already have other data stored in CMP[1], then specify a different value of [n] for the CMP files associated with foreign-denominated markets.

It is good practice to designate a single CMP file column to carry the forex data for all foreign-denominated markets, as we have done in steps 8 11.
11Run the SIG file.
12Look in the data directory containing your forex files. For each forex data file you tagged, you should now see the CMP[n] file that was just created, along with its .001 associated index file (which Mechanica creates automatically).

Heres an example:

§ forex historical data


§ CMP[n] file


§ index file


While the index file (*.001) associated with each CMP file is of no practical consequence from an end-user perspective, it must be present for the CMP file to operate correctly.

ThumbTack white

If you copy or move historical data files from one directory to another, be sure to include any CMP files, and all associated index (*.001) files. Likewise, if you delete a CMP file, be sure to delete its associated .001 file.

13The final step is to associate each foreign-denominated market with the appropriate forex CMP file.

When deciding whether or not the conversion values placed into CMP files need to be reciprocated it is important to understand which way around your foreign currency data is quoted. For example we are used to seeing USD/JPY because this is the convention in the FX market, this means that one US dollar buys x Japanese Yen. However by convention the Euro rate is quoted the other way around, i.e. EUR/USD, this means that one Euro buys x US dollars.

Because Mechanica multiplies the foreign currency point value by the exchange rate to get the equivalent US dollar value it requires data quoted in the foreign currency as in the case of EUR/USD above. If your data is quoted the other way around (e.g. USD/JPY) it must be reciprocated (R = Y).

Once youve set up all your foreign-denominated markets accordingly, specifying "Y" (Yes) in the column labeled "R" (Use reciprocal value), Mechanica will accurately compute dollar-based results for trades taken in those instruments.  Please note that this activity takes place in the Symbol Properties for your market data, not your forex data.


To ensure position sizing is handled correctly

As mentioned in the previous section, when using forex conversion data stored in a CMP file to bring price changes in foreign-denominated markets back into profit/loss in USD: While end of day profit/loss is calculated using the CMP record from the same date as the foreign-denominated historical data file, entry day risk is calculated using the previous days CMP record. That is also the value that should be referenced when using POINTVALUE to determine position size.

There are two ways to do this. The first is to place the POINTVALUE keyword in a column, and reference that columns value with a one day offset in a subsequent statement:


COL4 = ATR[21]       'measure of volatility in points

COL5 = POINTVALUE       'dollar value of 1 point move

'Yesterdays risk per contract (or share), in dollars;

'This info is passed to SIZ side. 



This example assigns yesterdays values of COL4 and COL5 to the keyword USERDEFINEDRISK, which makes this information available for later use on the SIZ side.

The second way to reference yesterdays values for position-sizing related statements is to simply use the day offset parameter of the POINTVALUE keyword:


COL4 = ATR[34]       'measure of volatility in points

'Yesterdays risk per contract (or share), in dollars;

'This info is passed to SIZ side.



There are several important points to note in these examples.

First…dont confuse the numbers in the brackets!

In the last line of code above, the bracketed [1] notation is a day offset (COL4[1]), and in this example tells Mechanica to look at the value of COL4 yesterday.

SIZING[1] simply identifies which of the eight possible SIZING[n] variables is used, so that Mechanica can keep track of the corresponding value(s).

The “n” in SIZING[n] can assume a value of 1-8, which means that Mechanica allows the simultaneous use of up to eight different SIZING variables per symbol, per day.

When trading markets denominated in your native currency, it is technically irrelevant whether you reference an instruments point value today or yesterday, since its value is stationary.

Butas noted at the end of Lesson 4anytime you pass values from the SIG side to the SIZ side using either SIZING[n] or USERDEFINEDRISK, make certain that they always reference yesterdays information in the SIG code...just like we did above, so that you do not inadvertently create a postdictive error.

Forex check list

Your Edit page properties tab points to the directory where your data actually resides. (use browse to confirm)
You have created a separate Data Page for your currency conversion run.
There you have tagged the forex symbols so that they run all together.
You get no errors when doing that.
In your forex data page Symbol Properties tab there is Nothing (not even a space) in the ForexFileName field.
In your forex data page Symbol Properties tab under the column named FxC there is "0" (zero).
In your market data page Symbol Properties tab you Do have the correct file names in the ForexFileName field.
In your market data page Symbol Properties tab under the column named FxC there is a non-zero value.  (this is n, the CMP[n] field that you populated, on your forex conversion run.)