# Advanced Markov-Based Machine Learning Framework for Making Adaptive Trading System

^{1}

^{2}

^{3}

^{*}

## Abstract

**:**

## 1. Introduction

#### 1.1. Stock Price Prediction Methods Prior Art: Classical Pipelines

#### 1.2. Stock Price Prediction Methods Prior Art: Recent Machine and Deep Learning Pipelines

#### 1.3. The Proposed Stock Price Prediction Systems: Brief Overview of Underlying Algorithm

## 2. The Overall Framework

#### 2.1. Stock Price Forecasting Problem

#### 2.2. Mathematical Background of LSTM

- ${\mathit{W}}_{\mathit{f}},{\mathit{W}}_{\mathit{i}},{\mathit{W}}_{\mathit{C}},{\mathit{W}}_{\mathit{o}}$ represent the LSTM weights
- ${\mathit{b}}_{\mathit{f}},{\mathit{b}}_{\mathit{i}},{\mathit{b}}_{\mathit{C}},{\mathit{b}}_{\mathit{o}}$ are the bias
- ${\mathit{C}}_{\mathit{t}}$ is the cell state
- $\mathit{\sigma}$ is the sigmoid function

## 3. The LSTMs Forecasting Framework: Description

^{t}

^{+1}depends of previous stock price value only y

^{t}, the related prediction error e

^{t}

^{+1}keeps same statistics, i.e., it satisfies Markov propriety so that the current stock price prediction error e

^{t}

^{+1}is correlated to previous ones e

^{t}only. We have applied this assumption to our prediction model based on LSTMs, as described in what follows. Formerly, we consider stock close price prediction made by the second LSTM pipeline, as pointed out in Figure 4.

^{t}to correct the current stock price forecasting process. Therefore, according to this clear consequence, we proceed correcting the stock close price prediction performed by our LSTM system ${\mathit{y}}^{\mathit{t}}$ as per Equation (9) with a part of previous stock close price prediction error, as reported below:

## 4. The Trading System Algorithm Block

**CRV**(Investment Amount): Total amount of invested money for buying or short selling the analyzed stocks.**N**(stock numbers): Number of shares. It is obtained by means of the following formula in which we have indicated, with_{s}**y**, the actual stock open price (13):_{open}$${\mathit{N}}_{\mathit{s}}=\mathit{r}\mathit{o}\mathit{u}\mathit{n}\mathit{d}\left(\frac{\mathit{C}\mathit{R}\mathit{V}}{{\mathit{y}}_{\mathit{o}\mathit{p}\mathit{e}\mathit{n}}}\right),$$**C**(trade commissions): applied commissions requested by the broker or bank engaged for executing/managing requested trades. It is often defined as a percentage of the CRV. In our experiments we supposed a classical value of 0.19% to be applied to CRV both during the opening and the closing of the requested trade._{s}

## 5. Experimental Results

_{update}) and without that correction, i.e., as it is performed by the trained LSTM only. From a simple analysis of the data reported in Table 1, the assumption made by the author improves, significantly, the overall prediction performance of the proposed approach. In Table 2, the authors report a further statistical comparisons index: The variance computed for the target stock price, as well as for the corresponding predicted ones (both with proposed Markov based correction “update” —and without that- “no update”), for each analyzed stock, in order to confirm how effective is our prediction model. As for Table 1, Table 2 reported statistic evaluations, confirm the robustness of the proposed approach. The benchmarks reported in Table 1 and Table 2 provide such statistic comparisons related to stock price forecasting. In order to improve that benchmark comparisons, we decided to evaluate the performance of the proposed approach by means of common robust indexes used in scientific literature for this purpose. The first comparison index we have used is described in Reference [18] where the authors presented an innovative LSTM-based approach to predict financial indexes with comparable prediction errors. In Reference [18], the authors showed an interesting benchmark comparison index suitable to evaluate the stock price prediction accuracy. In order to evaluate the proposed prediction algorithm of ups (LONG trend also knows as “Bullish”) and downs (SHORT trend also known as “Bearish”), the authors decided to calculate data accuracy by using the set of equation reported in Equations (16) and (17).

## 6. Conclusions and Future Works

## Author Contributions

## Funding

## Conflicts of Interest

## References

