estadísticas darwinex

What does Enough Portfolio Diversification look like?

How much is enough portfolio diversification? Reminds me of a song.

Cue Michael Jackson music. Don’t stop ’til you get enough. Was Michael talking about portfolio diversification when he wrote that song? As much as I’d love it to be true, I don’t think it can be.

So, what might a diversified portfolio look like?

Can we have too much portfolio diversification?

What does enough portfolio diversification really look like?

So many questions. Let’s break it down into each technique we’ve looked at so far.

Diversification across asset classes

We could look to trade Forex and stocks. By trading these two different asset classes we would expect that if there were a stock market decline it wouldn’t also lead to a decline in the FX market. We could take it a step further and trade commodities as well.

Diversification within the same asset class.

We could then break down each asset class and look to trade more than one asset within each asset class. Maybe a USD denominated FX pair and a JPY cross. We could trade stocks from different sectors or industries. Then we could trade a metal like copper and a soft commodity like coffee.

Remember though, due to the random nature of price action even two uncorrelated assets will exhibit similar behaviour some of the time. This means the max diversification benefit can only be achieved a maximum of 50% of the time when diversifying across 2 assets. This does increase with the more assets you trade.

Remember these assets need to be uncorrelated.

It’s also important at this point to look at how much the volume of trades has increased. In the above example, we have 2 FX trades, 2 stock trades and 2 commodity trades. Each of those will eat into our available margin.

Diversification across timeframes.

If one of the FX trades, trades the daily timeframe we could look to run a strategy on the 15min as well. Or we could trade one of the stocks, maybe a value stock, long-term and look to hold for a period of months. Then trade a tech stock short term, perhaps some form of intraday strategy.

Diversification across trading strategies.

We’ve already partially covered this in the above example. There may have been some overlap in using the same strategy in different asset classes.

But we could also look to harness different alphas within the same asset class. This could take the form of a momentum strategy and a mean reversion strategy within the same asset class.

The above is just a hypothetical to illustrate just how flexible diversification can be and the potential power it holds. But with great power comes great responsibility. Just because we have these tools at our disposal doesn’t mean we need to use them all.

It’s going to take a vast amount of time to backtest and implement the above. It’s also going to take a sizeable chunk of capital compared to just running two or three strategies. You’ll need to decide which applications are best suited to your portfolio.

To sum up

You can’t have too much diversification from a portfolio point of view. You can however have too little time and money to implement them all successfully. We need enough portfolio diversification that we get the benefit but not so much that it requires too much effort. To reiterate.

You’ll need to decide what’s best for you.

You need to find a balance between effort and value. Only you will know what that is as we all have different circumstances.

What’s your preferred method of diversification?

Tag us on Twitter (@Darwinexchange) with your thoughts.

Brought to you by Darwinex: UK FCA Regulated Broker, Asset Manager & Trader Exchange where Traders can legally attract Investor Capital and charge Performance Fees.

Risk disclosure:

Content Disclaimer: The contents of this video (and all other videos by the presenter) are for educational purposes only, and are not to be construed as financial and/or investment advice.


Portfolio Diversification | Using Multiple Trading Strategies to Diversify your Portfolio

In the last few videos, we’ve covered a range of ways to help diversify your portfolio.


  • Diversification between asset classes
  • Diversification within the same asset class
  • Diversification across timeframes

Today we want to look at Diversification across trading strategies.

But first, let’s take a step back and think about why we want diversification in our portfolio? As traders, we need to decide how best to get to the desired outcome.

We want to maximise our returns, but also minimise our risk. If we take zero risk, it’s fair to assume we can expect zero return. We need to decide what we’re willing to risk to get the returns we want.

By using some of the techniques above we can look to fine-tune our strategy to do just that. You may have noticed in the examples in the videos, that the returns of some of the individual strategies before diversification are higher than the diversified return.

We’re not looking to chase absolute returns. That’s not the point here. In all the examples the risk-return ratio has been higher on the diversified portfolio. We’re sacrificing a little return, for less risk.

I like to think of an old gambling saying I used to hear ‘you need to bet to win money, but you need money to bet.’ If you lose 50%, you must gain 100% to break even. By fine-tuning the risk-return ratio you are better equipped to speed up recovery in the event of a large drawdown.

As traders, we must decide if the trade-off, of lower returns but a higher risk-return ratio is more appealing to us than absolute returns.

Do you think that diversification is a good idea?


Can you diversify your portfolio too much?

Two things can mitigate some of our diversification strategies. Black Swan events and market randomness. That’s why it’s so important to diversify your portfolio properly, to fill in the gaps and reduce the effect of these.

The Darwinex platform has a tonne of trading metrics that both the trader and the investor can benefit from. Even just the description from the trader can provide some good information about the strategy.

You can even import your trading history from another broker and then use our trading metrics to analyse your strategy and compare it to some of our Darwin’s.

If you aren’t yet familiar with DARWIN assets, think of them like ETFs or Mid-Cap Stocks.

Just like an ETF could track the performance of the S&P500, a DARWIN is a financial asset that tracks the performance of a trader’s underlying trading strategy, in real-time.

Darwinex manages the risk of investments in DARWIN assets independently of providers, ensuring that they carry a monthly maximum target VaR (95%) of 6.5%.

Our FCA Regulated Asset Manager charges performance fees on investor profits (20%) on a high-water mark basis, paying 75% of them to Providers.

Brought to you by Darwinex: UK FCA Regulated Broker, Asset Manager & Trader Exchange where Traders can legally attract Investor Capital and charge Performance Fees.

Risk disclosure:

Content Disclaimer: The contents of this video (and all other videos by the presenter) are for educational purposes only, and are not to be construed as financial and/or investment advice.

darwin api

Introduction to Diversification | Reducing Risk by Portfolio Trading

Welcome to our latest content series on Portfolio Diversification.

It aims to provide a higher-level view of portfolio management ideas, rather than the specific indicators highlighted in the previous series Algo Trading for a Living.

We’ll kick things off with an Introduction to Portfolio Diversification.

Diversification is a really powerful tool for reducing the overall risk of your portfolio.

We’re going to look at the fundamental reasons diversification is an important part of any portfolio level trading strategy.

Firstly, what is “diversification” anyway?

We’ve probably all heard the saying ‘Don’t put all your eggs in one basket’; this refers to diversification.

In terms of finance, Portfolio Diversification is a term used to explain how trading portfolios can be constructed in a way that reduces the overall risk of the portfolio.

Diversification also smoothens drawdowns, in a way that is difficult to achieve by trading the components of the portfolio separately.

During this series, we’re going to look at four diversification techniques; starting in this video with a simple example using two uncorrelated FX currency pairs.


Which two FX pairs do you think we’re going to use?

Before watching the video, share your thoughts in the comments section below!


In the example, we discuss how to trade these two pairs as a mini-portfolio to help reduce the overall drawdown at the portfolio level.

Diversification is a technique that contributes to lowering the overall portfolio risk enabled by the trading of multiple; uncorrelated-techniques.


Do you trade any single-asset, systematic trading strategies?

Try doing some backtests on other uncorrelated assets.

Did you see any benefit from diversification? Let us know in the comments below!


Brought to you by Darwinex: UK FCA Regulated Broker, Asset Manager & Trader Exchange where Traders can legally attract Investor Capital and charge Performance Fees.

Risk disclosure:

Content Disclaimer: The contents of this video (and all other videos by the presenter) are for educational purposes only, and are not to be construed as financial and/or investment advice.

ZeroMQ - Distributed Trading Infrastructure

ZeroMQ – How To Interface Python/R with MetaTrader 4

Zero MQ - Distributed Messaging

ZeroMQ – Distributed Messaging

In this post, we present a technique employing ZeroMQ (an Open Source, Asynchronous Messaging Library and Concurrency Framework) for building a basic – but easily extensible – high performance bridge between external (non-MQL) programming languages and MetaTrader 4.


Reasons for writing this post:

  1. Lack of comprehensive, publicly available literature about this topic on the web.
  2. Traders have traditionally relied on Winsock/WinAPI based solutions that often require revision with both Microsoft™ and MetaQuotes™ updates.
  3. Alternatives to ZeroMQ include named pipes, and approaches where filesystem-dependent functionality forms the bridge between MetaTrader and external languages.


Click below to watch the video tutorials:

1) How to Interface Python Trading Strategies with MetaTrader

2) Algorithmic Trading via ZeroMQ: Trade Execution, Reporting & Management

3) Algorithmic Trading via ZeroMQ: Subscribing to Market Data

4) Build Algorithmic Trading Strategies with Python & ZeroMQ: Part 1

5) Build Algorithmic Trading Strategies with Python & ZeroMQ: Part 2

In this blog post, we lay the foundation for a distributed trading system that will:

  1. Consist of one or more trading strategies developed outside MetaTrader 4 (non-MQL),
  2. Use MetaTrader 4 for acquiring market data, trade execution and management,
  3. Support multiple non-MQL strategies interfacing with MetaTrader 4 simultaneously,
  4. Consider each trading strategy as an independent “Client”,
  5. Consider MetaTrader 4 as the “Server”, and medium to market,
  6. Permit both Server and Clients to communicate with each other on-demand.


Infographic: ZeroMQ-Enabled Distributed Trading Infrastructure (with MetaTrader 4)

Infographic: ZeroMQ-Enabled Distributed Trading Infrastructure (with MetaTrader 4)

Why ZeroMQ?

  1. Enables programmers to connect any code to any other code, in a number of ways.
  2. Eliminates a MetaTrader user’s dependency on just MetaTrader-supported technology (features, indicators, language constructs, libraries, etc.)
  3. Traders can develop indicators and strategies in C/C#/C++, Python, R and Java (to name a few), and deploy to market via MetaTrader 4.
  4. Leverage machine learning toolkits in Python and R for complex data analysis and strategy development, while interfacing with MetaTrader 4 for trade execution and management.
  5. ZeroMQ can be used as a high-performance transport layer in sophisticated, distributed trading systems otherwise difficult to implement in MQL.
  6. Different strategy components can be built in different languages if required, and seamlessly talk to each other over TCP, in-process, inter-process or multicast protocols.
  7. Multiple communication patterns and disconnected operation.

ZeroMQ: Supported Programming Languages

Though we focus on MQL interfaced with Python & R in this post, the basic process described here can be implemented easily in other ZeroMQ-supported languages.

A comprehensive list of ZeroMQ language bindings is available here:

Zero MQ Language Bindings

Who else is using ZeroMQ?

AT&T, Cisco, EA, Los Alamos Labs, NASA, Weta Digital, Zynga, Spotify, Samsung Electronics, Microsoft, CERN and Darwinex Labs.

ZeroMQ also powers at least 5 DARWINS on The DARWIN Exchange, where the underlying trading strategies were written in C++, Python and R.

Planning Flow Control

This post is not intended to be a detailed tutorial on ZeroMQ.

However, it is still important to understand a few things about ZeroMQ that make it particularly suited to the task of connecting external programming languages such as Python and R to MetaTrader 4.

  • It supports TCP, inter-process, in-process, PGM and EPGM enabled multicast networking. We will use the TCP transport type for the implementation in this post.
  • ZeroMQ enables servers and clients to connect “to each other” on demand, particularly useful for designing distributed trading infrastructure.
  • In addition to support for asynchronous communication and disconnected operation, ZeroMQ supports several communication patterns that permit higher-level data transfer, freeing programmers to focus more on the transfer logic rather than low-level mechanisms.
  • These patterns include: Request (REQ) / Reply (REP), Publish (PUB) / Subscribe (SUB) and Push (PUSH) / Pull (PULL).


For the implementation in this blog post, we will employ ZeroMQ’s REQ/REP and PUSH/PULL communication patterns. MetaTrader 4 will be our “Server”, and trading strategies will be “Clients”.

Please note that this (MT4=Server, Strategy=Client) is not a MUST – you will need to decide on whatever flow control suits your particular needs best.

For example, you might designate a machine independent of both the trading strategy as well as MetaTrader 4, as your Server, and have Strategies and MT4 both be Clients. There are a number of ways you could achieve the end goal; carefully planning flow control will lead to efficient functionality.


