{"id":45,"date":"2020-03-04T11:49:00","date_gmt":"2020-03-04T11:49:00","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=45"},"modified":"2025-02-05T12:48:18","modified_gmt":"2025-02-05T12:48:18","slug":"i-tried-using-deep-learning-to-predict-the-stock-market","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market","title":{"rendered":"I Tried Using Deep Learning to Predict the Stock Market"},"content":{"rendered":"\n<p>I magine being able to know when a stock is heading up or going down in the next week and then with the remaining cash you have, you would put all of your money to invest or short that stock. After playing the stock market with the knowledge of whether or not the stock will increase or decrease in value, you might end up a millionaire!<\/p>\n\n\n\n<p>Unfortunately, this is impossible because no one can know the future. However, we&nbsp;<em>can<\/em>&nbsp;make estimated guesses and informed forecasts based on the information we have in the present and the past regarding any stock. An estimated guess from past movements and patterns in stock price is called&nbsp;<a href=\"https:\/\/www.investopedia.com\/terms\/t\/technicalanalysis.asp\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Technical Analysis<\/strong><\/a>. We can use Technical Analysis (<em>TA<\/em>)to predict a stock\u2019s price direction, however, this is not 100% accurate. In fact, some traders criticize TA and have said that it is just as effective in predicting the future as Astrology. But there are other traders out there who swear by it and have established long successful trading careers.<\/p>\n\n\n\n<p>In our case, the Neural Network we will be using will utilize TA to help it make informed predictions. The specific Neural Network we will implement is called a&nbsp;<a href=\"https:\/\/pathmind.com\/wiki\/lstm\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Recurrent Neural Network \u2014 LSTM<\/strong><\/a>. Previously we utilized an RNN to predict Bitcoin prices (<em>see article below<\/em>): <a href=\"https:\/\/towardsdatascience.com\/predicting-bitcoin-prices-with-deep-learning-438bc3cf9a6f\">https:\/\/towardsdatascience.com\/predicting-bitcoin-prices-with-deep-learning-438bc3cf9a6f<\/a><\/p>\n\n\n\n<p>In the article, we explored the usage of LSTM to predict Bitcoin prices. We delved a little bit into the background of an LSTM model and gave instructions on how to program one to predict BTC prices. However, we limited the input data to Bitcoin\u2019s own price history and did not include other variables like technical indicators such as volume or moving averages.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6623\">Multivariable Input<\/h2>\n\n\n\n<p id=\"31ea\">Since the last RNN we constructed could only take in one sequence (past closing prices) to predict the future, we wanted to see if it would be possible to add even more data to the Neural Network. Maybe these other pieces of data could enhance our price forecasts? Perhaps by adding in TA indicators to our dataset, the Neural Network might be able to make much more accurate predictions? \u2014 Which is exactly what we want to accomplish here.<\/p>\n\n\n\n<p id=\"3c95\">In the next few sections, we will be constructing a new&nbsp;<em>Recurrent Neural Network&nbsp;<\/em>with the capability to take in not just one piece but multiple pieces of information in the form of&nbsp;<em>technical indicators<\/em>&nbsp;in order to forecast future prices in the stock market.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Price History and Technical Indicators<\/h2>\n\n\n\n<p id=\"3721\">In order to use a Neural Network to predict the stock market, we will be utilizing prices from the&nbsp;<strong><em>SPDR S&amp;P 500 (SPY)<\/em><\/strong>. This will give us a general overview of the stock market and by using an RNN we might be able to figure out which direction the market is heading.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"0f39\">Downloading Price History<\/h3>\n\n\n\n<p id=\"58e4\">To retrieve the right data for our Neural Network, you will need to head over to Yahoo Finance and&nbsp;<a href=\"https:\/\/finance.yahoo.com\/quote\/SPY\/history?p=SPY\" rel=\"noreferrer noopener\" target=\"_blank\"><em>download the prices for SPY<\/em><\/a>. We will be downloading five years worth of price history for SPY as a convenient&nbsp;<code>.csv<\/code>&nbsp;file.<\/p>\n\n\n\n<p id=\"67b4\">Another option would be to use a financial data API such as&nbsp;<a href=\"https:\/\/eodhistoricaldata.com\/r\/?ref=31CX3ILN\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>EOD Historical Data<\/strong><\/a>. It is free to sign up and you\u2019ll have access to vast amounts of datasets.&nbsp;<em>Disclosure: I earn a small commission from any purchases made through the link above.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ce49\">Technical Indicators<\/h3>\n\n\n\n<p id=\"c205\">After we have downloaded the price history for SPY, we can apply a Technical Analysis Python library to produce the Technical Indicator values. A more in depth look into the process from which we were able to retrieve the indicator values was covered here: <a href=\"https:\/\/towardsdatascience.com\/technical-indicators-on-bitcoin-using-python-c392b4a33810\">https:\/\/towardsdatascience.com\/technical-indicators-on-bitcoin-using-python-c392b4a33810<\/a><\/p>\n\n\n\n<p>The article above goes over the exact TA Python library we utilized in order to retrieve the indicator values for SPY.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3082\">Coding the Neural Network<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3ef4\">Import Libraries<\/h3>\n\n\n\n<p id=\"f5ad\">Let\u2019s begin coding out our Neural Network by first importing some libraries:<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist102695596\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-rnn_lib-py\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-python  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"rnn_lib.py content, created by marcosan93 on 05:11PM on April 28, 2020.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"rnn_lib.py\">\n        <tr>\n          <td id=\"file-rnn_lib-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-rnn_lib-py-LC1\" class=\"blob-code blob-code-inner js-file-line\"># Importing Libraries<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-rnn_lib-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">import numpy as np<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-rnn_lib-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">import matplotlib.pyplot as plt<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-rnn_lib-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">import pandas as pd<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-rnn_lib-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">from datetime import timedelta<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-rnn_lib-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">from sklearn.preprocessing import RobustScaler<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-rnn_lib-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">plt.style.use(&quot;bmh&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-rnn_lib-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-rnn_lib-py-LC9\" class=\"blob-code blob-code-inner js-file-line\"># Technical Analysis library<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-rnn_lib-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">import ta<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-rnn_lib-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-rnn_lib-py-LC12\" class=\"blob-code blob-code-inner js-file-line\"># Neural Network library<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-rnn_lib-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">from keras.models import Sequential<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-rnn_lib-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">from keras.layers import LSTM, Dense, Dropout<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-rnn_lib-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-rnn_lib-py-LC16\" class=\"blob-code blob-code-inner js-file-line\"># Loading in the Data<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_lib-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-rnn_lib-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">df = pd.read_csv(&quot;SPY.csv&quot;)<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/643c8039c1b25914ed24f31259deeb64\/raw\/f42400d0c33cfe365058f83246e32832990a7b10\/rnn_lib.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/643c8039c1b25914ed24f31259deeb64#file-rnn_lib-py\" class=\"Link--inTextBlock\">\n          rnn_lib.py\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n\n\n\n\n<p>First, we imported some of the usual Python libraries (<em>numpy, pandas, etc<\/em>). Next, we imported the technical analysis library we previously utilized to create Technical Indicators for BTC (<em>covered in the article above<\/em>). Then, we imported the Neural Network library from&nbsp;<a href=\"https:\/\/www.tensorflow.org\/guide\/keras\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Tensorflow Keras<\/strong><\/a>. After importing the necessary libraries, we\u2019ll load in the&nbsp;<code>SPY.csv<\/code>&nbsp;file we downloaded from&nbsp;<em>Yahoo Finance<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preprocessing the Data<a href=\"https:\/\/towardsdatascience.com\/predicting-bitcoin-prices-with-deep-learning-438bc3cf9a6f\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/h2>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist102695819\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-rnn_preprocessing-py\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-python  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"rnn_preprocessing.py content, created by marcosan93 on 05:22PM on April 28, 2020.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"rnn_preprocessing.py\">\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">## Datetime conversion<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">df[&#39;Date&#39;] = pd.to_datetime(df.Date)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC4\" class=\"blob-code blob-code-inner js-file-line\"># Setting the index<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">df.set_index(&#39;Date&#39;, inplace=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC7\" class=\"blob-code blob-code-inner js-file-line\"># Dropping any NaNs<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">df.dropna(inplace=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">## Technical Indicators<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC14\" class=\"blob-code blob-code-inner js-file-line\"># Adding all the indicators<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">df = ta.add_all_ta_features(df, open=&quot;Open&quot;, high=&quot;High&quot;, low=&quot;Low&quot;, close=&quot;Close&quot;, volume=&quot;Volume&quot;, fillna=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC17\" class=\"blob-code blob-code-inner js-file-line\"># Dropping everything else besides &#39;Close&#39; and the Indicators<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">df.drop([&#39;Open&#39;, &#39;High&#39;, &#39;Low&#39;, &#39;Adj Close&#39;, &#39;Volume&#39;], axis=1, inplace=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC20\" class=\"blob-code blob-code-inner js-file-line\"># Only using the last 1000 days of data to get a more accurate representation of the current market climate<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">df = df.tail(1000)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">## Scaling<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC27\" class=\"blob-code blob-code-inner js-file-line\"># Scale fitting the close prices separately for inverse_transformations purposes later<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">close_scaler = RobustScaler()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">close_scaler.fit(df[[&#39;Close&#39;]])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC32\" class=\"blob-code blob-code-inner js-file-line\"># Normalizing\/Scaling the DF<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">scaler = RobustScaler()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC34\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_preprocessing-py-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-rnn_preprocessing-py-LC35\" class=\"blob-code blob-code-inner js-file-line\">df = pd.DataFrame(scaler.fit_transform(df), columns=df.columns, index=df.index)<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/8c27af1f1a4d183ed899b0c91acf25a3\/raw\/d2d69bf5ce6d3306e6a7ead964b33cfbdf936736\/rnn_preprocessing.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/8c27af1f1a4d183ed899b0c91acf25a3#file-rnn_preprocessing-py\" class=\"Link--inTextBlock\">\n          rnn_preprocessing.py\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5adf\">Datetime Conversion<\/h3>\n\n\n\n<p id=\"26fe\">After loading in the data, we\u2019ll need to perform some preprocessing in order to prepare our data for the neural network and one of the first things we\u2019ll need to do is convert the DataFrame\u2019s index into the Datetime format. Then we will set the&nbsp;<code>Date<\/code>&nbsp;column in our data as the index for the DF.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"eaf1\">Creating Technical Indicators<\/h3>\n\n\n\n<p id=\"c1c1\">Next, we\u2019ll create some technical indicators by using the&nbsp;<code>ta<\/code>&nbsp;library. To cover as much technical analysis as possible, we\u2019ll use&nbsp;<em>all<\/em>&nbsp;the indicators available to us from the library. Then, drop everything else besides the&nbsp;<em>indicators<\/em>&nbsp;and the&nbsp;<em>Closing<\/em>&nbsp;<em>prices<\/em>&nbsp;from the dataset.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"a40f\">Recent Data<\/h3>\n\n\n\n<p id=\"f4d4\">Once we have created the technical indicator values, we can then eliminate some rows from our original dataset. We will only be including the last 1000 rows of data in order to have a more accurate representation of the current market climate.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"a3e0\">Scaling the Data<\/h3>\n\n\n\n<p id=\"ed2f\">When scaling our data, there are multiple approaches to take to make sure our data is still accurately represented. It may be useful to experiment with different scalers to see their effect on model performance.<\/p>\n\n\n\n<p id=\"1f89\">In our case, we will be utilizing&nbsp;<code>RobustScaler<\/code>&nbsp;to scale our data. This is done so that extreme outliers will have little effect and hopefully improve training time and overall model performance.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_lH0YFSyJ5fuMfY9TWhN3lQ-1024x356.png\" alt=\"\" class=\"wp-image-54\"\/><figcaption class=\"wp-element-caption\">Closing Prices Scaled using Robust Scaler<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e246\">Helper Functions<\/h2>\n\n\n\n<p id=\"0630\">Before we start constructing the neural network, let\u2019s create some helper functions to better optimize the process. We\u2019ll explain each function in detail.<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist102701208\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-rnn_helper-py\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-python  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"rnn_helper.py content, created by marcosan93 on 10:59PM on April 28, 2020.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"rnn_helper.py\">\n        <tr>\n          <td id=\"file-rnn_helper-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-rnn_helper-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def split_sequence(seq, n_steps_in, n_steps_out):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-rnn_helper-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-rnn_helper-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    Splits the multivariate time sequence<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-rnn_helper-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-rnn_helper-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-rnn_helper-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    # Creating a list for both variables<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-rnn_helper-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">    X, y = [], []<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-rnn_helper-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-rnn_helper-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">    for i in range(len(seq)):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-rnn_helper-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-rnn_helper-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">        # Finding the end of the current sequence<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-rnn_helper-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">        end = i + n_steps_in<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-rnn_helper-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">        out_end = end + n_steps_out<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-rnn_helper-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-rnn_helper-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">        # Breaking out of the loop if we have exceeded the dataset&#39;s length<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-rnn_helper-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">        if out_end &gt; len(seq):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-rnn_helper-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">            break<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-rnn_helper-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-rnn_helper-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">        # Splitting the sequences into: x = past prices and indicators, y = prices ahead<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-rnn_helper-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">        seq_x, seq_y = seq[i:end, :], seq[end:out_end, 0]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-rnn_helper-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-rnn_helper-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">        X.append(seq_x)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-rnn_helper-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">        y.append(seq_y)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-rnn_helper-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-rnn_helper-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">    return np.array(X), np.array(y)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-rnn_helper-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-rnn_helper-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-rnn_helper-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">def visualize_training_results(results):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-rnn_helper-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-rnn_helper-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">    Plots the loss and accuracy for the training and testing data<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-rnn_helper-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-rnn_helper-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">    history = results.history<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-rnn_helper-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">    plt.figure(figsize=(16,5))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-rnn_helper-py-LC34\" class=\"blob-code blob-code-inner js-file-line\">    plt.plot(history[&#39;val_loss&#39;])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-rnn_helper-py-LC35\" class=\"blob-code blob-code-inner js-file-line\">    plt.plot(history[&#39;loss&#39;])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L36\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"36\"><\/td>\n          <td id=\"file-rnn_helper-py-LC36\" class=\"blob-code blob-code-inner js-file-line\">    plt.legend([&#39;val_loss&#39;, &#39;loss&#39;])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L37\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"37\"><\/td>\n          <td id=\"file-rnn_helper-py-LC37\" class=\"blob-code blob-code-inner js-file-line\">    plt.title(&#39;Loss&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L38\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"38\"><\/td>\n          <td id=\"file-rnn_helper-py-LC38\" class=\"blob-code blob-code-inner js-file-line\">    plt.xlabel(&#39;Epochs&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L39\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"39\"><\/td>\n          <td id=\"file-rnn_helper-py-LC39\" class=\"blob-code blob-code-inner js-file-line\">    plt.ylabel(&#39;Loss&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L40\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"40\"><\/td>\n          <td id=\"file-rnn_helper-py-LC40\" class=\"blob-code blob-code-inner js-file-line\">    plt.show()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L41\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"41\"><\/td>\n          <td id=\"file-rnn_helper-py-LC41\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L42\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"42\"><\/td>\n          <td id=\"file-rnn_helper-py-LC42\" class=\"blob-code blob-code-inner js-file-line\">    plt.figure(figsize=(16,5))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L43\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"43\"><\/td>\n          <td id=\"file-rnn_helper-py-LC43\" class=\"blob-code blob-code-inner js-file-line\">    plt.plot(history[&#39;val_accuracy&#39;])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L44\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"44\"><\/td>\n          <td id=\"file-rnn_helper-py-LC44\" class=\"blob-code blob-code-inner js-file-line\">    plt.plot(history[&#39;accuracy&#39;])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L45\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"45\"><\/td>\n          <td id=\"file-rnn_helper-py-LC45\" class=\"blob-code blob-code-inner js-file-line\">    plt.legend([&#39;val_accuracy&#39;, &#39;accuracy&#39;])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L46\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"46\"><\/td>\n          <td id=\"file-rnn_helper-py-LC46\" class=\"blob-code blob-code-inner js-file-line\">    plt.title(&#39;Accuracy&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L47\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"47\"><\/td>\n          <td id=\"file-rnn_helper-py-LC47\" class=\"blob-code blob-code-inner js-file-line\">    plt.xlabel(&#39;Epochs&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L48\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"48\"><\/td>\n          <td id=\"file-rnn_helper-py-LC48\" class=\"blob-code blob-code-inner js-file-line\">    plt.ylabel(&#39;Accuracy&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L49\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"49\"><\/td>\n          <td id=\"file-rnn_helper-py-LC49\" class=\"blob-code blob-code-inner js-file-line\">    plt.show()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L50\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"50\"><\/td>\n          <td id=\"file-rnn_helper-py-LC50\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L51\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"51\"><\/td>\n          <td id=\"file-rnn_helper-py-LC51\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L52\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"52\"><\/td>\n          <td id=\"file-rnn_helper-py-LC52\" class=\"blob-code blob-code-inner js-file-line\">def layer_maker(n_layers, n_nodes, activation, drop=None, d_rate=.5):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L53\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"53\"><\/td>\n          <td id=\"file-rnn_helper-py-LC53\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L54\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"54\"><\/td>\n          <td id=\"file-rnn_helper-py-LC54\" class=\"blob-code blob-code-inner js-file-line\">    Creates a specified number of hidden layers for an RNN<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L55\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"55\"><\/td>\n          <td id=\"file-rnn_helper-py-LC55\" class=\"blob-code blob-code-inner js-file-line\">    Optional: Adds regularization option - the dropout layer to prevent potential overfitting (if necessary)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L56\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"56\"><\/td>\n          <td id=\"file-rnn_helper-py-LC56\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L57\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"57\"><\/td>\n          <td id=\"file-rnn_helper-py-LC57\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L58\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"58\"><\/td>\n          <td id=\"file-rnn_helper-py-LC58\" class=\"blob-code blob-code-inner js-file-line\">    # Creating the specified number of hidden layers with the specified number of nodes<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L59\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"59\"><\/td>\n          <td id=\"file-rnn_helper-py-LC59\" class=\"blob-code blob-code-inner js-file-line\">    for x in range(1,n_layers+1):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L60\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"60\"><\/td>\n          <td id=\"file-rnn_helper-py-LC60\" class=\"blob-code blob-code-inner js-file-line\">        model.add(LSTM(n_nodes, activation=activation, return_sequences=True))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L61\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"61\"><\/td>\n          <td id=\"file-rnn_helper-py-LC61\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L62\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"62\"><\/td>\n          <td id=\"file-rnn_helper-py-LC62\" class=\"blob-code blob-code-inner js-file-line\">        # Adds a Dropout layer after every Nth hidden layer (the &#39;drop&#39; variable)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L63\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"63\"><\/td>\n          <td id=\"file-rnn_helper-py-LC63\" class=\"blob-code blob-code-inner js-file-line\">        try:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L64\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"64\"><\/td>\n          <td id=\"file-rnn_helper-py-LC64\" class=\"blob-code blob-code-inner js-file-line\">            if x % drop == 0:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L65\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"65\"><\/td>\n          <td id=\"file-rnn_helper-py-LC65\" class=\"blob-code blob-code-inner js-file-line\">                model.add(Dropout(d_rate))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L66\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"66\"><\/td>\n          <td id=\"file-rnn_helper-py-LC66\" class=\"blob-code blob-code-inner js-file-line\">        except:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L67\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"67\"><\/td>\n          <td id=\"file-rnn_helper-py-LC67\" class=\"blob-code blob-code-inner js-file-line\">            pass<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L68\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"68\"><\/td>\n          <td id=\"file-rnn_helper-py-LC68\" class=\"blob-code blob-code-inner js-file-line\">          <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L69\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"69\"><\/td>\n          <td id=\"file-rnn_helper-py-LC69\" class=\"blob-code blob-code-inner js-file-line\">          <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L70\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"70\"><\/td>\n          <td id=\"file-rnn_helper-py-LC70\" class=\"blob-code blob-code-inner js-file-line\">def validater(n_per_in, n_per_out):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L71\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"71\"><\/td>\n          <td id=\"file-rnn_helper-py-LC71\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L72\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"72\"><\/td>\n          <td id=\"file-rnn_helper-py-LC72\" class=\"blob-code blob-code-inner js-file-line\">    Runs a &#39;For&#39; loop to iterate through the length of the DF and create predicted values for every stated interval<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L73\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"73\"><\/td>\n          <td id=\"file-rnn_helper-py-LC73\" class=\"blob-code blob-code-inner js-file-line\">    Returns a DF containing the predicted values for the model with the corresponding index values based on a business day frequency<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L74\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"74\"><\/td>\n          <td id=\"file-rnn_helper-py-LC74\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L75\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"75\"><\/td>\n          <td id=\"file-rnn_helper-py-LC75\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L76\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"76\"><\/td>\n          <td id=\"file-rnn_helper-py-LC76\" class=\"blob-code blob-code-inner js-file-line\">    # Creating an empty DF to store the predictions<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L77\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"77\"><\/td>\n          <td id=\"file-rnn_helper-py-LC77\" class=\"blob-code blob-code-inner js-file-line\">    predictions = pd.DataFrame(index=df.index, columns=[df.columns[0]])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L78\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"78\"><\/td>\n          <td id=\"file-rnn_helper-py-LC78\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L79\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"79\"><\/td>\n          <td id=\"file-rnn_helper-py-LC79\" class=\"blob-code blob-code-inner js-file-line\">    for i in range(n_per_in, len(df)-n_per_in, n_per_out):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L80\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"80\"><\/td>\n          <td id=\"file-rnn_helper-py-LC80\" class=\"blob-code blob-code-inner js-file-line\">        # Creating rolling intervals to predict off of<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L81\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"81\"><\/td>\n          <td id=\"file-rnn_helper-py-LC81\" class=\"blob-code blob-code-inner js-file-line\">        x = df[-i - n_per_in:-i]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L82\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"82\"><\/td>\n          <td id=\"file-rnn_helper-py-LC82\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L83\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"83\"><\/td>\n          <td id=\"file-rnn_helper-py-LC83\" class=\"blob-code blob-code-inner js-file-line\">        # Predicting using rolling intervals<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L84\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"84\"><\/td>\n          <td id=\"file-rnn_helper-py-LC84\" class=\"blob-code blob-code-inner js-file-line\">        yhat = model.predict(np.array(x).reshape(1, n_per_in, n_features))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L85\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"85\"><\/td>\n          <td id=\"file-rnn_helper-py-LC85\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L86\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"86\"><\/td>\n          <td id=\"file-rnn_helper-py-LC86\" class=\"blob-code blob-code-inner js-file-line\">        # Transforming values back to their normal prices<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L87\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"87\"><\/td>\n          <td id=\"file-rnn_helper-py-LC87\" class=\"blob-code blob-code-inner js-file-line\">        yhat = close_scaler.inverse_transform(yhat)[0]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L88\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"88\"><\/td>\n          <td id=\"file-rnn_helper-py-LC88\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L89\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"89\"><\/td>\n          <td id=\"file-rnn_helper-py-LC89\" class=\"blob-code blob-code-inner js-file-line\">        # DF to store the values and append later, frequency uses business days<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L90\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"90\"><\/td>\n          <td id=\"file-rnn_helper-py-LC90\" class=\"blob-code blob-code-inner js-file-line\">        pred_df = pd.DataFrame(yhat, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L91\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"91\"><\/td>\n          <td id=\"file-rnn_helper-py-LC91\" class=\"blob-code blob-code-inner js-file-line\">                               index=pd.date_range(start=x.index[-1], <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L92\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"92\"><\/td>\n          <td id=\"file-rnn_helper-py-LC92\" class=\"blob-code blob-code-inner js-file-line\">                                                   periods=len(yhat), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L93\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"93\"><\/td>\n          <td id=\"file-rnn_helper-py-LC93\" class=\"blob-code blob-code-inner js-file-line\">                                                   freq=&quot;B&quot;),<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L94\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"94\"><\/td>\n          <td id=\"file-rnn_helper-py-LC94\" class=\"blob-code blob-code-inner js-file-line\">                               columns=[x.columns[0]])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L95\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"95\"><\/td>\n          <td id=\"file-rnn_helper-py-LC95\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L96\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"96\"><\/td>\n          <td id=\"file-rnn_helper-py-LC96\" class=\"blob-code blob-code-inner js-file-line\">        # Updating the predictions DF<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L97\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"97\"><\/td>\n          <td id=\"file-rnn_helper-py-LC97\" class=\"blob-code blob-code-inner js-file-line\">        predictions.update(pred_df)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L98\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"98\"><\/td>\n          <td id=\"file-rnn_helper-py-LC98\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L99\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"99\"><\/td>\n          <td id=\"file-rnn_helper-py-LC99\" class=\"blob-code blob-code-inner js-file-line\">    return predictions<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L100\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"100\"><\/td>\n          <td id=\"file-rnn_helper-py-LC100\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L101\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"101\"><\/td>\n          <td id=\"file-rnn_helper-py-LC101\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L102\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"102\"><\/td>\n          <td id=\"file-rnn_helper-py-LC102\" class=\"blob-code blob-code-inner js-file-line\">def val_rmse(df1, df2):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L103\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"103\"><\/td>\n          <td id=\"file-rnn_helper-py-LC103\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L104\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"104\"><\/td>\n          <td id=\"file-rnn_helper-py-LC104\" class=\"blob-code blob-code-inner js-file-line\">    Calculates the root mean square error between the two Dataframes<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L105\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"105\"><\/td>\n          <td id=\"file-rnn_helper-py-LC105\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L106\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"106\"><\/td>\n          <td id=\"file-rnn_helper-py-LC106\" class=\"blob-code blob-code-inner js-file-line\">    df = df1.copy()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L107\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"107\"><\/td>\n          <td id=\"file-rnn_helper-py-LC107\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L108\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"108\"><\/td>\n          <td id=\"file-rnn_helper-py-LC108\" class=\"blob-code blob-code-inner js-file-line\">    # Adding a new column with the closing prices from the second DF<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L109\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"109\"><\/td>\n          <td id=\"file-rnn_helper-py-LC109\" class=\"blob-code blob-code-inner js-file-line\">    df[&#39;close2&#39;] = df2.Close<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L110\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"110\"><\/td>\n          <td id=\"file-rnn_helper-py-LC110\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L111\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"111\"><\/td>\n          <td id=\"file-rnn_helper-py-LC111\" class=\"blob-code blob-code-inner js-file-line\">    # Dropping the NaN values<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L112\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"112\"><\/td>\n          <td id=\"file-rnn_helper-py-LC112\" class=\"blob-code blob-code-inner js-file-line\">    df.dropna(inplace=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L113\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"113\"><\/td>\n          <td id=\"file-rnn_helper-py-LC113\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L114\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"114\"><\/td>\n          <td id=\"file-rnn_helper-py-LC114\" class=\"blob-code blob-code-inner js-file-line\">    # Adding another column containing the difference between the two DFs&#39; closing prices<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L115\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"115\"><\/td>\n          <td id=\"file-rnn_helper-py-LC115\" class=\"blob-code blob-code-inner js-file-line\">    df[&#39;diff&#39;] = df.Close - df.close2<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L116\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"116\"><\/td>\n          <td id=\"file-rnn_helper-py-LC116\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L117\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"117\"><\/td>\n          <td id=\"file-rnn_helper-py-LC117\" class=\"blob-code blob-code-inner js-file-line\">    # Squaring the difference and getting the mean<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L118\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"118\"><\/td>\n          <td id=\"file-rnn_helper-py-LC118\" class=\"blob-code blob-code-inner js-file-line\">    rms = (df[[&#39;diff&#39;]]**2).mean()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L119\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"119\"><\/td>\n          <td id=\"file-rnn_helper-py-LC119\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L120\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"120\"><\/td>\n          <td id=\"file-rnn_helper-py-LC120\" class=\"blob-code blob-code-inner js-file-line\">    # Returning the sqaure root of the root mean square<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L121\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"121\"><\/td>\n          <td id=\"file-rnn_helper-py-LC121\" class=\"blob-code blob-code-inner js-file-line\">    return float(np.sqrt(rms))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_helper-py-L122\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"122\"><\/td>\n          <td id=\"file-rnn_helper-py-LC122\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/c69f3906c5311d07a48f86a31c52a5cf\/raw\/ebd1f7517b65222fa06644571100b2c11d844a8d\/rnn_helper.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/c69f3906c5311d07a48f86a31c52a5cf#file-rnn_helper-py\" class=\"Link--inTextBlock\">\n          rnn_helper.py\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>split_sequence<\/code>&nbsp;\u2014 This function splits a multivariate time sequence. In our case, the input values are going to be the&nbsp;<em>Closing<\/em>&nbsp;prices and&nbsp;<em>indicators<\/em>&nbsp;for a stock. This will split the values into our&nbsp;<strong><em>X<\/em><\/strong>&nbsp;and&nbsp;<strong><em>y<\/em><\/strong>&nbsp;variables. The&nbsp;<strong><em>X<\/em><\/strong>&nbsp;values will contain the past closing prices and technical indicators. The&nbsp;<strong><em>y<\/em><\/strong>&nbsp;values will contain our target values (<em>future closing prices only<\/em>).<\/li>\n\n\n\n<li><code>visualize_training_results<\/code>&nbsp;\u2014 This function will help us evaluate the Neural Network we just created. The thing we are looking for when evaluating our NN is&nbsp;<strong><em>convergence<\/em><\/strong>. The validation values and regular values for&nbsp;<strong>Loss<\/strong>&nbsp;and&nbsp;<strong>Accuracy<\/strong>&nbsp;must start to&nbsp;<em>align<\/em>&nbsp;as training progresses. If they do not converge, then that may be a sign of overfitting\/underfitting. We must go back and modify the construction of the NN, which means to alter the number of layers\/nodes, change the optimizer function, etc.<\/li>\n\n\n\n<li><code>layer_maker<\/code>&nbsp;\u2014 This function constructs the body of our NN. Here we can customize the number of layers and nodes. It also has a regularization option of adding Dropout layers if necessary to prevent overfitting\/underfitting.<\/li>\n\n\n\n<li><code>validater<\/code>&nbsp;\u2014 This function creates a DF with predicted values for a specific range of dates. This range rolls forward with each loop. The intervals for the range are customizable. We use this DF to evaluate the model\u2019s predictions by comparing them to the actual values later on.<\/li>\n\n\n\n<li><code>val_rmse<\/code>&nbsp;\u2014 This function will return the root mean squared error (<em>RMSE<\/em>) of our model\u2019s predictions compared to the actual values. The value returned represents how far off our model\u2019s predictions are on average. The general goal is to reduce the RMSE of our model\u2019s predictions.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"993e\">Splitting the Data<\/h2>\n\n\n\n<p id=\"f86b\">In order to appropriately format our data, we will need to split the data into two sequences. The length of these sequences can be modified but we will be using the values from the last 90 days to predict prices for the next 30 days. The&nbsp;<code>split_sequence<\/code>&nbsp;function will then format our data into the appropriate&nbsp;<strong><em>X<\/em><\/strong>&nbsp;and&nbsp;<strong><em>y<\/em><\/strong>&nbsp;variables where&nbsp;<strong><em>X<\/em><\/strong>&nbsp;contains the closing prices&nbsp;<em>and<\/em>&nbsp;indicators for the past 90 days and&nbsp;<strong><em>y<\/em><\/strong>&nbsp;contains the closing prices for the next 30 days.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\"># How many periods looking back to learn\nn_per_in  = 90\n\n# How many periods to predict\nn_per_out = 30\n\n# Features \nn_features = df.shape[1]\n\n# Splitting the data into appropriate sequences\nX, y = split_sequence(df.to_numpy(), n_per_in, n_per_out)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>What our NN will do with this information is&nbsp;<em>learn<\/em>&nbsp;how the last 90 days of closing prices and technical indicator values&nbsp;<em>affect<\/em>&nbsp;the next 30 days of closing prices.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"b111\">Neural Network Modeling<\/h2>\n\n\n\n<p id=\"afb6\">Now we can begin constructing our Neural Network! The following code is how we construct our NN with custom layers and nodes.<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist102804948\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-rnn_model-py\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-python  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"rnn_model.py content, created by marcosan93 on 07:04PM on May 03, 2020.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"rnn_model.py\">\n        <tr>\n          <td id=\"file-rnn_model-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-rnn_model-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">## Creating the NN<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-rnn_model-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-rnn_model-py-LC3\" class=\"blob-code blob-code-inner js-file-line\"># Instatiating the model<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-rnn_model-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">model = Sequential()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-rnn_model-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-rnn_model-py-LC6\" class=\"blob-code blob-code-inner js-file-line\"># Activation<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-rnn_model-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">activ = &quot;tanh&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-rnn_model-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-rnn_model-py-LC9\" class=\"blob-code blob-code-inner js-file-line\"># Input layer<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-rnn_model-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">model.add(LSTM(90, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-rnn_model-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">               activation=activ, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-rnn_model-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">               return_sequences=True, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-rnn_model-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">               input_shape=(n_per_in, n_features)))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-rnn_model-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-rnn_model-py-LC15\" class=\"blob-code blob-code-inner js-file-line\"># Hidden layers<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-rnn_model-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">layer_maker(n_layers=1, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-rnn_model-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">            n_nodes=30, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-rnn_model-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">            activation=activ)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-rnn_model-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-rnn_model-py-LC20\" class=\"blob-code blob-code-inner js-file-line\"># Final Hidden layer<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-rnn_model-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">model.add(LSTM(60, activation=activ))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-rnn_model-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-rnn_model-py-LC23\" class=\"blob-code blob-code-inner js-file-line\"># Output layer<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-rnn_model-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">model.add(Dense(n_per_out))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-rnn_model-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-rnn_model-py-LC26\" class=\"blob-code blob-code-inner js-file-line\"># Model summary<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-rnn_model-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">model.summary()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-rnn_model-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-rnn_model-py-LC29\" class=\"blob-code blob-code-inner js-file-line\"># Compiling the data with selected specifications<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-rnn_model-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">model.compile(optimizer=&#39;adam&#39;, loss=&#39;mse&#39;, metrics=[&#39;accuracy&#39;])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-rnn_model-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-rnn_model-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">## Fitting and Training<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_model-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-rnn_model-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">res = model.fit(X, y, epochs=50, batch_size=128, validation_split=0.1)<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/d56c2d72b03f71d5bc34b1ddd6b02ffd\/raw\/12eade5e6bf5a8640241a87420caf41b009e7841\/rnn_model.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/d56c2d72b03f71d5bc34b1ddd6b02ffd#file-rnn_model-py\" class=\"Link--inTextBlock\">\n          rnn_model.py\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n\n\n\n\n<p id=\"fa95\">This is where we begin experimenting with the parameters for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Number of Layers<\/li>\n\n\n\n<li>Number of Nodes<\/li>\n\n\n\n<li>Different Activation functions<\/li>\n\n\n\n<li>Different Optimizers<\/li>\n\n\n\n<li>Number of Epochs and Batch Sizes<\/li>\n<\/ul>\n\n\n\n<p id=\"9b06\">The values we input for each of these parameters will have to be explored as each value can have a significant effect on the overall model\u2019s quality. There are probably methods out there to find the optimum values for each parameter. For our case we subjectively tested out different values for each parameter and the best ones we found can be seen in the code snippet above.<\/p>\n\n\n\n<p id=\"cccc\">If you wish to know more about the reasoning and concepts behind these variables, then it is suggested that you read our&nbsp;<a rel=\"noreferrer noopener\" target=\"_blank\" href=\"https:\/\/towardsdatascience.com\/predicting-bitcoin-prices-with-deep-learning-438bc3cf9a6f\"><em>previous article about Deep Learning and Bitcoin<\/em><\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"d1f2\">Visualizing Loss and Accuracy<\/h3>\n\n\n\n<p id=\"735b\">After training, we will visualize the progress of our Neural Network with our custom helper function:<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">visualize_training_results(res)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_n56dVJPMX9VxxuVYTiHfhw.png\" alt=\"\" class=\"wp-image-58\"\/><\/figure>\n\n\n\n<p id=\"8ae0\">As our network trains, we can see that the Loss decreasing and Accuracy increasing. As a general rule, we are looking for the two lines to&nbsp;<strong><em>converge or align<\/em><\/strong>&nbsp;together as the number of epochs increases. If they do not, then that is a sign that the model is inadequate and we will need to go back and change some parameters.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ffe8\">Model Validation<\/h3>\n\n\n\n<p id=\"309f\">Another way we can evaluate the quality of our model\u2019s predictions is to test it against the actual values and calculate the RMSE with our custom helper function:&nbsp;<code>val_rmse<\/code>.<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist102751766\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-rnn_valid-py\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-python  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"rnn_valid.py content, created by marcosan93 on 12:19AM on May 01, 2020.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"rnn_valid.py\">\n        <tr>\n          <td id=\"file-rnn_valid-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-rnn_valid-py-LC1\" class=\"blob-code blob-code-inner js-file-line\"># Transforming the actual values to their original price<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-rnn_valid-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">actual = pd.DataFrame(close_scaler.inverse_transform(df[[&quot;Close&quot;]]), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-rnn_valid-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">                      index=df.index, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-rnn_valid-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">                      columns=[df.columns[0]])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-rnn_valid-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-rnn_valid-py-LC6\" class=\"blob-code blob-code-inner js-file-line\"># Getting a DF of the predicted values to validate against<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-rnn_valid-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">predictions = validater(n_per_in, n_per_out)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-rnn_valid-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-rnn_valid-py-LC9\" class=\"blob-code blob-code-inner js-file-line\"># Printing the RMSE<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-rnn_valid-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">print(&quot;RMSE:&quot;, val_rmse(actual, predictions))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-rnn_valid-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-rnn_valid-py-LC12\" class=\"blob-code blob-code-inner js-file-line\"># Plotting<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-rnn_valid-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">plt.figure(figsize=(16,6))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-rnn_valid-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-rnn_valid-py-LC15\" class=\"blob-code blob-code-inner js-file-line\"># Plotting those predictions<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-rnn_valid-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">plt.plot(predictions, label=&#39;Predicted&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-rnn_valid-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-rnn_valid-py-LC18\" class=\"blob-code blob-code-inner js-file-line\"># Plotting the actual values<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-rnn_valid-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">plt.plot(actual, label=&#39;Actual&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-rnn_valid-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-rnn_valid-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">plt.title(f&quot;Predicted vs Actual Closing Prices&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-rnn_valid-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">plt.ylabel(&quot;Price&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-rnn_valid-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">plt.legend()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-rnn_valid-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">plt.xlim(&#39;2018-05&#39;, &#39;2020-05&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_valid-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-rnn_valid-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">plt.show()<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/48b4e95be5e9cacf0debd5f59768f2ae\/raw\/a9449d786845838227753fe7f27179728ec8aa38\/rnn_valid.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/48b4e95be5e9cacf0debd5f59768f2ae#file-rnn_valid-py\" class=\"Link--inTextBlock\">\n          rnn_valid.py\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_voMOjU43ybP5ARErIMZYkQ-1024x443.png\" alt=\"\" class=\"wp-image-60\"\/><\/figure>\n\n\n\n<p id=\"40c7\">Here we plot the predicted values with the actual values to see how well the compare. If the plot of the predicted values are extremely off and nowhere near the actual values, then we know that our model is deficient. However, if the values appear visually close and the RMSE is very low, then we can conclude that our model is acceptable.<\/p>\n\n\n\n<p id=\"fd16\">Our model seems to do well in the beginning but it cannot capture or model some intense movements in the price. This is probably why the last three predictions appear very far off. Perhaps with more training and experimentation our model could anticipate those movements.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1065\">Forecasting the Future<\/h2>\n\n\n\n<p id=\"8189\">Once we are satisfied with how well our model performs, then we can use it to predict future values. This part is fairly simply relative to what we have already done.<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist102751758\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-rnn_forecast-py\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-python  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"rnn_forecast.py content, created by marcosan93 on 12:18AM on May 01, 2020.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"rnn_forecast.py\">\n        <tr>\n          <td id=\"file-rnn_forecast-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC1\" class=\"blob-code blob-code-inner js-file-line\"># Predicting off of the most recent days from the original DF<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">yhat = model.predict(np.array(df.tail(n_per_in)).reshape(1, n_per_in, n_features))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC4\" class=\"blob-code blob-code-inner js-file-line\"># Transforming the predicted values back to their original format<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">yhat = close_scaler.inverse_transform(yhat)[0]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC7\" class=\"blob-code blob-code-inner js-file-line\"># Creating a DF of the predicted prices<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">preds = pd.DataFrame(yhat, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">                     index=pd.date_range(start=df.index[-1]+timedelta(days=1), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">                                         periods=len(yhat), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">                                         freq=&quot;B&quot;), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">                     columns=[df.columns[0]])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC14\" class=\"blob-code blob-code-inner js-file-line\"># Number of periods back to plot the actual values<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">pers = n_per_in<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC17\" class=\"blob-code blob-code-inner js-file-line\"># Transforming the actual values to their original price<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">actual = pd.DataFrame(close_scaler.inverse_transform(df[[&quot;Close&quot;]].tail(pers)), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">                      index=df.Close.tail(pers).index, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">                      columns=[df.columns[0]]).append(preds.head(1))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC22\" class=\"blob-code blob-code-inner js-file-line\"># Printing the predicted prices<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">print(preds)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC25\" class=\"blob-code blob-code-inner js-file-line\"># Plotting<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">plt.figure(figsize=(16,6))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">plt.plot(actual, label=&quot;Actual Prices&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">plt.plot(preds, label=&quot;Predicted Prices&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">plt.ylabel(&quot;Price&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">plt.xlabel(&quot;Dates&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">plt.title(f&quot;Forecasting the next {len(yhat)} days&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">plt.legend()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-rnn_forecast-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-rnn_forecast-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">plt.show()<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/159beef601e1f716d3d90f6883198508\/raw\/f65450f47530cbbe55f8ec8187e545542644058b\/rnn_forecast.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/159beef601e1f716d3d90f6883198508#file-rnn_forecast-py\" class=\"Link--inTextBlock\">\n          rnn_forecast.py\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n\n\n\n\n<p id=\"c170\">Here we are just predicting off of the most recent values we have from the downloaded&nbsp;<code>.csv<\/code>&nbsp;file. Once we run the code we are presented with the following forecast:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_0uRHKzBOYrwHw2zoJwu-BQ-1024x426.png\" alt=\"\" class=\"wp-image-61\"\/><figcaption class=\"wp-element-caption\">SPY price forecast for the next month<\/figcaption><\/figure>\n\n\n\n<p>And there we have it! \u2014 The forecasted prices for SPY. Do what you wish with this knowledge but remember one thing:&nbsp;<em>the stock market is unpredictable<\/em>. The values predicted here are&nbsp;<em>not<\/em>&nbsp;certain. They may be better than just randomly guessing since the values are educated guesses based on the Technical Indicators and price patterns from the past.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fa4e\">Closing<\/h2>\n\n\n\n<p id=\"cde2\">We were able to successfully construct a Recurrent Neural Network of LSTM layers that is able to take in multiple inputs rather than just one. The quality of the model may vary from person to person depending on how much time they wish to spend on it. These predictions can be extremely useful for those wishing to gain some insight into the future price movement of a stock even though predicting the future isn\u2019t possible. But, it is likely to believe that this way is better than randomly guessing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I magine being able to know when a stock is heading up or going down in the next week and then with the remaining cash you have, you would put all of your money to invest or short that stock. After playing the stock market with the knowledge of whether or not the stock will [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[62],"tags":[],"coding-language":[30],"ready-to-go-solution":[],"qualification":[31,32],"financial-apis-category":[36],"financial-apis-manuals":[38,40],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-stocks-price-prediction-examples","coding-language-python","qualification-experienced","qualification-guru","financial-apis-category-stock-market-prices","financial-apis-manuals-intraday","financial-apis-manuals-technical-indicators"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.9 (Yoast SEO v26.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Deep Learning to Predict Stock Market: Myth or Reality? | EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"Explore the fascinating world of using deep learning to predict stock market movements. Leverage the power of data to make informed investment choices\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"I Tried Using Deep Learning to Predict the Stock Market\" \/>\n<meta property=\"og:description\" content=\"Explore the fascinating world of using deep learning to predict stock market movements. Leverage the power of data to make informed investment choices\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market\" \/>\n<meta property=\"og:site_name\" content=\"Financial Academy\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/eodhistoricaldata\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-04T11:49:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T12:48:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2022\/03\/i-tried-using-deep-learning-to-predict-the-stock-market.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"450\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Marco Santos\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/_marco_santos_\" \/>\n<meta name=\"twitter:site\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marco Santos\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market\"},\"author\":{\"name\":\"Marco Santos\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/21a7f35c812f05fb7c4e60a624a3237d\"},\"headline\":\"I Tried Using Deep Learning to Predict the Stock Market\",\"datePublished\":\"2020-03-04T11:49:00+00:00\",\"dateModified\":\"2025-02-05T12:48:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market\"},\"wordCount\":2091,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_lH0YFSyJ5fuMfY9TWhN3lQ-1024x356.png\",\"articleSection\":[\"Stocks Price Predictions Examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market\",\"name\":\"Deep Learning to Predict Stock Market: Myth or Reality? | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_lH0YFSyJ5fuMfY9TWhN3lQ-1024x356.png\",\"datePublished\":\"2020-03-04T11:49:00+00:00\",\"dateModified\":\"2025-02-05T12:48:18+00:00\",\"description\":\"Explore the fascinating world of using deep learning to predict stock market movements. Leverage the power of data to make informed investment choices\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#primaryimage\",\"url\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_lH0YFSyJ5fuMfY9TWhN3lQ-1024x356.png\",\"contentUrl\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_lH0YFSyJ5fuMfY9TWhN3lQ-1024x356.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"I Tried Using Deep Learning to Predict the Stock Market\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"name\":\"Financial APIs Academy | EODHD\",\"description\":\"Financial Stock Market Academy\",\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\",\"name\":\"EODHD (EOD Historical Data)\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"width\":159,\"height\":82,\"caption\":\"EODHD (EOD Historical Data)\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/eodhistoricaldata\",\"https:\/\/x.com\/EOD_data\",\"https:\/\/www.reddit.com\/r\/EODHistoricalData\/\",\"https:\/\/eod-historical-data.medium.com\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/21a7f35c812f05fb7c4e60a624a3237d\",\"name\":\"Marco Santos\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c176ca2898e90e41837f2fe073b4001074052c63f3559b29e7e4ae9d7a048a1b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c176ca2898e90e41837f2fe073b4001074052c63f3559b29e7e4ae9d7a048a1b?s=96&d=mm&r=g\",\"caption\":\"Marco Santos\"},\"description\":\"NYC Data Scientist specializing in AI\/ML with a passion for code\",\"sameAs\":[\"http:\/\/linkedin.com\/in\/marco-s-santos\",\"https:\/\/x.com\/https:\/\/twitter.com\/_marco_santos_\"],\"url\":\"https:\/\/eodhd.com\/financial-academy\/author\/marcosantos\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Deep Learning to Predict Stock Market: Myth or Reality? | EODHD APIs Academy","description":"Explore the fascinating world of using deep learning to predict stock market movements. Leverage the power of data to make informed investment choices","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market","og_locale":"en_US","og_type":"article","og_title":"I Tried Using Deep Learning to Predict the Stock Market","og_description":"Explore the fascinating world of using deep learning to predict stock market movements. Leverage the power of data to make informed investment choices","og_url":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2020-03-04T11:49:00+00:00","article_modified_time":"2025-02-05T12:48:18+00:00","og_image":[{"width":800,"height":450,"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2022\/03\/i-tried-using-deep-learning-to-predict-the-stock-market.png","type":"image\/png"}],"author":"Marco Santos","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/_marco_santos_","twitter_site":"@EOD_data","twitter_misc":{"Written by":"Marco Santos","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market"},"author":{"name":"Marco Santos","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/21a7f35c812f05fb7c4e60a624a3237d"},"headline":"I Tried Using Deep Learning to Predict the Stock Market","datePublished":"2020-03-04T11:49:00+00:00","dateModified":"2025-02-05T12:48:18+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market"},"wordCount":2091,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#primaryimage"},"thumbnailUrl":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_lH0YFSyJ5fuMfY9TWhN3lQ-1024x356.png","articleSection":["Stocks Price Predictions Examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market","url":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market","name":"Deep Learning to Predict Stock Market: Myth or Reality? | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#primaryimage"},"thumbnailUrl":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_lH0YFSyJ5fuMfY9TWhN3lQ-1024x356.png","datePublished":"2020-03-04T11:49:00+00:00","dateModified":"2025-02-05T12:48:18+00:00","description":"Explore the fascinating world of using deep learning to predict stock market movements. Leverage the power of data to make informed investment choices","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#primaryimage","url":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_lH0YFSyJ5fuMfY9TWhN3lQ-1024x356.png","contentUrl":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_lH0YFSyJ5fuMfY9TWhN3lQ-1024x356.png"},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/i-tried-using-deep-learning-to-predict-the-stock-market#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"I Tried Using Deep Learning to Predict the Stock Market"}]},{"@type":"WebSite","@id":"https:\/\/eodhd.com\/financial-academy\/#website","url":"https:\/\/eodhd.com\/financial-academy\/","name":"Financial APIs Academy | EODHD","description":"Financial Stock Market Academy","publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/eodhd.com\/financial-academy\/#organization","name":"EODHD (EOD Historical Data)","url":"https:\/\/eodhd.com\/financial-academy\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","width":159,"height":82,"caption":"EODHD (EOD Historical Data)"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/eodhistoricaldata","https:\/\/x.com\/EOD_data","https:\/\/www.reddit.com\/r\/EODHistoricalData\/","https:\/\/eod-historical-data.medium.com\/"]},{"@type":"Person","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/21a7f35c812f05fb7c4e60a624a3237d","name":"Marco Santos","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c176ca2898e90e41837f2fe073b4001074052c63f3559b29e7e4ae9d7a048a1b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c176ca2898e90e41837f2fe073b4001074052c63f3559b29e7e4ae9d7a048a1b?s=96&d=mm&r=g","caption":"Marco Santos"},"description":"NYC Data Scientist specializing in AI\/ML with a passion for code","sameAs":["http:\/\/linkedin.com\/in\/marco-s-santos","https:\/\/x.com\/https:\/\/twitter.com\/_marco_santos_"],"url":"https:\/\/eodhd.com\/financial-academy\/author\/marcosantos"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-J","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":2,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":6268,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/45\/revisions\/6268"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=45"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=45"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=45"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=45"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=45"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}