- Kim, K.; Han, I. Genetic Algorithms Approach to Feature Discretization in Artificial Neural Networks for the prediction of Stock Price Index. Expert Syst. Appl.
**2000**, 19, 125–132. [Google Scholar] [CrossRef] - Kimoto, T.; Asakawa, K.; Yoda, M. Stock Market Prediction System with Modular Neural Networks. In Proceedings of the 1990 IJCNN International Joint Conference on Neural Networks, San Diego, CA, USA, 17–21 June 1990. [Google Scholar]
- Wang, J.-H.; Leu, J.-Y. Stock market trend prediction using ARIMA-based neural networks. In Proceedings of the International Conference on Neural Networks (ICNN’96), Washington, DC, USA, 3–6 June 1996. [Google Scholar]
- Niaki, S.T.A.; Hoseinzade, S. Forecasting s&p 500 index using artificial neural networks and design of experiments. J. Ind. Eng. Int.
**2013**, 9, 1. [Google Scholar] - Nelson, D.M.Q.; Pereira, A.C.M.; de Oliveira, R.A. Stock market’s price movement prediction with LSTM neural networks. In Proceedings of the 2017 International Joint Conference on Neural Networks (IJCNN), Anchorage, AK, USA, 14–19 May 2017. [Google Scholar]
- Zhang, Z.; Shen, Y.; Zhang, G.; Song, Y.; Zhu, Y. Short-term Prediction for Opening Price of Stock Market Based on Self-adapting Variant PSO-Elman Neural Network. In Proceedings of the 2017 8th IEEE International Conference on Software Engineering and Service Science (ICSESS), Beijing, China, 24–26 November 2017. [Google Scholar]
- Kumar, I.; Dogra, K.; Utreja, C.; Yadav, P. A Comparative study of supervised machine learning algorithms for stock market trend prediction. In Proceedings of the 2018 Second International Conference on Inventive Communication and Computational Technologies (ICICCT), Coimbatore, India, 20–21 April 2018. [Google Scholar]
- Bollen, J.; Mao, H. Twitter mood as a stock market predictor. Computer
**2011**, 44, 91–94. [Google Scholar] [CrossRef] - Gers, F.A.; Schmidhuber, J. LSTM Recurrent Neural Networks Learn Simple Context Free and Context Sensitive Languages. IEEE Trans. Neural Netw.
**2001**, 12, 1333–1340. [Google Scholar] [CrossRef] [PubMed] - Diebold, F.X. Elements of Forecasting, 4th ed.; Thomson Learning: Belmont, CA, USA, 2007. [Google Scholar]
- Granger, C.; Newbold, P. Forecasting Transformed Series. J. R. Stat. Soc.
**2001**, 38, 189–203. [Google Scholar] [CrossRef] - Gers, F.A.; Schraudolph, N.N.; Schmidhuber, J. Learning precise timing with LSTM recurrent networks. J. Mach. Learn. Res.
**2003**, 3, 115–143. [Google Scholar] - Savvopoulos, A.; Kanavos, A.; Mylonas, P.; Sioutas, S. LSTM Accelerator for Convolutional Object Identification. Algorithms
**2018**, 11, 157. [Google Scholar] [CrossRef] - Yahoo Finance. Available online: https://it.finance.yahoo.com/ (accessed on 24 October 2018).
- Somani, P.; Talele, S.; Sawant, S. Stock Market Prediction Using Hidden Markov Model. In Proceedings of the 7th Joint International Information Technology and Artificial Intelligence Conference, Chongqing, China, 20–21 December 2014. [Google Scholar]
- Keras Documentation. Available online: https://keras.io/ (accessed on 24 October 2018).
- Tensorflow.org. Available online: https://www.tensorflow.org/ (accessed on 24 October 2018).
- Pang, X.; Zhou, Y.; Wang, P.; Lin, W.; Chang, V. An innovative neural network approach for stock market prediction. J. Supercomput.
**2018**, 1–21. [Google Scholar] [CrossRef] - Investopedia. Available online: https://www.investopedia.com/terms/d/drawdown.asp (accessed on 17 December 2018).
- Reid, D.; Hussain, A.J.; Tawfik, H. Spiking Neural Networks for Financial Data Prediction. In Proceedings of the 2013 International Joint Conference on Neural Networks (IJCNN), Dallas, TX, USA, 4–9 August 2013. [Google Scholar]
- Artificial Intelligence (AI)—STMicroelectronics. Available online: https://www.st.com/content/st_com/en/about/innovation---technology/artificial-intelligence.html (accessed on 17 December 2018).
- Rundo, F.; Conoci, S.; Ortis, A.; Battiato, S. An Advanced Bio-Inspired PhotoPlethysmoGraphy (PPG) and ECG Pattern Recognition System for Medical Assessment. Sensors
**2018**, 18, 405. [Google Scholar] [CrossRef] [PubMed] - Rundo, F.; Ortis, A.; Battiato, S.; Conoci, S. Advanced Bio-Inspired System for Noninvasive Cuff-Less Blood Pressure Estimation from Physiological Signal Analysis. Computation
**2018**, 6, 46. [Google Scholar] [CrossRef] - Rundo, F.; Conoci, S.; Banna, G.L.; Ortis, A.; Stanco, F.; Battiato, S. Evaluation of Levenberg–Marquardt neural networks and stacked autoencoders clustering for skin lesion analysis, screening and follow-up. IET Comput. Vis.
**2018**, 12, 957–996. [Google Scholar] [CrossRef] - Ortis, A.; Farinella, G.M.; Torrisi, G.; Battiato, S. Visual Sentiment Analysis Based on Objective Text Description of Images. In Proceedings of the International Conference on Content-Based Multimedia Indexing (CBMI), La Rochelle, France, 4–6 September 2018. [Google Scholar]

