Skip to content

Freelancer Project - Streaming process pipeline and Trading Bot

License

Notifications You must be signed in to change notification settings

Luissalazarsalinas/Trading-Bot

Repository files navigation

Trading bot and Sentiment Detector Project

Language Framework Framework Framework Docker

Freelancer Project - Streaming process pipeline and Trading Bot.

Problem Statement

Automated trading system also referred to as algorimith trading, allow traders to establish specific rules for both trade entries and exits that, once programmed, can be automatically executed via a computer. In this sese, there is a long list of advantages to having a computer monitor the markets for trading opportunities and execute the trades, including:

  • Minimizing emotions
  • Backtesting
  • Peserving discipline
  • Improving order entry speed
  • Diversiying trading

On the other hand, Sentiment analysis is also one of the more successful methods of including the effects of market psychology in a trading strategy. Empirical evidence suggests that investor sentiment is one of the most reliable indicators of future price movements.

Therefore, in this project, we develop a Streamlit App that utilizes an Automated Trading System as an API to get one trading strategy (MACD and MFI) and a sentiment detector based on a deep learning model(GRU).

The App can be viewed through this link

Deep Learning Model NoteBook

Trading system

Trading Strategies implemets in this project:

Moving average convergence/divergence(MACD)

  • The MACD is a technical analysis indicator that aims to identify changes in a share price's momentum. The MACD collects data from different moving averages to help traders indetify possible oppotunities around support and resistance levels.

MACD indicator components:

  • MACD line, measures the distance between two moving averages.
  • Signal line, identifies changes in price momentum and acts as a trigger for buy and sell signal.
  • Histogram, represents the difference between the MACD and signal line.

The MACD line was created by subtracting the 26-period moving average form the 12-period moving average. on the other hand, the signal line was created taking the 9-period moving average of the MACD.

Sell and Buy MACD signal

  • The MACD is then displayed as a histogram, a graphical representation of the distance between the two lines. If the MACD cuts through the signal line from below, traders could use it as a buy signal and if it cuts the signal line from above, traders might use it as a sell signal.

Data

Financial data

Data preprocessing stets:

  • Transform the data from json format to a dataframe format
  • Create datetime index
  • Stored the data into a PostGres Database

Text data

  • The tweets data were extrated from Twitter app using snscrape python library.

Keywords for searching:

  • "Stock Market"
  • "Stock Market sentiment"
  • "Stocks"

Data preprocessing stets:

  • Transform the data into a dataframe format
  • Clean tweets data
  • Stored the data in a CSV file
  • Cleaning and feature engineering (Lemmatizer and remove Stock words)
  • Create target variable (Get sentiments)

Sentiment Analysis

Modelling

Recurrent Neural Network Architectures that were tested:

  • LSTM
  • GRU

GRU architecture was chosen as the final model.

REST API

The trading system was developed as a rest API/web service using FastAPI (web framework from python). In this sense, this API has three different services:

  • MACD trading strategy service
  • MFI trading strategy service
  • Sentiment detector services

The API's code and its dependencies were packed into a container using Docker. The Docker image was stored on Docker hud.