How to Give A Eulogy

A step-by-step guide on delivering a meaningful eulogy.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Using moving averages to predict stock prices

The objective is to predict the next day opening price of HDFC Bank on the basis of open, high, low, close, volume, 5DMA(5DMA is 5 days moving average), 10DMA, 20DMA, 50DMA. A comparative study is also conducted to check which moving average contributes to better accuracy.

Data contains date, open, high, low, close, volume, 5 days moving average, 10 days moving average, 20 days moving average, 50 days moving average and the next day open. Date is excluded for analysis.
Next day opening price is used as label and all the remaining attributes are used as features.

The visualisation is performed using Japanese Candle Stick Pattern and an additional line graph to plot the 5 days moving average. The entire plot is very difficult to understand in a single graph. demonstrates the entire data since 2015. It plots the OHLC and 5DMA. For simplicity purpose, data of the latest 100 days is plotted below which includes OHLC price and 5DMA. Green color indicates a positive day and red color indicates a negative day.

Latest 100 days OHLC and moving average
Latest 100 days in OHLC and 5DMA

We define a helper function which does not normalise the data by default and uses the data upto 4 decimals places. Open, high, low, close, volume, 5DMA, 10DMA, 20DMA and 50DMA are used as features. These are further split t include only specific moving averages. Label includes only the next day opening price of the stock. If normalise is set as true, individual columns will be divided by the column means so that majority of the data gets converted to single digit values. Single digit values are much easier to compute in terms of multiplication and division so that the computation time gets reduced. These column means too are returned by the function so that they can be multiplied to the single digit data for visualisation purpose.

Four Linear Regression models are developed. The models includes various moving averages at a time, i.e. one model uses 5DMA as a feature, next one use 10DMA as a feature and so on. Each model predicts the opening price of the stock for the next day. The results are mentioned below.

The Linear Regression model that uses 5DMA as a feature performs best with an accuracy of 88%. Below is the visualisation of the result.

Result of Linear Regression using 5DMA. It results in an accuracy of 88%.

Other Accuracies computed using 5 DMA, 10DMA, 20DMA and 50DMA are as follows

The above table shows how accuracy drops after considering higher moving averages.

Graphs for other moving averages are as follows.

Result of Linear Regression using 50DMA

A collective graph of all the results is as follows.

Comparative analysis of all the results

Smaller moving averages contribute to higher accuracy when used as a feature to predict the opening price of the next day. As higher moving averages are considered as features, the accuracy of the Linear Regression model drops.

Add a comment

Related posts:

A Rising Photographer Says Art Is for Everyone

With reverence to the greats like Sally Mann, our ‘Muse of the Week’ is a photographer who believes photography is a skillful art that can still be for everyone. BENZPHOTOGRAPHY* works freelance…

LA Lockdown Volume 1

Welcome to the first edition of my new quarantine-inspired mailbag. I’ll be posting these every Monday for the foreseeable future, covering anything and everything. Kat and I got an Oculus Go VR…

The Rise of Women In Politics

Greta Thunberg is a 16-year-old Swedish student and climate activist. She defines herself as a messenger and catalyst in the climate crisis revolution. In August 2018, Greta began a school strike…