This post describes how to construct a currency portfolio composed of any number of currency pairs (from those available on the Darwinex platform) and allocations, in MetaTrader.
A few common use-cases for constructing currency portfolios include:
- Studying the correlation of a trading strategy’s returns to market volatility.
- Trading currency strength instead of single pairs themselves.
- Creating custom portfolios most responsive to selected news events.
- Diversification of risk, trading with more controlled volatility.
—
While the resulting portfolio is displayed as an index similar to the one constructed for individual currencies in our previous post (Currency Index Indicator for MetaTrader 4), the key differences in this implementation are:
- Dynamic Portfolio Allocation (customize weights as you see fit)
- Dynamic Portfolio Size (select any number of assets for inclusion)
As before, MQL source code has been provided to enable traders to deploy this implementation as a custom indicator on the MetaTrader platform.
What is a Currency Portfolio?
A currency portfolio is a combination or group of currency pairs, constructed in much the same way as the currency index in our previous post.
Unlike trading one or two assets at any one time, carefully constructed portfolios of reasonably uncorrelated currency pairs enable traders to diversify risk better.
As losses on some currency pairs in the portfolio are likely to get partially (if not fully) compensated for by gains on others, overall portfolio volatility is reduced, softening the effects of sudden swings in individual portfolio components.
Portfolio Composition & Allocations
The MetaTrader indicator provided takes the following inputs:
- Comma-separated list of currency pairs to include in the portfolio.
- Comma-separated list of portfolio weights.
- Analysis Start Date to begin plotting the portfolio’s index from, based to 100.
In the indicator’s inputs, these three parameters are called “Portfolio_Assets”, “Portfolio_Weights” and “StartDate” respectively.
For example,
Inputs for an equally-weighted portfolio beginning on the 1st of January, 2017, and containing NZDCHF, GBPJPY, AUDUSD and EURCAD, where NZDCHF and EURCAD are being shorted, would look like this:
The indicator automatically calculates the allocation for each asset, based on the “Portfolio_Weights” inputs specified.
In this case, inputs of [-1, 1, 1, -1] translate to a 25% allocation to each of the 4 assets in the mix, shorting the first and last assets respectively.
Allocations can be modified conveniently.
Say for example, a user wanted to enter inputs for “Portfolio_Weights” as [-1, 2, 4, -1] -> the resultant weighted currency portfolio would then contain:
- 12.5% for -NZDCHF
- 25.0% for GBPJPY
- 50.0% for AUDUSD
- 12.5% for -EURCAD
Note: The indicator averages allocations internally to complete 100%. So if it’s more intuitive, [-1,2,4,-1] can also be specified as [-12.5,25.0,50.0,-12.5] -> the results are the same.
Portfolio Calculation Logic
Each currency portfolio P, at time t, where rates_total time periods are available for processing, can be mathematically represented as follows:
[latex]\lim_{t\rightarrow rates\_total} P(t) = P(t-1)(1 + \sum_{j=1}^{n}(\frac{C_{j,t} – C_{j,t-1}}{C_{j, t-1}})(\frac{W_j}{\sum_{k=1}^{n}(W_k)}))[/latex]
where “C” = each currency pair’s contribution, “n” = number of currency pairs/weights in the portfolio, and:
[latex]j\space\ \epsilon \space\ \{1 \space\ .. \space\ n\}[/latex]
[latex]t\space\ \epsilon \space\ \{1 \space\ .. \space\ rates\_total\}[/latex]
[latex]W\space\ \epsilon \space\ \{-\infty \rightarrow +\infty \} \space\ – \space\ user \space\ specified \space\ portfolio \space\ weights[/latex]
As with the Currency Index indicator before, the contribution of each currency pair to the portfolio value is calculated as above, indexed to base 100.00 from the chosen start date. The default start date is January 01, 2017.
MetaTrader Indicator (Source Code)
We’ve uploaded a functional MetaTrader 4 Indicator that constructs portfolios as described in this post, to our GitHub page under tools -> MQL4.
First, simply Right-Click and Save-As on the following link to save the file to your computer, and follow the instructions below them:
Click here to download DLabs_CurrencyPortfolio.mq4
Instructions:
- Launch MetaTrader 4, and open your data folder (File -> Open Data Folder)
- Copy the “DLabs_CurrencyPortfolio.mq4” into your MQL4\Indicators directory,
- Restart MetaTrader 4 and open a new chart,
- Double-click on DLabs_CurrencyPortfolio under Indicators to load the indicator on any chart.
To recap, the indicator takes the following inputs:
- Portfolio_Assets -> the currency pairs you want in the portfolio.
- Portfolio_Weights -> their respective allocations.
- StartDate -> the portfolio index’s start date.
Click OK, and the indicator will draw the selected currency portfolio in its own dedicated window.
Important Note: In order for the indicator to draw correctly and accurately, users must ensure that their History Center contains data for all currency pairs you’ve specified in Portfolio_Assets.
[Additional Resources] Constructing Currency Portfolio Indexes in MetaTrader 4
Do you have what it takes? – Join the Darwinex Trader Movement!
2 Comments
Miguel
¿Como tiene en cuenta el swap?
Es decir la curva ya ha descontado este efecto.
The Market Bull
Hi Miguel,
When constructing the curve, the indicator uses the Close price for each constituent asset in the user-specified portfolio.
These prices are then used to calculate a weighted return at each interval, all such weighted returns then being accumulated to produce the curve displayed.
This implementation can be found in the for() loop inside the following file:
https://raw.githubusercontent.com/darwinex/DarwinexLabs/master/tools/MQL4/DLabs_CurrencyPortfolio.mq4