Found 78 repositories(showing 30)
jamesmawm
A high-frequency trading model using Interactive Brokers API with pairs and mean-reversion in Python
KidQuant
This project involves using a combination of statistics along with financial thoery to demonstrate a popular trading strategy used in equity markets: Pairs Trading.
wangy8989
Pairs Trading with Machine Learning on Distributed Python Platform
trading strategy is a fixed plan to go long or short in markets, there are two common trading strategies: the momentum strategy and the reversion strategy. Firstly, the momentum strategy is also called divergence or trend trading. When you follow this strategy, you do so because you believe the movement of a quantity will continue in its current direction. Stated differently, you believe that stocks have momentum or upward or downward trends, that you can detect and exploit. Some examples of this strategy are the moving average crossover, the dual moving average crossover, and turtle trading: The moving average crossover is when the price of an asset moves from one side of a moving average to the other. This crossover represents a change in momentum and can be used as a point of making the decision to enter or exit the market. You’ll see an example of this strategy, which is the “hello world” of quantitative trading later on in this tutorial. The dual moving average crossover occurs when a short-term average crosses a long-term average. This signal is used to identify that momentum is shifting in the direction of the short-term average. A buy signal is generated when the short-term average crosses the long-term average and rises above it, while a sell signal is triggered by a short-term average crossing long-term average and falling below it. Turtle trading is a popular trend following strategy that was initially taught by Richard Dennis. The basic strategy is to buy futures on a 20-day high and sell on a 20-day low. Secondly, the reversion strategy, which is also known as convergence or cycle trading. This strategy departs from the belief that the movement of a quantity will eventually reverse. This might seem a little bit abstract, but will not be so anymore when you take the example. Take a look at the mean reversion strategy, where you actually believe that stocks return to their mean and that you can exploit when it deviates from that mean. That already sounds a whole lot more practical, right? Another example of this strategy, besides the mean reversion strategy, is the pairs trading mean-reversion, which is similar to the mean reversion strategy. Whereas the mean reversion strategy basically stated that stocks return to their mean, the pairs trading strategy extends this and states that if two stocks can be identified that have a relatively high correlation, the change in the difference in price between the two stocks can be used to signal trading events if one of the two moves out of correlation with the other. That means that if the correlation between two stocks has decreased, the stock with the higher price can be considered to be in a short position. It should be sold because the higher-priced stock will return to the mean. The lower-priced stock, on the other hand, will be in a long position because the price will rise as the correlation will return to normal. Besides these two most frequent strategies, there are also other ones that you might come across once in a while, such as the forecasting strategy, which attempts to predict the direction or value of a stock, in this case, in subsequent future time periods based on certain historical factors. There’s also the High-Frequency Trading (HFT) strategy, which exploits the sub-millisecond market microstructure. That’s all music for the future for now; Let’s focus on developing your first trading strategy for now! A Simple Trading Strategy As you read above, you’ll start with the “hello world” of quantitative trading: the moving average crossover. The strategy that you’ll be developing is simple: you create two separate Simple Moving Averages (SMA) of a time series with differing lookback periods, let’s say, 40 days and 100 days. If the short moving average exceeds the long moving average then you go long, if the long moving average exceeds the short moving average then you exit. Remember that when you go long, you think that the stock price will go up and will sell at a higher price in the future (= buy signal); When you go short, you sell your stock, expecting that you can buy it back at a lower price and realize a profit (= sell signal). This simple strategy might seem quite complex when you’re just starting out, but let’s take this step by step: First define your two different lookback periods: a short window and a long window. You set up two variables and assign one integer per variable. Make sure that the integer that you assign to the short window is shorter than the integer that you assign to the long window variable! Next, make an empty signals DataFrame, but do make sure to copy the index of your aapl data so that you can start calculating the daily buy or sell signal for your aapl data. Create a column in your empty signals DataFrame that is named signal and initialize it by setting the value for all rows in this column to 0.0. After the preparatory work, it’s time to create the set of short and long simple moving averages over the respective long and short time windows. Make use of the rolling() function to start your rolling window calculations: within the function, specify the window and the min_period, and set the center argument. In practice, this will result in a rolling() function to which you have passed either short_window or long_window, 1 as the minimum number of observations in the window that are required to have a value, and False, so that the labels are not set at the center of the window. Next, don’t forget to also chain the mean() function so that you calculate the rolling mean. After you have calculated the mean average of the short and long windows, you should create a signal when the short moving average crosses the long moving average, but only for the period greater than the shortest moving average window. In Python, this will result in a condition: signals['short_mavg'][short_window:] > signals['long_mavg'][short_window:]. Note that you add the [short_window:] to comply with the condition “only for the period greater than the shortest moving average window”. When the condition is true, the initialized value 0.0 in the signal column will be overwritten with 1.0. A “signal” is created! If the condition is false, the original value of 0.0 will be kept and no signal is generated. You use the NumPy where() function to set up this condition. Much the same like you read just now, the variable to which you assign this result is signals['signal'][short_window], because you only want to create signals for the period greater than the shortest moving average window! Lastly, you take the difference of the signals in order to generate actual trading orders. In other words, in this column of your signals DataFrame, you’ll be able to distinguish between long and short positions, whether you’re buying or selling stock.
ozdemirozcelik
Pair-Trading bot developed with Python and Interactive Brokers Trader Workstation (TWS) API
10mohi6
stock-pairs-trading is a python library for backtest with stock pairs trading using kalman filter on Python 3.8 and above.
iammortimer
MortyBot is a Python bot implementing several trading strategies. It can work with any assets pair on the WAVES DEX and TurtleNetwork DEX.
Pairs trading backtesting enviroment built with Python.
Teino1978-Corp
A high-frequency trading model using Interactive Brokers API with pairs and mean-reversion in Python
A high-frequency trading model using Interactive Brokers API with pairs and mean-reversion in Python
BilliamsFluster
StockBotWebApp is a full-stack, voice-enabled trading platform I’ve always wanted to build. It pairs a Next.js frontend with an Express API and a Python FastAPI StockBot for analysis, backtesting, and real-time broker connectivity (Schwab, Alpaca). Features include the Jarvis assistant for voice interaction, secure env management via Infisical
10mohi6
jquants-pairs-trading is a python library for backtest with japanese stock pairs trading using kalman filter, J-Quants on Python 3.8 and above.
justfairdev
Pair-Trading bot developed with Python and Interactive Brokers Trader Workstation (TWS) API
abhi647
The Quantitative Strategy Analysis project aims to provide analysts with tools to research, backtest, and analyze various trading strategies involving currency pairs and ETFs. With Python notebooks, historical datasets, and performance reporting tools, this project is designed to streamline quantitative research
A Python project implementing a pairs trading strategy using cointegration analysis. Identifies pairs of assets with a historical relationship, tests for cointegration, and develops a mean-reversion trading strategy. Includes backtesting, risk management, and performance evaluation
Pratham-Uppal
An autonomous DyDx trading bot built using Python, and deployed on AWS EC2. This bot interacts with the DYDX Layer 2 Ethereum Trading Exchange, exploiting statistical arbitrage in pairs trading with exceptional precision. It operates unsupervised, consistently, and sends real-time trade performance updates via Telegram for continuous user insights.
YoussefBechara
A Python-based analytical tool that identifies and visualizes seasonal patterns in currency pairs. Combines statistical methods with interactive visualizations to help forex traders recognize recurring price behaviors and optimize trading strategies around seasonal tendencies.
momaabna
This Python script is a basic trading bot that interacts with the Binance API to perform buy and sell actions for a given trading pair (in this case, "LUNAUSDT"). The bot uses moving average strategies to determine buy and sell signals based on historical price data retrieved from Binance.
KingMaster86
Pi Trade is an automated Python-based cryptocurrency trading bot designed for Pi Network. It interacts with the exchange API to execute buy and sell orders based on simple price change strategies. The bot supports multiple trading pairs like PI NETWORK/USDT, PI NETWORK/BTC, and more, enabling efficient, hands-free trading.
KeithMaki
Detect new USDT trading pairs on binance with python
OsSyLab
A collection of automated trading bots built with Python, including pair trading, Q-learning, and DQN strategies.
bugattmark
Live Algorithmic Trading BTC in Python 📈 Automated BTC/USDT pair trading with a predefined strategy on Binance
TanyaSharma-1
Pair trading strategy app using Python & Streamlit. Detects cointegrated stock pairs, generates trading signals via z-score, and includes price charts, signal table, CSV export, and backtesting with Sharpe Ratio & returns.
liyincode
🚀 Python scripts to fetch historical K-line data for spot trading pairs from Binance API with optional technical analysis indicators.
parimita-mrig
An autonomous DyDx trading bot built using Python, and deployed on AWS EC2. This bot interacts with the DYDX Layer 2 Ethereum Trading Exchange, exploiting statistical arbitrage in pairs trading with exceptional precision. It operates unsupervised, consistently, and sends real-time trade performance updates via Telegram for continuous user insights.
MarcelaFerreiraR
Brazilian Stock Market Analysis Tool: Python-based dashboard that extracts B3 stock data from TradingView and Yahoo Finance, featuring pair trading analysis with correlation, beta calculation, and cointegration testing for identifying trading opportunities in the Brazilian market.
umeshdudi
This repository contains a Python-based trading bot that uses the OANDA API and the yfinance library to perform automated trading on the EUR/USD currency pair. The bot implements a simple trading strategy based on candlestick patterns and manages trades with take profit and stop loss settings.
TpSoftDev
A Python-based trading bot for MetaTrader 5 that employs the Simple Moving Average (SMA) strategy to trade the EUR/USD forex pair. This bot calculates the SMA based on recent market data and automates buy and sell orders based on SMA crossovers. It integrates with MetaTrader 5 API for real-time trading and uses Pandas for data analysis.
sb4541
High-dimensional constrained Markowitz OP for pair trading in Wilshire 5000 index with paralleled intuitive stochastic algorithm and tricks to handle memory occupancy (halving execution time), connected Excel and Python code through VBA for quick extraction and update of data
Rodriguez7
This repository contains Python scripts for generating trading signals for the EUR/USD forex pair. The scripts use various technical indicators like Z-score, Bollinger Bands, and Average True Range (ATR) to generate buy and sell signals. The scripts also include risk management strategies using ATR with a risk-reward ratio of 1:3.