Coder Social home page Coder Social logo

shimonanarang / pair-trading Goto Github PK

View Code? Open in Web Editor NEW
42.0 2.0 13.0 1.36 MB

Statistical arbitrage of cointegrating currencies with pair trading where the signal for the next day is predicted using LSTM

Python 100.00%
pair-trading-strategy cointegration pair-trading mean-reversion lstm-neural-networks

pair-trading's Introduction

Pair Trading for Cointegrating Currencies

  • Statistical arbitrage uses various financial statistics to find pricing inefficiencies in mean-reverting trading pairs. This project explores the statistical arbitrage of the Canadian and Australian dollars.
  • A common type of statistical arbitrage is pair-trading. If two assets are cointegrated, then their price will converge to the mean price in the long term
  • Pair-trading recognizes deviations in the price of a stock from the mean and either shorts or longs the stock. Once the price reverts to the mean, profit can be made.
  • The trading signal is a statistical measure that indicates the moments of mean deviation and reversion
  • Trading model for the next day is predicted using LSTMs and position of the portfolio is determined from hedge ratios

Packages

  • keras
  • tensorflow
  • statsmodels
  • NumPy

Files

  • check_johansen_loop.py: checks cointegration with johansen test in loop
  • check_mean_reversion.py: checks mean reversion of two time series using Augmented Dickey Fuller test
  • AUDCAD_unequal_mod.py: main file
  • model.py: Trains LSTM Model and Predicts the trading signal
  • evaluation.py: evaluation using portfolio metrics and rmspe
  • seq_norm.py: window normalisation and data prep for LSTM model

Positions

Positions of securities are calculated by using the hedge ratios (hedge ratios determine capital allocation). Positions of two securities on training and test set:

image

image

When two cointegrating securities diverge due to market conditions, they tend to converge in few time periods

Usage

  1. Clone the repo

git clone https://github.com/shimonanarang/pair-trading.git

  1. Install the requirements

pip install -r requirements.txt

  1. Navigate and run the following command

python AUDCAD_uneual_mod.py

References

  1. Joao Frois Caldeira and Guilherme Moura. \Selection of a portfolio of Pairs Based on Cointegration: A Statistical Arbitrage Strategy". In: Bras. Financas 11.1 (Mar. 2013)
  2. Lu, Anran, et al. Cluster-Based Statistical Arbitrage Strategy. Stanford University, (June, 2018)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.