Skip to content

Code repository for the book "Hands On AI Trading with Python, QuantConnect, and AWS."

Notifications You must be signed in to change notification settings

QuantConnect/HandsOnAITradingBook

Repository files navigation

Master the art of AI-driven algorithmic trading strategies through hands-on examples, in-depth insights, and step-by-step guidance

Hands-On AI Trading with Python, QuantConnect, and AWS explores real-world applications of AI technologies in algorithmic trading. It provides practical examples with complete code, allowing readers to understand and expand their AI toolbelt.


getting-started-banner


To use the repo open the main.py and research.ipynb files from an example folder and copy/paste the code into your project’s files on QuantConnect Cloud / Local Platform.


If you prefer to use the LEAN CLI, follow these steps:

  1. Clone the repo.
  2. Run bash command to move the main.py/research.ipynb to a project in your organization workspace.
  3. cd to the organization workspace.
  4. Run the backtest / Open the notebook on your local machine, or push the project to QuantConnect Cloud.

Note: Running the projects locally require the local machine to have the required datasets.


Using the backtestlib functionality:

In order to use the backtestlib functionality:

  1. Create a library called backtestlib.
  2. add the library to your project.

The process to create and add a library depends on whether you use Cloud PlatformLocal Platform, or the CLI.


examples-banner


Follow the steps above to use these examples:


ML Trend Scanning with MLFinlab
Uses MLFinLab's trend scanning package to detect price trends (up/down/no-trend) for timing Bitcoin trades.

Factor Preprocessing Techniques for Regime Detection
Applies different preprocessing techniques and PCA on market factors to predict SPY's weekly returns using a multiclass random forest model.

Reversion vs. Trending - Strategy Selection by Classification
Uses neural networks to predict whether the next trading day will favor momentum or reversion risk exposure by analyzing volatility indicators.

Alpha by Hidden Markov Models
Employs Hidden Markov Models to predict market volatility regimes and allocate funds between different ETFs and options accordingly.

FX SVM Wavelet Forecasting
Uses Support Vector Machines (SVM) and wavelets to predict forex pair prices, where wavelets decompose price data into components and SVM predicts each component separately.

Dividend Harvesting Selection of High-Yield Assets
Uses a decision tree regression model to predict future dividend yields based on financial ratios to build a high-yield portfolio.

Effect of Positive-Negative Splits
Utilizes a multiple linear regression model to estimate future returns when stock splits are imminent and trades accordingly.

Stoploss Based on Historical Volatility and Drawdown Recovery
Uses regression models to dynamically adjust stop-loss levels based on market conditions.

ML Trading Pairs Selection
Demonstrates using PCA and clustering techniques to identify potential pairs for statistical arbitrage trading. It first applies PCA to transform standardized stock returns into principal components, then uses the OPTICS clustering algorithm and various statistical tests (cointegration, Hurst exponent, half-life) to select optimal trading pairs.

Stock Selection through Clustering Fundamental Data
Uses PCA and learning-to-rank algorithms to predict relative performance of stocks based on fundamental data.

Inverse Volatility Rank and Allocate to Future Contracts
Applies ridge regression to predict volatility and allocate futures contracts inversely proportional to their expected volatility.

Trading Costs Optimization
Uses a DecisionTreeRegressor to predict trading costs and optimize trade execution timing.

PCA Statistical Arbitrage Mean Reversion
Applies PCA and linear regression for statistical arbitrage to exploit price differences between related securities.

Temporal CNN Prediction
Uses a temporal CNN to predict the direction of future stock prices based on OHLCV data.

Gaussian Classifier for Direction Prediction
Employs Gaussian Naive Bayes classifiers to predict daily returns of technology stocks.

LLM Summarization of Tiingo News Articles
Uses OpenAI's GPT-4 to analyze sentiment from news articles for trading decisions.

Head Shoulders Pattern Matching with CNN
Uses a one-dimensional CNN to detect head-and-shoulders patterns and trade forex accordingly.

Amazon Chronos Model
Utilizes Amazon's Chronos model to forecast future price paths and optimize portfolio weights.

FinBERT Model
Applies the FinBERT language model to assess news sentiment and make trading decisions based on aggregate sentiment scores.



About

Code repository for the book "Hands On AI Trading with Python, QuantConnect, and AWS."

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •