Skip to content

The code I made to find stocks with suitable cointegration for pairs trading using the Engle-Granger test to calculate p values of different stock pairs.

License

Notifications You must be signed in to change notification settings

Rcode879/p-value-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Cointegration Pair Finder

This Python script identifies cointegrated stock pairs among S&P 500 companies β€” a common statistical arbitrage strategy used in pairs trading.

It automatically downloads S&P 500 tickers from Wikipedia, fetches their historical price data from Yahoo Finance, and performs the Engle-Granger cointegration test on all possible stock pairs.


πŸš€ Features

  • Scrapes S&P 500 tickers directly from Wikipedia
  • Downloads historical price data using yfinance
  • Computes cointegration tests for all stock combinations
  • Outputs the top 10 pairs with the lowest p-values (most likely to be cointegrated)

🧠 How It Works

  1. Fetch S&P 500 tickers from Wikipedia.
  2. Download adjusted closing prices for a chosen subset of tickers.
  3. Run cointegration tests (statsmodels.tsa.stattools.coint) for every pair.
  4. Sort by p-value to identify the strongest candidates.

πŸ“¦ Requirements

Install dependencies using:

pip install requests pandas yfinance statsmodels lxml

About

The code I made to find stocks with suitable cointegration for pairs trading using the Engle-Granger test to calculate p values of different stock pairs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages