Jocimar Lopes
Jocimar Lopes
developer en free worker
Jocimar Lopes
Ha publicado el artículo Statistical Arbitrage Through Cointegrated Stocks (Part 9): Backtesting Portfolio Weights Updates
Statistical Arbitrage Through Cointegrated Stocks (Part 9): Backtesting Portfolio Weights Updates

This article describes the use of CSV files for backtesting portfolio weights updates in a mean-reversion-based strategy that uses statistical arbitrage through cointegrated stocks. It goes from feeding the database with the results of a Rolling Windows Eigenvector Comparison (RWEC) to comparing the backtest reports. In the meantime, the article details the role of each RWEC parameter and its impact in the overall backtest result, showing how the comparison of the relative drawdown can help us to further improve those parameters.

Jocimar Lopes
Ha publicado el artículo Statistical Arbitrage Through Cointegrated Stocks (Part 8): Rolling Windows Eigenvector Comparison for Portfolio Rebalancing
Statistical Arbitrage Through Cointegrated Stocks (Part 8): Rolling Windows Eigenvector Comparison for Portfolio Rebalancing

This article proposes using Rolling Windows Eigenvector Comparison for early imbalance diagnostics and portfolio rebalancing in a mean-reversion statistical arbitrage strategy based on cointegrated stocks. It contrasts this technique with traditional In-Sample/Out-of-Sample ADF validation, showing that eigenvector shifts can signal the need for rebalancing even when IS/OOS ADF still indicates a stationary spread. While the method is intended mainly for live trading monitoring, the article concludes that eigenvector comparison could also be integrated into the scoring system—though its actual contribution to performance remains to be tested.

2
Chacha Ian Maroa
Chacha Ian Maroa 2025.12.05
Great article
Jocimar Lopes
Ha publicado el artículo Statistical Arbitrage Through Cointegrated Stocks (Part 7): Scoring System 2
Statistical Arbitrage Through Cointegrated Stocks (Part 7): Scoring System 2

This article describes two additional scoring criteria used for selection of baskets of stocks to be traded in mean-reversion strategies, more specifically, in cointegration based statistical arbitrage. It complements a previous article where liquidity and strength of the cointegration vectors were presented, along with the strategic criteria of timeframe and lookback period, by including the stability of the cointegration vectors and the time to mean reversion (half-time). The article includes the commented results of a backtest with the new filters applied and the files required for its reproduction are also provided.

3
Jocimar Lopes
Ha publicado el artículo Statistical Arbitrage Through Cointegrated Stocks (Part 6): Scoring System
Statistical Arbitrage Through Cointegrated Stocks (Part 6): Scoring System

In this article, we propose a scoring system for mean-reversion strategies based on statistical arbitrage of cointegrated stocks. The article suggests criteria that go from liquidity and transaction costs to the number of cointegration ranks and time to mean-reversion, while taking into account the strategic criteria of data frequency (timeframe) and the lookback period for cointegration tests, which are evaluated before the score ranking properly. The files required for the reproduction of the backtest are provided, and their results are commented on as well.

2
Jocimar Lopes
Ha publicado el artículo Statistical Arbitrage Through Cointegrated Stocks (Part 5): Screening
Statistical Arbitrage Through Cointegrated Stocks (Part 5): Screening

This article proposes an asset screening process for a statistical arbitrage trading strategy through cointegrated stocks. The system starts with the regular filtering by economic factors, like asset sector and industry, and finishes with a list of criteria for a scoring system. For each statistical test used in the screening, a respective Python class was developed: Pearson correlation, Engle-Granger cointegration, Johansen cointegration, and ADF/KPSS stationarity. These Python classes are provided along with a personal note from the author about the use of AI assistants for software development.

2
Jocimar Lopes
Ha publicado el artículo Statistical Arbitrage Through Cointegrated Stocks (Part 4): Real-time Model Updating
Statistical Arbitrage Through Cointegrated Stocks (Part 4): Real-time Model Updating

This article describes a simple but comprehensive statistical arbitrage pipeline for trading a basket of cointegrated stocks. It includes a fully functional Python script for data download and storage; correlation, cointegration, and stationarity tests, along with a sample Metatrader 5 Service implementation for database updating, and the respective Expert Advisor. Some design choices are documented here for reference and for helping in the experiment replication.

1
Jocimar Lopes
Ha publicado el artículo Statistical Arbitrage Through Cointegrated Stocks (Part 3): Database Setup
Statistical Arbitrage Through Cointegrated Stocks (Part 3): Database Setup

This article presents a sample MQL5 Service implementation for updating a newly created database used as source for data analysis and for trading a basket of cointegrated stocks. The rationale behind the database design is explained in detail and the data dictionary is documented for reference. MQL5 and Python scripts are provided for the database creation, schema initialization, and market data insertion.

1
Jocimar Lopes
Ha publicado el artículo Statistical Arbitrage Through Cointegrated Stocks (Part 2): Expert Advisor, Backtests, and Optimization
Statistical Arbitrage Through Cointegrated Stocks (Part 2): Expert Advisor, Backtests, and Optimization

This article presents a sample Expert Advisor implementation for trading a basket of four Nasdaq stocks. The stocks were initially filtered based on Pearson correlation tests. The filtered group was then tested for cointegration with Johansen tests. Finally, the cointegrated spread was tested for stationarity with the ADF and KPSS tests. Here we will see some notes about this process and the results of the backtests after a small optimization.

1
Jocimar Lopes
Ha publicado el artículo Statistical Arbitrage Through Cointegrated Stocks (Part 1): Engle-Granger and Johansen Cointegration Tests
Statistical Arbitrage Through Cointegrated Stocks (Part 1): Engle-Granger and Johansen Cointegration Tests

This article aims to provide a trader-friendly, gentle introduction to the most common cointegration tests, along with a simple guide to understanding their results. The Engle-Granger and Johansen cointegration tests can reveal statistically significant pairs or groups of assets that share long-term dynamics. The Johansen test is especially useful for portfolios with three or more assets, as it calculates the strength of cointegrating vectors all at once.

1
Jocimar Lopes
Ha publicado el artículo Statistical Arbitrage Through Mean Reversion in Pairs Trading: Beating the Market by Math
Statistical Arbitrage Through Mean Reversion in Pairs Trading: Beating the Market by Math

This article describes the fundamentals of portfolio-level statistical arbitrage. Its goal is to facilitate the understanding of the principles of statistical arbitrage to readers without deep math knowledge and propose a starting point conceptual framework. The article includes a working Expert Advisor, some notes about its one-year backtest, and the respective backtest configuration settings (.ini file) for the reproduction of the experiment.

2
Ishtiaq Ahmad
Ishtiaq Ahmad 2025.04.11
Mystery solved. 😊😊😊
Jocimar Lopes
Ha publicado el artículo Desarrollando un cliente MQTT para MetaTrader 5: un enfoque TDD - Final
Desarrollando un cliente MQTT para MetaTrader 5: un enfoque TDD - Final

Este artículo es la última parte de una serie que describe nuestros pasos de desarrollo de un cliente MQL5 nativo para el protocolo MQTT 5.0. Aunque la biblioteca aún no está lista para la producción, en esta parte utilizaremos nuestro cliente para actualizar un símbolo personalizado con ticks (o precios) procedentes de otro broker. Por favor, consulte la parte inferior de este artículo para obtener más información sobre el estado actual de la biblioteca, lo que falta para que sea totalmente compatible con el protocolo MQTT 5.0, una posible hoja de ruta, y cómo seguir y contribuir a su desarrollo.

Jocimar Lopes
Ha publicado el artículo Desarrollando un cliente MQTT para MetaTrader 5: metodología TDD (Parte 6)
Desarrollando un cliente MQTT para MetaTrader 5: metodología TDD (Parte 6)

