This project repository describes and implementation of below Financial trading Algorithms
- Moving Average
- Bollinger Bands
In statistics a moving average is an algorithm that calculates the unweighted mean of the last n samples.
Types: Simple Moving Average (SMA) Exponential Moving Average (EMA)
- The SMA is a technical indicator for determining if an asset price will continue or reverse a bull or bear trend.
- The SMA is calculated as the arithmetic average of an asset's price over some period.
- The SMA can be enhanced as an exponential moving average (EMA) that more heavily weights recent price action.
Death Cross A short-term moving average breaks below a long-term moving average Golden Cross A short-term moving average breaks above a long-term moving average
Where Short-term moving average: 50 days Long-term moving average: 200 days
- The EMA is a moving average that places a greater weight and significance on the most recent data points.
- Like all moving averages, this technical indicator is used to produce buy and sell signals based on crossovers and divergences from the historical average.
- Traders often use several different EMA days, for instance, 20-day, 30-day, 90-day, and 200-day moving averages.
- Find the Initial EMA Value E.g., 14 + 13 + 14 + 12 + 13 = 66; 66 ÷ 5 = 13.2 So the SMA, which becomes your initial EMA value, is 13.2.
- Calculate the Weighting Multiplier (Smoothing Constant) 2 ÷ (number of time periods + 1) 2 ÷ (5 + 1) = 2 ÷ 6 = 0.3333
- Input That Information in the EMA Formula EMA = (closing price - previous day's EMA) × smoothing constant as a decimal + previous day's EMA EMA = (12 - 13.2) × 0.3333 + 13.2 EMA = 12.80 So the EMA value for day six is 12.80.
- If the closing value on day seven was $11, you'd repeat the process, using day six's value of 12.80 as the new "previous day's EMA." So the calculation for day seven is as follows: EMA = (11 - 12.8) × 0.3333 + 12.8 EMA = 12.20
- A Bollinger Band® is a technical analysis tool defined by a set of lines plotted two standard deviations (positively and negatively) away from a SMA of the security's price, but can be adjusted to user preferences.
- There are three lines that compose Bollinger Bands: A simple moving average (middle band) and an upper and lower band.
- The upper and lower bands are typically 2 standard deviations +/- from a 20-day simple moving average, but can be modified.
Download or clone the project into the local machine and edit the configuration file (config.json) by follow:
- Change the tradeURL with the your trading data provider URL.
- change the algorithm band period as per your need.
Once projct set up is done, running this project is much easier as like running python projects.
- Open the command prompt and navigate to the project location.
- type the below command to run this project.
python movingAverage.py
This command will run the project http://localhost:5000
URLs
- Simple Moving Average (SMA) - http://localhost:5000
- Exponential Moving Average (EMA) - http://localhost:5000/ema
- Bollinger Bands - http://localhost:5000/bollingerbands
Author: Shivakumar Ravichandran