Skip to content

Interact with the ALPACA stock brokerage through the terminal. Allows you to manage positions, execute trades, run analysis, backtest strategy, execute pairs trading strategy.

Notifications You must be signed in to change notification settings

AidanAlr/Alpaca-Pairs-Trading-Terminal

Repository files navigation


Alpaca-Pairs-Trading-Terminal

◦ Built on the official ALPACA API.

SciPy Python pandas NumPy

GitHub license git-last-commit GitHub commit activity GitHub top language

📍 Overview

This command line interface allows users to interact with their alpaca brokerage account through the terminal. Features include view current profits and positions, get asset price quotes, execute trades, run analyses, backtest strategies, and implement a pairs trading strategy all from the command line.


Usage Documentation

This script uses argparse to handle command-line arguments for interacting with Alpaca trading functions. Below are the available options:

Command-Line Arguments

  • -t, --ticker : Enter an Alpaca ticker. Add -q or -tr for quote or trade.
  • -tr, --trade : Visit the trade menu for the ticker.
  • -p, --positions : Print current positions.
  • --exitall : Exit all positions immediately.
  • -im, --imenu : Enter interactive menu.
  • -q, --quote : Get a quote for the ticker.

Example Usage

python terminal.py -t AAPL -q

This will get a quote for the ticker AAPL.

Demo of interactive menu

Terminal.Demo.mp4

📦 Features

► Analysis

Conduct the analysis required to find a suitable pair for statistical arbitrage. Submit a CSV file of stock tickers and the program will download the stock data from the last year and check the correlation between all assets. If a pair has a sufficiently high correlation, it is placed through ADF test to check the stationarity of the time series and cointegration tests for the suitability of the pair. Once a suitable pair is chosen, we use a 60-day rolling regression on the asset prices allowing us to generate the hedge ratio; we then analyse the relative spread between assets. When the spread exceeds a certain boundary, we will buy one asset and short the other expecting the spread to retract.

You will be presented with the option to backtest the strategy as well.

► Backtest strategy

Dashboard that generates graphic representations of spread, zscored spread and strategy return. Allows you to test different strategies by adjusting take profits and stop loss.

► Execute Pairs Trading Strategy

Once you have chosen a pair execute and manage a pairs trading strategy directly from your terminal.

► View current positions with profit and loss

Dashboard for viewing all important metrics about current positions.

► Manual Trade

Option to conduct a manual trade, market or limit order.

► Get Quote

Option to conduct get the market price of an asset.

► Close All Positions

Option to quickly exit all positions.


🔧 Installation

  1. Clone the Pairs-Trading-Algorithm repository:
git clone https://github.com/AidanAlr/Pairs-Trading-Algorithm
  1. Change to the project directory:
cd Pairs-trading-Algorithm
  1. Install the dependencies:
pip install -r requirements.txt
add account details to trading .FAKENV and change to .env

🤖 Running Program

Change to the directory containing the cloned repository. Open the terminal in this folder.

Enter to see a list of command line arguments:

python terminal.py -h

To interact with the terminal through an interactive menu:

python terminal.py -im

🤝 Contributing

Contributions are welcome! Here are several ways you can contribute:


Return


About

Interact with the ALPACA stock brokerage through the terminal. Allows you to manage positions, execute trades, run analysis, backtest strategy, execute pairs trading strategy.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages