USDX Dollar Index

by marekfx in category Other at 05/04/2014
Description

This indicator calculates USDX and EURX indices.

USDX index measures the performance of USD against a basket of currencies: EUR, JPY, GBP, CAD, SEK and CHF

 

Download
2948 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using System;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Internals;

// (C) 2014 marekfx

//ICE USDX contract - https://www.theice.com/publicdocs/futures_us/USDX_Futures_Contract.pdf
//ICE EURX contract - https://www.theice.com/publicdocs/rulebooks/futures_us/24_ICE_Futures_EURO_Index.pdf

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AutoRescale = true, AccessRights = AccessRights.None)]
    public class DollarIndex : Indicator
    {
        [Parameter("Show USDX", DefaultValue = true)]
        public bool ShowUSDX { get; set; }

        [Parameter("Show EURX", DefaultValue = false)]
        public bool ShowEURX { get; set; }

        [Output("USDX")]
        public IndicatorDataSeries USDX { get; set; }

        [Output("EURX")]
        public IndicatorDataSeries EURX { get; set; }

        private Index _usdxIndex;

        private Index _eurxIndex;

        protected override void Initialize()
        {
            _usdxIndex = new Index 
            {
                Name = "USDX",
                Multiplier = 50.14348112,
                Constituents = new List<Constituent> 
                {
                    //wieght is negative when USD is not the base currency (EURUSD and GBPUSD)

                    new Constituent("EURUSD", -0.576),
                    new Constituent("USDJPY", 0.136),
                    new Constituent("GBPUSD", -0.119),
                    new Constituent("USDCAD", 0.091),
                    new Constituent("USDSEK", 0.042),
                    new Constituent("USDCHF", 0.036)
                }
            };

            _eurxIndex = new Index 
            {
                Name = "EURX",
                Multiplier = 34.38805726,
                Constituents = new List<Constituent> 
                {
                    new Constituent("EURUSD", 0.3155),
                    new Constituent("EURJPY", 0.1891),
                    new Constituent("EURGBP", 0.3056),
                    new Constituent("EURSEK", 0.0785),
                    new Constituent("EURCHF", 0.1113)
                }
            };
        }

        public override void Calculate(int index)
        {
            var date = MarketSeries.OpenTime[index];

            if (ShowUSDX)
            {
                USDX[index] = CalculateIndex(_usdxIndex, date);
            }

            if (ShowEURX)
            {
                EURX[index] = CalculateIndex(_eurxIndex, date);
            }
        }

        private double CalculateIndex(Index index, DateTime date)
        {
            //index is calculated as a weighted geometric mean of its constituents' close prices

            double result = index.Multiplier;

            foreach (var weight in index.Constituents)
            {
                var series = MarketData.GetSeries(weight.Symbol, TimeFrame);
                if (series == null)
                {
                    return double.NaN;
                }
                double close = GetCloseByDate(date, series);
                result *= Math.Pow(close, weight.Weight);
            }
            return result;
        }

        private double GetCloseByDate(DateTime date, MarketSeries series)
        {
            var idx = series.OpenTime.GetIndexByExactTime(date);
            if (idx == -1)
            {
                return double.NaN;
            }
            return series.Close[idx];
        }
    }

    public class Index
    {
        public string Name { get; set; }

        /// <summary>
        /// Constant multiplier as defined in ICE contract spec
        /// </summary>
        public double Multiplier { get; set; }

        /// <summary>
        /// List of index constituents
        /// </summary>
        public List<Constituent> Constituents { get; set; }
    }

    public class Constituent
    {
        public Constituent(string symbol, double cx)
        {
            Symbol = symbol;
            Weight = cx;
        }

        public string Symbol { get; private set; }

        /// <summary>
        /// Constituent Weight
        /// </summary>
        public double Weight { get; private set; }
    }
}
Comments

Spotware Team - April 07, 2014 @ 10:52

Please use GetIndexByExactTime method instead of iterating all indexes. It will speed up your indicator.

tekASH - May 02, 2014 @ 11:47

it shows nothing after installing on cAlgo. Why? Lines dont show up.

Timmi - May 12, 2014 @ 22:45

_usdxIndex = new Index

            {

                Name = "USDX",

                Multiplier = 50.14348112,

                Constituents = new List<Constituent>

                {

                    //wieght is negative when USD is not the base currency (EURUSD and GBPUSD)

 

                    new Constituent("EURUSD", -0.576),

                    new Constituent("USDJPY", 0.136),

                    new Constituent("GBPUSD", -0.119),

                    new Constituent("USDCAD", 0.091),

                    new Constituent("USDSEK", 0.042),

                    new Constituent("USDCHF", 0.036)

                }

            };

 

            _eurxIndex = new Index

            {

                Name = "EURX",

                Multiplier = 34.38805726,

                Constituents = new List<Constituent>

                {

                    new Constituent("EURUSD", 0.3155),

                    new Constituent("EURJPY", 0.1891),

                    new Constituent("EURGBP", 0.3056),

                    new Constituent("EURSEK", 0.0785),

                    new Constituent("EURCHF", 0.1113)

                }

I would like to create my own, more extensive version, but am new at this. 

Could you please tell me how you determined these amounts? 

ie: the multipliers and the weighted amounts for each pair

thank you

 

marekfx - May 13, 2014 @ 22:33

Hi Timmi,

the weights and multipliers are taken from USDX contract specification as traded on the ICE. Weights were originally  calculated based on the trade volumes.

If you want to assign your own weights or add or remove constituents ensure that:

- sum of absolute values of weights add up to 1

- weight is negative when USD is the quote currency (as in GBPUSD)

tomolo - June 09, 2014 @ 16:54

Could I have some clarification on how the GetIndexByExactTime method works?  Im having trouble using this indicator in a robot (ie no method for Result)

jaredthirsk - May 05, 2016 @ 10:19

marekfx, I created an indicator derived on this.  May I post it and keep your copyright notice and add my own copyright notice? (I will make my additions CC0 license.)

My indicator:

  • overlay by default
  • option to inverse (very useful for gold and silver)
  • Current USDX pinned to current gold price; scroll back to see relative bullishness/bearishness of current symbol.
  • configurable amplitude magnification.  Uses exponent.  1.9 seems to match XAUUSD very closely.

Kitco has their "Did gold really go up $x.xx?", now I have my own indicator.  I was shocked how closely the price action follows the USDX most of the time.

 

bullitttrader - October 24, 2018 @ 23:43

Hello, can you update the Indicator? I think it does not work yet? I get NAN

0