Request (REQ) / Reply (REP) Pattern

The Server (MetaTrader 4 EA) will employ a TCP socket of type REP, to receive requests and send responses. A REP socket MUST always initiate a pair of calls: first, a receive, followed by a send.

The Client (Trading Strategy, e.g. in Python) will employ a TCP socket of type REQ, to send requests and receive responses. A REQ socket MUST always initiate a pair of calls too: first, a send, followed by a receive.

For this implementation, the REQ/REP pattern will enable our Clients to send commands to the MetaTrader 4 Server and receive acknowledgements of the same (e.g. OPEN/MODIFY/CLOSE trades, GET BID/ASK RATES, GET HISTORICAL PRICES, etc.)


Push (PUSH) / Pull (PULL) Pattern

The Server (MetaTrader 4 EA) will also employ a second, PUSH socket, to send additional information to Clients (Trading Strategies). This is a one-way socket, and the server will only be able to send data to this socket, without being able to receive anything back through the same socket.

The Client (Trading Strategy) will also employ a second, PULL socket, to receive additional information from the Server. This too is a one-way socket, and the client will only be able to receive data from this socket, without being able to send anything through the same socket.

The PUSH/PULL pattern enables servers and clients to exchange data with each other on-demand, but in one direction without expecting a response. This could of course be swapped out for another REQ/REP pattern, depending on your application’s flow control requirements.


In summary, for this post’s basic implementation:

  1. The Server will employ two sockets, one REP and one PUSH.
  2. Each Client will employ two sockets, one REQ and one PULL.


Infographic: What this flow control plan looks like in practice.

Infographic: ZeroMQ Process Flow Control


MetaTrader 4 Expert Advisor – Components

As displayed in the infographic above, the MT4 EA will serve as our ZeroMQ-enabled Server, with three main modules:

  1. MESSAGE ROUTER – This allows the EA to receive commands and send acknowledgements back to connecting Clients (trading strategies) through the REP socket. The Router passes all messages on to the Parser. Note: For this example, the Router doesn’t serve much purpose, but it is good practice to have this intermediary where several strategies connect to the Server (MT4) and some manner of pre-parse actions may need to be performed.
  2. MESSAGE PARSER – Messages received by this module are decomposed into actions for the next module (Interpreter & Executor).
  3. INTERPRETER & EXECUTOR – This module literally “interprets” decomposed messages and performs requested actions accordingly. For example, if the Client is requesting market data, the module gathers it from the MetaTrader 4 History DB and sends it on to the Client via the PUSH socket. Alternatively, if the Client is requesting a BUY or SELL trade be opened on e.g. the EUR/USD, it sends the trade to market and a notification of success/failure/ticket-info to the Client via the PUSH socket.

Implementation Requirements

  1. ZeroMQ – MQL4 Bindings -> Download and install the required files as instructed here:
  2. For Python -> “pyzmq” library
  3. For R -> “rzmq” library

Sample Code

To give you a head start, we’ve published a functional MetaTrader 4 Expert Advisor with the full implementation discussed in this blog post.

The MQL sample code provided is quite extensible, and can be used as a template in your efforts.

GitHub Links:

  1. DWX ZeroMQ Connector – Python & MQL


  1. The Python source code demonstrates how communication patterns are implemented.
  2. It’s fairly simple to integrate this code in your existing Python/R trading strategies.


[WEBINAR REPLAY] How to Interface Python/R Trading Strategies with MetaTrader 4

[VIDEO TUTORIAL] Algorithmic Trading via ZeroMQ: Trade Execution, Reporting & Management (Python to MetaTrader)

[VIDEO TUTORIAL] Algorithmic Trading via ZeroMQ: Subscribing to Market Data (Python to MetaTrader)

[VIDEO TUTORIAL] Build Algorithmic Trading Strategies with Python & ZeroMQ: Part 1

[VIDEO TUTORIAL] Build Algorithmic Trading Strategies with Python & ZeroMQ: Part 2

Do you have what it takes? – Join the Darwinex Trader Movement!

Darwinex - The Open Trader Exchange