Git Product home page Git Product logo

machine-learning-for-trading-1's Introduction

Algorithmic Trading using Machine Learning

This repository contains the source code for a Python Project which aims at studying different machine learning models and applying them in the domain of algorithmic trading.

It also includes screeners for identifying potential stocks and backtesting strategies for each model. An online learning model is also prepared to be used during live trading.

Getting Started

All of the functions are implemented in Jupyter Notebooks.

Prerequisites

  • Anaconda Navigator (preferred)
  • yFinance
  • TA-Lib
  • Backtrader
  • PyFolio

Installing

Open the Anaconda Prompt and install the additional libraries using:

pip install yfinance
conda install -c conda-forge ta-lib
pip install backtrader
conda install -c conda-forge pyfolio

And, we're good to go!

Deployment

Data

The notebook 00_Data.ipynb loads the required fundamental and market data for S&P500 stocks using Yahoo Finance and stores them in the directory /data.

The notebook 01_Screener.ipynb screens for momentum and value stocks based on the downloaded data.

The notebook 02_FeatureEngineering.ipynb creates financial features from the data and accomodates technical and factor data to the dataset. The dataset is cleaned and categorical variables are encoded as well.

Returns for holding periods of 1, 5, 10, 21, 42 and 63 days are added as target variables and stored in /data/featureset.csv.

Training

The notebook 03_LinearModels.ipynb applies Ridge Regression and Logistic Regression to predict returns/market movements.

The notebook 04_TimeSeries.ipynb decomposes the series, makes it stationary and applies ARMA and VAR to predict returns.

The notebook 05_UnsupervisedLearning.ipynb applies PCA on the engineered features to extract the best 30 principal components (/data/pcafeatureset.csv).

Further, PCA and Hierarchial Clustering are used to obtain weights for a bag of selected 100 stocks.

The notebook 06_BoostingMethods.ipynb uses the PCA extracted features to train XGBoost, LightGBM and CatBoost models to predict returns/market movements.

All predictions are stored as CSVs in the directory /predictions.

Backtesting

The notebook 07_Backtesting.ipynb uses Backtrader to backtest the predictions for all the trading models. Further analysis is done using PyFolio.

The notebook 08_OnlineModel.ipynb trains an online learning K-Nearest Neighbors model along with backtesting.

The file helpers.py contains helper functions for calculation and visualisation.

Built With

Authors

  • Ishan Bhattacharya - Initial work - ishanbhattacharya
  • References - Machine Learning for Algorithmic Trading (2nd Edition), Stefan Jansen

See also the list of contributors who participated in this project.

machine-learning-for-trading-1's People

Contributors

ishanbhattacharya avatar

Stargazers

 avatar

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.