Giter Site home page Giter Site logo

10mohi6 / stock-pairs-trading-python Goto Github PK

View Code? Open in Web Editor NEW
32.0 2.0 12.0 96 KB

stock-pairs-trading is a python library for backtest with stock pairs trading using kalman filter on Python 3.8 and above.

License: MIT License

Python 100.00%
backtest kalman-filter pairs-trading python stock

stock-pairs-trading-python's Introduction

stock-pairs-trading

PyPI License: MIT codecov Build Status PyPI - Python Version Downloads

stock-pairs-trading is a python library for backtest with stock pairs trading using kalman filter on Python 3.8 and above.

Installation

$ pip install stock-pairs-trading

Usage

find pairs

from stock_pairs_trading import StockPairsTrading

spt = StockPairsTrading(
    start="2007-12-01",
    end="2017-12-01",
)
r = spt.find_pairs(["AAPL", "ADBE", "MSFT", "IBM"])
print(r)
[('ADBE', 'MSFT')]

pairs.png

backtest

from pprint import pprint
from stock_pairs_trading import StockPairsTrading

spt = StockPairsTrading(
    start="2007-12-01",
    end="2017-12-01",
)
r = spt.backtest(('ADBE', 'MSFT'))
pprint(r)
{'cointegration': 0.0018311528816901195,
 'correlation': 0.9858057442729853,
 'maximum_drawdown': 34.801876068115234,
 'profit_factor': 1.1214715644744209,
 'riskreward_ratio': 0.8095390763424627,
 'sharpe_ratio': 0.03606830691295276,
 'total_profit': 35.97085762023926,
 'total_trades': 520,
 'win_rate': 0.5807692307692308}

performance.png

latest signal

from pprint import pprint
from stock_pairs_trading import StockPairsTrading

spt = StockPairsTrading(
    start="2007-12-01",
    end="2017-12-01",
)
r = spt.latest_signal(("ADBE", "MSFT"))
pprint(r)
{'ADBE Adj Close': 299.5,
 'ADBE Buy': True, # entry buy
 'ADBE Cover': False, # exit buy
 'ADBE Sell': False, # entry sell
 'ADBE Short': False, # exit sell
 'MSFT Adj Close': 244.74000549316406,
 'MSFT Buy': False, # entry buy
 'MSFT Cover': False, # exit buy
 'MSFT Sell': True, # entry sell
 'MSFT Short': False, # exit sell
 'date': '2022-09-16',
 'zscore': -36.830427514962274}

Advanced Usage

from pprint import pprint
from stock_pairs_trading import StockPairsTrading

spt = StockPairsTrading(
    start="2007-12-01",
    end="2017-12-01",
    outputs_dir_path = "outputs",
    data_dir_path = "data",
    column = "Adj Close",
    window = 1,
    transition_covariance = 0.01,
)
r = spt.backtest(('ADBE', 'MSFT'))
pprint(r)

stock-pairs-trading-python's People

Contributors

10mohi6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stock-pairs-trading-python's Issues

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.