Git Product home page Git Product logo

p2_ml_algotrade's Introduction

P2_ML_AlgoTrade

UCB FinTech Butlers - Project 2 : Machine Learning Algorithmic Trading

Objective

Build predictive models using machine learning algorithms for buy-sell decision making

Definitions

Algorithmic trading relies on computer programs that execute algorithms to automate some or all elements of a trading strategy. Algorithms are a sequence of steps or rules designed to achieve a goal. They can take many forms and facilitate optimization throughout the investment process, from idea generation to asset allocation, trade execution, and risk management.

Machine learning (ML) involves algorithms that learn rules or patterns from data to achieve a goal such as minimizing a prediction error. We will illustrate how to apply ML algorithms ranging from linear models to recurrent neural networks (RNNs) to market and fundamental data and generate tradeable signals.

Technical-Trading-Bot (Future Release) Trading Bot built using the Alpaca API in Python.

Indicators used for Signal Generation: ATR, DEMA, EFI, EMA, EMV, Force Index, RSI, SMA_Fast, SMA_Slow, SSMA, TEMA, TRIMA, StochRSI, and Stochastic Oscillator.

The Machine Learning Workflow

Developing an ML solution requires a systematic approach to maximize the chances of success while proceeding efficiently. It is also important to make the process transparent and replicable to facilitate collaboration, maintenance, and subsequent refinements.

The process is iterative throughout but these steps were followed:

  1. Data Collection
  2. Data Preprocessing
  3. Feature Engineering
  4. Label Generation
  5. Model Selection
  6. Model Training
  7. Model Evaluation
  8. Model Deployment

Modeling

The following process has been followed to test and select the most suitable Models using the SPY and QQQ:

  1. Data Loading Prepared Train/Test datasets were loaded from saved files. Please see the Data Preparation README for details on the preparation of the datasets.

  2. Model Training Sci-Kit Learn Modeling An initial set of Machine Learning models were built using six different packages from the Scikit-Learn library:

    As the initial step in the building of all models a StandardScaler was instantiated. There were 10-plus models built using different parameters. F1-score and AUC-ROC score were calculated to determine the predictive power of the model.

    • TensorFlow Modeling
      • A Deep Neural Network consisting of two Dense layers was designed with the intent of predicting portfolio performance. The following steps were involved in the training of the neural network.

      • A loop was used to perform the following steps atleast once per portfolio:

        • StandardScaler() defined and fit to training data
        • Training data transformed by scaler
        • Test data transformed by scaler
        • Keras-Tuner Hypberband tuner was used to find the optimal combination of the following parameters:
        • The model with the 'best' performance from all the model configurations was chosen
  3. Model Performance/Selection Models were evaluated using an ROC-AUC score and F1 score, with the accuracy score and plotting of returns being the primary metrics. Foundational Models

Technologies

Details on asset performance are retrieved using the Yahoo Finance API. The Machine Learning Models were built in Jupyter Lab, written in Python and leveraged GoogleColab to provide feedback from Contributors. Visualizations are provided by the hvPlot and Matplotlib libraries. The Pandas and Numpy libraries are used to work with the asset data retrieved from the API.

Installation Guide

The contents of the repository should be placed into the desired folder on the users computer, being sure to maintain the directory structure.

The following python packages must be installed to run the models locally:

  • pandas
  • matplotlib
  • talib
  • finta
  • yahoo_fin
  • numpy
  • hvplot
  • jupyterlab (only if the .ipynb file is used. running the .py file does not require jupyterlab)

These packages may be individually installed into the environment of your choice or you may create a new conda environment using the included environment.yml file.

conda env create -f environment.yml

If you prefer using pip, the included requirements.txt file may be used to install the required packages.

pip install -r requirements.txt

Contributors

License

License information can be found in the included LICENSE file.

Resources / Credits

Code for generating the Machine Learning Models was modified from code provided by UC Berkeley Extension FinTech Bootcamp Research on trading factors and machine learning was modified from code for Machine Learning for Algorithmic Trading, 2nd edition by Stefan Jansen Analysis of Financial Time Series, 3rd Edition, Ruey S. Tsay Quantitative Equity Investing: Techniques and Strategies, Frank J. Fabozzi, Sergio M. Focardi, Petter N. Kolm

Future Research

  • Integrating Risk Tolerance Survey from Project 1
  • Explore other machine learning models
  • Runtime/ Resource efficiency
  • Test on other asset classes, stocks and sectors
  • Test on ‘paper trading’ mode

Future Releases

  • Add UI/UX
  • API integration
  • Deploy to the cloud
  • Blockchain record keeping
  • Adding macroeconomic market information for the client
  • Improve visualizations

Disclaimer

The information provided through this application is for information and educational purposes only. It is not intended to be, nor should it be used as, investment advice. Seek a duly licensed professional for investment advice.

p2_ml_algotrade's People

Contributors

lutov001 avatar slay1007 avatar supersilver1978 avatar malika0410 avatar mikenguyenx avatar

Watchers

 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.