GithubHelp home page GithubHelp logo

jeff-lewis / algorithmictrading-cointegration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vermeirjellen/algorithmictrading-cointegration

0.0 2.0 0.0 1.66 MB

Proof of concept Cointegration-Based spread trading strategy applied to the Foreign Exchange market

License: Other

R 100.00%

algorithmictrading-cointegration's Introduction

Proof of concept: In sample cointegration-based statistical arbitrage trading strategy.

View the paper "Cointegration-Based spread trading applied to the foreign exchange market.pdf" inside the ./paper directory for more information on the strategy.

Entrance point to the project is "demo.R" and the functionality is well documented inside the code. The script executes the following functionality in order:
1) A portfolio containing currency pair objects is created from the .csv files which are provided in the ./data directory. It should be noted that all relevant timeseries are recreated in such a way that the USD currency pair becomes the quoted pair, for consistency reasons.
2) A particular data window is selected and the individual time series are plotted (line 23)
3) The timeseries are tested for integration of order 1: I(1)
4) The I(1) Currency pairs are grouped in smaller cointegrationTestPortfolioCollection objects. Cointegration tests are performed on these subgroups one by one, as follows:
- We obtain the optimal VAR lag length by searching for the VAR model that fits the timeseries data in the portfolio optimally, based upon the SC criterion.
- We use this lag length to launch a Johansen Cointegration procedure test on the portfolio
- We use the trace statistic to determine the cointegration properties of the portfolio
- Some additional properties such as the half life of mean reversion are further determined for the cointegrating portfolios
5) For this partcular demo run we determine that for 16 out of the 91 tested portfolios, the null hypothesis of no cointegrating vectors is rejected with more than 90% confidence.
6) For these particular portfolios we use the "optimal" cointegrating vectors with highest eigenvalues and we use the relevant vectorvalues as our hedge ratio's.
7) We use the hedge ratio's to create spreads for these cointegrating portfolios and output some graphs for illustration purposes (line 75)
8) We execute a simple mean reversion strategy on the cointegrating spread and output the results for Portfolio(AUDUSD/CADUSD) (Line 82)
9) We execute a simple mean reversion strategy on the cointegrating spread and output the results for Portfolio(AUDUSD/CADUSD/NZDUSD/JPYUSD/ (Line 92). We note that the latter portfolio has stronger cointegrating properties and a lower half life of mean reversion. As expected, The results -as expressed by the Sharpe ratio- for this portfolio are better (Transaction costs / bid-ask spreads are included in the analysis).

Images containing the relevant results of the demo script are added to the main folder. In case of problems or errors while running the code, make sure that your R version is up to date and all the required subpackages that are mentioned in config.r are installed properly. Uncommenting and executing the first 4 lines in config.R should resolve most potential problems that might occur. Also view the extended comments inside the ./classes and ./functions files for more information on the technical implementation details. Separate README documents might be included at a later time to provide more detailed information.

Project code is copyrighted by Jellen Vermeir and available for distribution under the FreeBSD license conditions. Following people are also credited for the co-authoring of the attached paper:
- Thys Lynsey
- Van Overloop Hans
- Van Drom Karen
- Vanstreels Dieter
- Trippaers Veerle

Feel free to contact me about this project via [email protected]

algorithmictrading-cointegration's People

Contributors

vermeirjellen avatar

Watchers

 avatar  avatar

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.