{"id":24496849,"url":"https://github.com/10mohi6/stock-pairs-trading-python","last_synced_at":"2025-04-14T04:14:21.299Z","repository":{"id":59536523,"uuid":"537801681","full_name":"10mohi6/stock-pairs-trading-python","owner":"10mohi6","description":"stock-pairs-trading is a python library for backtest with stock pairs trading using kalman filter on Python 3.8 and above.","archived":false,"fork":false,"pushed_at":"2023-09-19T11:26:04.000Z","size":96,"stargazers_count":36,"open_issues_count":1,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T04:14:15.047Z","etag":null,"topics":["backtest","kalman-filter","pairs-trading","python","stock"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/10mohi6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-17T12:28:43.000Z","updated_at":"2024-12-17T16:52:54.000Z","dependencies_parsed_at":"2022-09-18T14:14:17.095Z","dependency_job_id":null,"html_url":"https://github.com/10mohi6/stock-pairs-trading-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fstock-pairs-trading-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fstock-pairs-trading-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fstock-pairs-trading-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fstock-pairs-trading-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/10mohi6","download_url":"https://codeload.github.com/10mohi6/stock-pairs-trading-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819408,"owners_count":21166477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backtest","kalman-filter","pairs-trading","python","stock"],"created_at":"2025-01-21T21:19:06.360Z","updated_at":"2025-04-14T04:14:21.268Z","avatar_url":"https://github.com/10mohi6.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stock-pairs-trading\n\n[![PyPI](https://img.shields.io/pypi/v/stock-pairs-trading)](https://pypi.org/project/stock-pairs-trading/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![codecov](https://codecov.io/gh/10mohi6/stock-pairs-trading-python/branch/main/graph/badge.svg?token=DukbkJ6Pnx)](https://codecov.io/gh/10mohi6/stock-pairs-trading-python)\n[![Build Status](https://app.travis-ci.com/10mohi6/stock-pairs-trading-python.svg?branch=main)](https://app.travis-ci.com/10mohi6/stock-pairs-trading-python)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/stock-pairs-trading)](https://pypi.org/project/stock-pairs-trading/)\n[![Downloads](https://pepy.tech/badge/stock-pairs-trading)](https://pepy.tech/project/stock-pairs-trading)\n\nstock-pairs-trading is a python library for backtest with stock pairs trading using kalman filter on Python 3.8 and above.\n\n## Installation\n\n    $ pip install stock-pairs-trading\n\n## Usage\n\n### find pairs\n```python\nfrom stock_pairs_trading import StockPairsTrading\n\nspt = StockPairsTrading(\n    start=\"2007-12-01\",\n    end=\"2017-12-01\",\n)\nr = spt.find_pairs([\"AAPL\", \"ADBE\", \"MSFT\", \"IBM\"])\nprint(r)\n```\n```python\n[('ADBE', 'MSFT')]\n```\n![pairs.png](https://raw.githubusercontent.com/10mohi6/stock-pairs-trading-python/main/tests/pairs.png)\n\n### backtest\n```python\nfrom pprint import pprint\nfrom stock_pairs_trading import StockPairsTrading\n\nspt = StockPairsTrading(\n    start=\"2007-12-01\",\n    end=\"2017-12-01\",\n)\nr = spt.backtest(('ADBE', 'MSFT'))\npprint(r)\n```\n```python\n{'cointegration': 0.0018311528816901195,\n 'correlation': 0.9858057442729853,\n 'maximum_drawdown': 34.801876068115234,\n 'profit_factor': 1.1214715644744209,\n 'riskreward_ratio': 0.8095390763424627,\n 'sharpe_ratio': 0.03606830691295276,\n 'total_profit': 35.97085762023926,\n 'total_trades': 520,\n 'win_rate': 0.5807692307692308}\n```\n![performance.png](https://raw.githubusercontent.com/10mohi6/stock-pairs-trading-python/main/tests/performance.png)\n\n### latest signal\n```python\nfrom pprint import pprint\nfrom stock_pairs_trading import StockPairsTrading\n\nspt = StockPairsTrading(\n    start=\"2007-12-01\",\n    end=\"2017-12-01\",\n)\nr = spt.latest_signal((\"ADBE\", \"MSFT\"))\npprint(r)\n```\n```python\n{'ADBE Adj Close': 299.5,\n 'ADBE Buy': True, # entry buy\n 'ADBE Cover': False, # exit buy\n 'ADBE Sell': False, # entry sell\n 'ADBE Short': False, # exit sell\n 'MSFT Adj Close': 244.74000549316406,\n 'MSFT Buy': False, # entry buy\n 'MSFT Cover': False, # exit buy\n 'MSFT Sell': True, # entry sell\n 'MSFT Short': False, # exit sell\n 'date': '2022-09-16',\n 'zscore': -36.830427514962274}\n```\n## Advanced Usage\n```python\nfrom pprint import pprint\nfrom stock_pairs_trading import StockPairsTrading\n\nspt = StockPairsTrading(\n    start=\"2007-12-01\",\n    end=\"2017-12-01\",\n    outputs_dir_path = \"outputs\",\n    data_dir_path = \"data\",\n    column = \"Adj Close\",\n    window = 1,\n    transition_covariance = 0.01,\n)\nr = spt.backtest(('ADBE', 'MSFT'))\npprint(r)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10mohi6%2Fstock-pairs-trading-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F10mohi6%2Fstock-pairs-trading-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10mohi6%2Fstock-pairs-trading-python/lists"}