**Figure 13.**BMPS.MI Close Price time-serie (red: predicted without Markov correction; blue: real value).

**Figure 15.**ISP.MI Close Price time-serie (red: predicted without Markov correction; blue: real value).

**Table 1.**ENEL.MI, UCG.MI, BMPS.MI, CVAL.MI, and ISP.MI RMSE normalized in [0, 1] while enclosed in bracket corresponding not normalized.

ENEL.MI | UCG.MI | BMPS.MI | CVAL.MI | ISP.MI | |
---|---|---|---|---|---|

$\mathit{R}\mathit{M}\mathit{S}{\mathit{E}}_{\mathit{n}\mathit{o}\mathbf{\_}\mathit{u}\mathit{p}\mathit{d}\mathit{a}\mathit{t}\mathit{e}}$ | 0.030 (0.08132) | 0.0064 (0.75) | 0.0053 (30.0152) | 0.0067 (0.068) | 0.027 (0.06787) |

$\mathit{R}\mathit{M}\mathit{S}{\mathit{E}}_{\mathit{u}\mathit{p}\mathit{d}\mathit{a}\mathit{t}\mathit{e}}$ | 0.028 (0.07633) | 0.0060 (0.70) | 0.0052 (28.069) | 0.0060 (0.064) | 0.025 (0.0631) |

**Table 2.**ENEL.MI, UCG.MI, BMPS.MI, CVAL.MI, and ISP.MI Variance normalized in [0, 1] while enclosed in bracket corresponding not normalized

ENEL.MI | UCG.MI | BMPS.MI | CVAL.MI | ISP.MI | |
---|---|---|---|---|---|

$\mathit{V}\mathit{A}\mathit{R}\mathit{I}\mathit{A}\mathit{N}\mathit{C}{\mathit{E}}_{\mathit{t}\mathit{a}\mathit{r}\mathit{g}\mathit{e}\mathit{t}}$ | 0.0923 (0.66) | 0.00362 (47,6) | 0.004569 (147786) | 0.0055 (0.27) | 0.0732 (0.4542) |

$\mathit{V}\mathit{A}\mathit{R}\mathit{I}\mathit{A}\mathit{N}\mathit{C}{\mathit{E}}_{\mathit{n}\mathit{o}\mathbf{\_}\mathit{u}\mathit{p}\mathit{d}\mathit{a}\mathit{t}\mathit{e}}$ | 0.092 (0.65) | 0.00357 (46.5) | 0.00463 (147812) | 0.0054 (0.2451) | 0.0729 (0.4504) |

$\mathit{V}\mathit{A}\mathit{R}\mathit{I}\mathit{A}\mathit{N}\mathit{C}{\mathit{E}}_{\mathit{u}\mathit{p}\mathit{d}\mathit{a}\mathit{t}\mathit{e}}$ | 0.09221 (0.66) | 0.00360 (46.7) | 0.00462 (147619) | 0.0055 (0.2456) | 0.0730 (0.4509) |

ENEL.MI | UCG.MI | BMPS.MI | CVAL.MI | ISP.MI | |
---|---|---|---|---|---|

$\mathit{D}\mathit{a}\mathit{t}\mathit{a}\mathit{A}\mathit{c}\mathit{c}\mathit{u}\mathit{r}\mathit{a}\mathit{c}\mathit{y}$ | 0.501813 | 0.999412 | 0.510281 | 0.99402 | 0.50 |

ENEL.MI | UCG.MI | BMPS.MI | CVAL.MI | ISP.MI | |
---|---|---|---|---|---|

$\mathit{M}\mathit{a}\mathit{x}\mathit{i}\mathit{m}\mathit{u}\mathit{m}\mathit{D}\mathit{r}\mathit{a}\mathit{w}\mathit{d}\mathit{o}\mathit{w}\mathit{n}$ | −9.2350 | −3.3345 | −11.0911 | −4.0011 | −10.9876 |

© 2019 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Rundo, F.; Trenta, F.; Di Stallo, A.L.; Battiato, S. Advanced Markov-Based Machine Learning Framework for Making Adaptive Trading System. *Computation* **2019**, *7*, 4.
https://doi.org/10.3390/computation7010004

**AMA Style**

Rundo F, Trenta F, Di Stallo AL, Battiato S. Advanced Markov-Based Machine Learning Framework for Making Adaptive Trading System. *Computation*. 2019; 7(1):4.
https://doi.org/10.3390/computation7010004

**Chicago/Turabian Style**

Rundo, Francesco, Francesca Trenta, Agatino Luigi Di Stallo, and Sebastiano Battiato. 2019. "Advanced Markov-Based Machine Learning Framework for Making Adaptive Trading System" *Computation* 7, no. 1: 4.
https://doi.org/10.3390/computation7010004