Giter VIP home page Giter VIP logo

karagul / pairtrading-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kartikeyathakur/pairtrading

0.0 0.0 0.0 10 KB

The python file checks every pair in the S&P500 for co-integration using the Augmented Dickey Fuller test, calculates their correlation, buckets them by the level of correlation and does a performance analysis of the pair based trading strategy on the pair.

Python 100.00%

pairtrading-1's Introduction

PairTrading

This simple python script (df_no_factors.py) checks all the pairs in the SNP500 index for cointegration using the Augmented Dickey Fuller test and performs a performance analysis on the cointegrated pairs.

The time series data has been obtained using the Kaggle dataset and code at https://www.kaggle.com/camnugent/sandp500 . Many thanks. This data is in the file named quandl.csv. It can be found at https://drive.google.com/open?id=1dvM7k-jauLHPyea-I7kTd3LRDADfLaMs . I cannot upload this to the repository as it is more than 25 MB. Just keep the py file and the csv in the same repository and do not change any names. Run the py file and you are good to go. Since there are more than 100,000 possible pairs the script takes some time to run. Could be a couple of hours but after that you have all the results and you just need to analyze them to get your performance analysis.

The results can be found at https://drive.google.com/open?id=1jXEDXwUtfAZ8VkpY1wGA4kYVcojV-QMV . I cannot add them to the repository as they are bigger than 25 MB. The results are from an anlysis performed in May 2018. I have separed pairs into 3 groups. One has pairs with positive Cumulative returns and sharpe ratios, one has pairs with negative cumulative returns and sharp ratios and one has pairs with either a negative sharpe ratio or a neagtive cumulative return.

Also, I have created pairs where sectors were same for both the stocks to see if pairs in the same sector perform better compared to the others. The files with 'unbound' in their names do not have this constraint. In these pairs ignore the sector names as they are just the sector of the first stock in the pair.

Additionally, I performed a correlation analysis and bucketed the pairs in 5 buckets based on correlation to see if correlation had any effect on profits in a apir trading strategy. The buckets are -1.0 to 0.5, 05 to 0.8, 0.8 to 0.9 and 0.9 to 0.97 and 0.97 to 1.0. These have names like lowest, low, meduim, high and highest and if you see these words in the results they are nothing but the bucket of correlation in which they fall.

Conintegration and correlation checks are done for the first three years of data and the performance analysis on the latest two years of data.

pairtrading-1's People

Contributors

kartikeyathakur 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.