UofA522 / Project1

Rust Project 1 for 522 - Stock Market Monitor
GNU General Public License v3.0
0 stars 0 forks source link

Rust Project 1 for ECE 522 - Stock Market Monitor

Group-4

Overview

The goal of the project is as follows:

  1. Write a simple stock monitoring program that takes a stock symbol as input
  2. The output fo the program is a chart showing the daily closing price for the last 6 months
  3. Print the minimum and maximum closing prices for the last 6 months along with the respective dates of those closing prices.
  4. Plot the days when volatility in the price was greater than 2% of the closing price.
  5. Also plot one of the financial analysis algorithms like RSI or MACD.

The crates used in this project and their uses are described as follows:

  1. clap: crate is used for building flexible command line interface applications. [Link]

  2. yahoo_finance_api: has been used in this project to fetch the stock quotes of the past six months using the yahoo! finance API. [Link]

  3. tokio: A runtime for writing reliable asynchronous applications in Rust.

  4. lazy_static: A crate for declaring lazily evaluated static variables

  5. log: A crate used for providing a single API that abstracts various logging implementations

  6. log4rs: Logging implementation used for our application, modelled after popular Java logging libraries like logback and log4j

  7. plotters: crate is used to plot various types of graphs like line chart, histogram, candlesticks plot etc. [Link]

  8. chrono: The ‘chrono’ crate is a library which contains a list of functions which can be used to perform various operations on dates and times in the Proleptic Gregorian calendar. [Link]

  9. ta: crate is used for technical analysis tasks. We have used this crate to calculate a variety of financial analysis indicators like RSI (Relative Strength Index), MACD (Moving Average Convergence Divergence) etc.

Financial Analysis Indicators/Algorithms used:

1. Volatile Days

On the stock chart volatile days are plotted in order to indicate the days where stock price varied by more than 2% of the total price.

2. Bollinger Bands

We have implemented the Bollinger Bands Indicators by using the ta crate. For Bollinger Bands, three lines are plotted (middle band, upper band, lower band). The middle band is usually calculated as a simple moving average over a particular period (a period of 20 has been used in our program). The upper band and lower band are calculated by adding and subtracting the multiple of standard deviation respectively to the average value. Mathematically, these bands can be written as follows:

BollingerBands_Middle Band = Simple Moving Average (SMA).
BollingerBands_Upper Band = SMA + Standard_Deviation of observation * multiplier
BollingerBands_Lower Band = SMA - Standard_Deviation of observation * multiplier 

In this project, the multiplier is taken as 2.

3. Relative Strength Index (RSI)

We have implemented the Relative Strength Index (RSI) Indicators by using the ta crate. Mathematically RSI can be defined as follows:

RSIt = EMAUt * 100 / (EMAUt + EMADt)

where

  1. RSIt : value of RSI indicator in a moment of time t
  2. EMAUt : value of EMA of up periods in a moment of time t
  3. EMADt : value of EMA of down periods in a moment of time t

The RSI indicator is studied in order to identify the oversold or overbought conditions of a stock. A period of 14 has been used in this project to calculate the RSI.

4. Fast/Slow Exponential Moving Average (EMA):

We have implemented the Fast/Slow SMA Indicators by using the ta crate. And fast period is set to 20 and slow period is set to 50.

5. Fast/Slow Simple Moving Average (SMA):

We have implemented the Fast/Slow SMA Indicators by using the ta crate. And fast period is set to 20 and slow period is set to 50.

6. Moving Average Convergence Divergence (MACD):

We have implemented the MACD Indicators by using the ta crate. For calculating the MACD we have used a slow period of 26, fast period of 12 and a signal period of 9.

Charting Setup

For plotting all the charts we used plotters and labelled the x and y axis where and when needed.

We have used Line and Histogram Charts primarily. The charts looks like as follows:

stock_chart_TSLA

stock_chart_BNY

macd_TSLA

macd_BNY

sma_TSLA

sma_BNY

rsiTSLA

sma_BNY

sma_TSLA

stock_chart_BNY

stock_chart_TSLA

Autoscaling is supported for height not width, width is fixed.

Project Setup

To setup the project lets look at the project setup that you might have:

image

After you extract the file your file directory should something as above. Follow the steps.

  1. Install Rust from here
  2. Run cd ./stock_market
  3. Run cargo build --release
  4. You should now see a target directory
  5. Run cd ./target/release
  6. Then run ./stock_marker.exe --name AAPL image

Note: All errors are logged to a log file under the 'log' directory

Usage Instructions

Help

 ./stock_market.exe --help

or

 ./stock_market.exe -h

Output:

image

Version

./stock_market.exe --version

or

./stock_market.exe -v

Basic Usage

./stock_market --name <STOCK_TICKER_NAME>

This shows the daily stock quotes for the last 6 months

Example

image

Usages with different range and interval

./stock_market --name <STOCK_TICKER_NAME> --range <range> --interval <interval>

Example

image

The above example works only if you supported ranges and intervals as shown in the below table.

Table for Supported Range and interval

image

References:

  1. ta
  2. chrono
  3. plotters
  4. yahoo_finance_api
  5. clap
  6. tokio
  7. lazy_static
  8. log
  9. log4rs