Este artículo supone la sexta parte de la serie que describe las etapas de desarrollo de un cliente MQL5 nativo para el protocolo MQTT 5.0. En esta parte, describiremos los principales cambios en nuestra primera refactorización, obteniendo un borrador de trabajo de nuestras clases de construcción de paquetes, creando los paquetes PUBLISH y PUBACK y la semántica de los códigos de motivo PUBACK.

Jocimar Lopes
Ha publicado el artículo Desarrollando un cliente MQTT para MetaTrader 5: metodología de TDD (Parte 5)
Desarrollando un cliente MQTT para MetaTrader 5: metodología de TDD (Parte 5)

El presente artículo supone la quinta parte de la serie que describe las etapas de desarrollo de un cliente MQL5 nativo para el protocolo MQTT 5.0. Hoy describiremos la estructura de los paquetes PUBLISH: cómo establecemos sus banderas de publicación (Publish Flags), codificamos cadenas de nombres de temas y establecemos IDs de paquetes cuando es necesario.

Jocimar Lopes
Ha publicado el artículo Desarrollando un cliente MQTT para MetaTrader 5: metodología de TDD (Parte 4)
Desarrollando un cliente MQTT para MetaTrader 5: metodología de TDD (Parte 4)

Este artículo supone la cuarta parte de la serie que describe las etapas de desarrollo de un cliente MQL5 nativo para el protocolo MQTT. En esta parte, veremos las propiedades de MQTT v5.0, su semántica, cómo leemos algunas de ellas, y ofreceremos un breve ejemplo de cómo se pueden usar las propiedades para ampliar el protocolo.

Jocimar Lopes
Ha publicado el artículo Desarrollando un cliente MQTT para MetaTrader 5: metodología de TDD (Parte 3)
Desarrollando un cliente MQTT para MetaTrader 5: metodología de TDD (Parte 3)

El presente artículo supone la tercera parte de la serie que describe las etapas de desarrollo de un cliente MQL5 nativo para el protocolo MQTT. En esta ocasión, hablaremos con detalle sobre la aplicación de un desarrollo basado en pruebas para implementar el intercambio de paquetes CONNECT/CONNACK. Al final de este paso, nuestro cliente DEBERÁ poder comportarse adecuadamente al lidiar con cualquier posible resultado del servidor al intentar conectarse.

Jocimar Lopes
Ha publicado el artículo Desarrollando un cliente MQTT para MetaTrader 5: metodología de TDD (Parte 2)
Desarrollando un cliente MQTT para MetaTrader 5: metodología de TDD (Parte 2)

El artículo forma parte de una serie que describe las etapas de desarrollo de un cliente MQL5 nativo para el protocolo MQTT. En esta parte describiremos la organización de nuestro código, los primeros archivos de encabezado y las clases, así como la escritura de las pruebas. Este artículo también incluirá notas breves sobre un desarrollo basado en las pruebas y su aplicación a este proyecto.

Jocimar Lopes
Ha publicado el artículo Desarrollando un cliente MQTT para MetaTrader 5: metodología de TDD
Desarrollando un cliente MQTT para MetaTrader 5: metodología de TDD

El presente artículo representa el primer intento de desarrollar un cliente MQTT nativo para MQL5. El MQTT es un protocolo de comunicación "publicación-suscripción". Es ligero, abierto, simple y está diseñado para implementarse con facilidad, lo cual permite su uso en muchas situaciones.

Jocimar Lopes
Ha publicado el artículo Cómo conectar MetaTrader 5 a PostgreSQL
Cómo conectar MetaTrader 5 a PostgreSQL

Este artículo describiremos cuatro métodos para conectar el código MQL5 a una base de datos de Postgres y ofreceremos una guía paso a paso para configurar un entorno de desarrollo para uno de ellos, la API REST, utilizando el Subsistema de Windows para Linux (WSL). Asimismo, mostraremos una aplicación demostrativa de la API con el código MQL5 correspondiente para insertar datos y consultas a las tablas correspondientes, así como un asesor demo para usar estos datos.

Jocimar Lopes
Se ha registrado en MQL5.community