{"id":67,"date":"2022-01-19T12:53:00","date_gmt":"2022-01-19T12:53:00","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=67"},"modified":"2025-02-05T13:23:56","modified_gmt":"2025-02-05T13:23:56","slug":"what-happens-if-you-day-trade-crypto-with-facebook-prophet","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet","title":{"rendered":"What Happens if you Day Trade Crypto with Facebook Prophet?"},"content":{"rendered":"\n<p>In the past, I\u2019ve experimented with various forms of machine learning models in order to develop a successful cryptocurrency trading strategy. These various strategies would utilize&nbsp;<a href=\"https:\/\/medium.com\/geekculture\/ai-crypto-trading-vs-buy-hold-11116bd8c18b\">classification models<\/a>,&nbsp;<a href=\"https:\/\/medium.com\/geekculture\/i-tested-facebooks-machine-learning-model-in-the-crypto-market-8a8aaf09564f\">time-series models<\/a>, and&nbsp;<a href=\"https:\/\/medium.com\/geekculture\/what-happens-when-you-trade-stocks-based-on-news-52c27960a1e5\">sentiment analysis<\/a>. The results of these strategies would range from mediocre to \u201cgood but requires more testing\u201d. I\u2019ve never settled on a specific strategy and hope to one day move on from the testing phase to \u201cactually implementing it with real money\u201d phase.<\/p>\n\n\n\n<p id=\"78b8\">In all of these different strategies, I have yet to change the frequency of the historical data tested. The frequency of data I have always used and backtested with was the&nbsp;<em>daily historical price data<\/em>. That frequency for price data is not bad at all but it is limited, especially with the around the clock trading availability of the cryptocurrency market.<\/p>\n\n\n\n<p id=\"08b8\">So in order to continue my testing, I\u2019ll need to know what it is like to day trade crypto with machine learning. Specifically, I\u2019ll be using a time series machine learning model that I have found to be easy to use and implement \u2014&nbsp;<em>Facebook Prophet<\/em>. Feel free to code along with me or just continue reading to see the final outcome.<\/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\">The Necessary Libraries and Data<\/h2>\n\n\n\n<p id=\"457a\">To begin, I\u2019ll need to import some libraries:<\/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\">from eod import EodHistoricalData\nimport pandas as pd\nfrom datetime import datetime, timedelta\nimport calendar\nfrom tqdm import tqdm\nimport numpy as np\nimport random\nimport plotly.express as px\nfrom prophet import Prophet<\/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>If you\u2019re familiar with data science, then you may recognize many of these libraries.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4e5e\">Crypto Intraday Price Data<\/h2>\n\n\n\n<p id=\"ad3a\">Next, I\u2019ll have to grab the intraday price data for a selected cryptocurrency. To do so, I utilized&nbsp;<a href=\"https:\/\/eodhistoricaldata.com\/?ref=31CX3ILN&amp;utm_source=medium&amp;utm_medium=post&amp;utm_campaign=what_happens_if_you_day_trade_crypto_with_facebook_prophet\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>a financial API service called EOD HD<\/strong><\/a>, which allows me to retrieve the historical price data of select cryptocurrencies at various time intervals.&nbsp;<em>Disclosure: I earn a small commission from any purchases made through the link above.<\/em><\/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\"># Importing and assigning the api key\nwith open(\"..\/..\/eodHistoricalData-API.txt\", \"r\") as f:\n    api_key = f.read()\n    \n# EOD Historical Data client\nclient = EodHistoricalData(api_key)<\/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 id=\"5a8f\">With my provided API key, I can now retrieve the hourly price data from assorted cryptocurrencies. For this project, I chose to focus on the most famous of crypto of them all \u2014&nbsp;<em>Bitcoin<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"37a8\">Function for Intraday Crypto Price Data<\/h2>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist114123713\" 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-intraday_data_fbp-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=\"intraday_data_fbp.py content, created by marcosan93 on 10:47PM on January 13, 2022.\"\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=\"intraday_data_fbp.py\">\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def getIntradayPrices(crypto, n_hours, training_hours, mov_avg):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    Gets crypto prices from now to N days ago and training amount will be in addition <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    to the number of days to train. (According to the EOD documentation: The maximum <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    periods between \u2018from\u2019 and \u2018to\u2019 are 120 days for 1-minute interval, 600 days <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    for 5-minute interval and 7200 days for 1 hour interval.)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">    There also appears to be a time delay on the data of about 15-20 hours, which <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">    is added to the from(ago) variable.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">    # Getting the time from N hours ago<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">    ago = datetime.utcnow() - timedelta(hours=n_hours+training_hours+15)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">    # Getting the unix timestamp format for the intraday data from the API<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">    timestamp_unix = str(calendar.timegm(ago.utctimetuple()))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">    # Retrieving price data<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">    resp = client.get_prices_intraday(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">        crypto+&#39;-USD.CC&#39;, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">        interval=&quot;1h&quot;, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">        from_=timestamp_unix<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">    # Removing the last time period for uniformity if necessary<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">    if resp[-1][&#39;datetime&#39;][-5:-3] != &quot;00&quot;:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">        resp = resp[:-1]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">    # Price formatting for the dataframe<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">    prices = pd.DataFrame(resp)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">    # Filling NaNs with the most recent values for any missing data<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">    prices = prices.fillna(method=&#39;ffill&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC34\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC35\" class=\"blob-code blob-code-inner js-file-line\">    # Getting the N Day Moving Average and rounding the values for some light data preprocessing<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L36\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"36\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC36\" class=\"blob-code blob-code-inner js-file-line\">    prices[&#39;MA&#39;] = prices[[&#39;open&#39;]].rolling(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L37\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"37\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC37\" class=\"blob-code blob-code-inner js-file-line\">        window=mov_avg<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L38\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"38\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC38\" class=\"blob-code blob-code-inner js-file-line\">    ).mean().apply(lambda x: round(x, 6))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L39\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"39\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC39\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L40\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"40\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC40\" class=\"blob-code blob-code-inner js-file-line\">    # Resetting format for FBP<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L41\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"41\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC41\" class=\"blob-code blob-code-inner js-file-line\">    prices = prices.rename(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L42\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"42\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC42\" class=\"blob-code blob-code-inner js-file-line\">        columns={&quot;datetime&quot;: &quot;ds&quot;, &quot;MA&quot;: &quot;y&quot;}<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L43\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"43\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC43\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L44\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"44\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC44\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_data_fbp-py-L45\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"45\"><\/td>\n          <td id=\"file-intraday_data_fbp-py-LC45\" class=\"blob-code blob-code-inner js-file-line\">    return prices<\/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\/85a9ed9e1bef05cbe58ab08c42c12d63\/raw\/afd3c133c22d9d03f2b2febb1306f01059a88e5a\/intraday_data_fbp.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/85a9ed9e1bef05cbe58ab08c42c12d63#file-intraday_data_fbp-py\" class=\"Link--inTextBlock\">\n          intraday_data_fbp.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=\"2283\">For this function, I\u2019ll be grabbing the hourly price data. However, there are other options for shorter time intervals. At times during the API call, I found there to be a slight time delay. The API does have a separate package that provides live data but for the purpose of this project it was not necessary.<\/p>\n\n\n\n<p id=\"fb1f\">Next, I retrieved the hourly data from a specific timestamp dictated by the provided parameters within the function. After grabbing the data and performing some basic formatting and handling of missing data, I moved on to applying a moving average to the dataset. This is done in order to smooth out any outliers that may appear within the data. Lastly, the DataFrame is then renamed to be compatible with Facebook Prophet.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bf8b\">Training and Predicting with Facebook Prophet<\/h2>\n\n\n\n<p id=\"fd12\">I\u2019ve written other articles detailing the process of training and predicting with Facebook Prophet on daily data. If you choose to learn more about that specific process then&nbsp;<a href=\"https:\/\/medium.com\/geekculture\/i-tested-facebooks-machine-learning-model-in-the-crypto-market-8a8aaf09564f\"><strong>click here<\/strong><\/a>. However, in this project, I had to make adjustments to the function in order to compensate for the hourly data:<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist114123950\" 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-fbp_func_intraday-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=\"fbp_func_intraday.py content, created by marcosan93 on 10:57PM on January 13, 2022.\"\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=\"fbp_func_intraday.py\">\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def fbpTrainPredict(df, forecast_hours):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    Uses FB Prophet and fits to a appropriately formatted DF. Makes a prediction N days into <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    the future based on given forecast period. Returns predicted values as a DF.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    # Setting up prophet<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">    m = Prophet(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">        yearly_seasonality=False,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">        weekly_seasonality=False,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">        daily_seasonality=False<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">    # Fitting to the prices<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">    m.fit(df[[&#39;ds&#39;, &#39;y&#39;]])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">    # Future DF<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">    future = m.make_future_dataframe(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">        periods=forecast_hours,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">        freq=&quot;H&quot;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">        include_history=False<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">    # Predicting values<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">    forecast = m.predict(future)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">    # Returning a set of predicted values<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_func_intraday-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-fbp_func_intraday-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">    return forecast[[&#39;ds&#39;, &#39;yhat&#39;, &#39;yhat_lower&#39;, &#39;yhat_upper&#39;]]<\/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\/ccd350391ea483cc3e2d806245d132ec\/raw\/60394b4bc267b45cf77d0d83602e2ca10b517a52\/fbp_func_intraday.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/ccd350391ea483cc3e2d806245d132ec#file-fbp_func_intraday-py\" class=\"Link--inTextBlock\">\n          fbp_func_intraday.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=\"9159\">There are only two adjustments that needed to be made in order to handle intraday or hourly data. One was switching all the seasonality options to&nbsp;<em>False<\/em>. The other one was designating the frequency parameter to hourly with \u201cH\u201d within the&nbsp;<code>.make_future_dataframe()<\/code>&nbsp;function. Finally, this function returns the dates and predictions based on the provided DF.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"31b9\">Predictions Over Time<\/h2>\n\n\n\n<p id=\"67f9\">The next step would be to make predictions over a set period of time. To do so, I created a function that implements the train and predict function in a loop to simulate these predictions over time.<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist114140397\" 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-intraday_fbp_predict-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=\"intraday_fbp_predict.py content, created by marcosan93 on 04:39PM on January 14, 2022.\"\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=\"intraday_fbp_predict.py\">\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def runningFBP(prices, forecast_hours, training_hours):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    Runs Facebook Prophet to get predictions over a set period <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    of time. Uses FBP to train and predict every hour and gets the <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    price forecasts in the next N hours.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">    # DF for the predicted values<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">    pred_df = pd.DataFrame()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">    # Running the model each day<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">    for i in tqdm(range(training_hours, len(prices))):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">        # Training and Predicting the last hour on the forecast<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">        forecast = fbpTrainPredict(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">            prices[i-training_hours:i], <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">            forecast_hours<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">        ).tail(1)[[<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">            &#39;ds&#39;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">            &#39;yhat&#39;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">            &#39;yhat_lower&#39;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">            &#39;yhat_upper&#39;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">        ]]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">        # Adding the forecast predicted<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">        pred_df = pred_df.append(forecast, ignore_index=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">                <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">    # Prepping for merge by converting date values to be the same type<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">    pred_df[&#39;ds&#39;] = pred_df[&#39;ds&#39;].apply(str)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">    prices[&#39;ds&#39;] = prices[&#39;ds&#39;].apply(str)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">    # Shifting the forecasts back in order to compare it to the &#39;current&#39; open values<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">    pred_df[[&#39;yhat&#39;, &#39;yhat_lower&#39;, &#39;yhat_upper&#39;]] = pred_df[[&#39;yhat&#39;, &#39;yhat_lower&#39;, &#39;yhat_upper&#39;]].shift(-forecast_hours)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC34\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC35\" class=\"blob-code blob-code-inner js-file-line\">    # Merging with the prices DF in order to compare values for positions later<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L36\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"36\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC36\" class=\"blob-code blob-code-inner js-file-line\">    merge_df = prices[[&#39;ds&#39;, &#39;open&#39;]].merge(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L37\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"37\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC37\" class=\"blob-code blob-code-inner js-file-line\">        pred_df,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L38\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"38\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC38\" class=\"blob-code blob-code-inner js-file-line\">        on=&#39;ds&#39;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L39\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"39\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC39\" class=\"blob-code blob-code-inner js-file-line\">        how=&#39;outer&#39;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L40\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"40\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC40\" class=\"blob-code blob-code-inner js-file-line\">    ).dropna().set_index(&#39;ds&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L41\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"41\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC41\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_fbp_predict-py-L42\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"42\"><\/td>\n          <td id=\"file-intraday_fbp_predict-py-LC42\" class=\"blob-code blob-code-inner js-file-line\">    return merge_df<\/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\/52042820a81f978e5a913cbf9aefa855\/raw\/9f8fb6bcbc7e123055ace393d5fd51b64aa971d2\/intraday_fbp_predict.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/52042820a81f978e5a913cbf9aefa855#file-intraday_fbp_predict-py\" class=\"Link--inTextBlock\">\n          intraday_fbp_predict.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=\"3da8\">This function returns all the predictions made over the set period of time. For example, if the&nbsp;<code>forecast_hours<\/code>&nbsp;parameter is set to 5, then each date will have the predicted price of the fifth hour in the future. The function only trains on a moving window of the most recent hourly data in the \u2018<em>for<\/em>\u2019 loop, then makes a price forecast of 5 hours. I then shift these predictions back so that they will align with the \u201ccurrent\u201d values. This is done to simulate what predictions could look like every hour if it were ran in realtime.<\/p>\n\n\n\n<p id=\"6635\">Now with the predictions and their respective \u201ccurrent\u201d values set in a dataframe, I can move on to establishing the trading positions\u2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"da3e\">Trading Positions<\/h2>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist114140583\" 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-fbp_positions-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=\"fbp_positions.py content, created by marcosan93 on 04:52PM on January 14, 2022.\"\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=\"fbp_positions.py\">\n        <tr>\n          <td id=\"file-fbp_positions-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-fbp_positions-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def fbpPositions(pred_df, short=True):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_positions-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-fbp_positions-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_positions-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-fbp_positions-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    Gets positions based on the predictions and the actual values. This<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_positions-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-fbp_positions-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    is the logic of the trading strategy.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_positions-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-fbp_positions-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_positions-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-fbp_positions-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    if pred_df[&#39;open&#39;] &lt; pred_df[&#39;yhat_lower&#39;]:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_positions-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-fbp_positions-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">        return 1<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_positions-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-fbp_positions-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">    elif pred_df[&#39;open&#39;] &gt; pred_df[&#39;yhat_upper&#39;] and short:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_positions-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-fbp_positions-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">        return -1<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_positions-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-fbp_positions-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">    else:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_positions-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-fbp_positions-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">        return 0<\/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\/e00d91c94c394e133472709ac6d73bf3\/raw\/71b713cd226d6c22fe5e662ff42ba66ad6ff9b0a\/fbp_positions.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/e00d91c94c394e133472709ac6d73bf3#file-fbp_positions-py\" class=\"Link--inTextBlock\">\n          fbp_positions.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=\"04e1\">The function above establishes the basic trading strategy used during the backtest. Here, if the \u201c<em>open<\/em>\u201d price of Bitcoin is less than the predicted lower bound price, then the returned position is a \u201c<em>Buy<\/em>\u201d or \u201c<em>1<\/em>\u201d and vice-versa. If it is neither then it basically means the position is a \u201c<em>0<\/em>\u201d or do nothing. These positions will make up the Prophet positions for the backtest.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"cd05\">Baseline Positions<\/h2>\n\n\n\n<p id=\"5c4c\">The next thing I need to do is establish the baseline positions for the backtest. These positions will be used to compare to the Prophet positions in order to see if there are any significant improvements with using Prophet over them. These baseline trading strategy positions will be&nbsp;<em>Buying and Holding<\/em>&nbsp;and&nbsp;<em>Random<\/em>&nbsp;positions:<\/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\"># Adding sentiment positions to the forecast DF\npositions = pred_df\n\n# Getting forecast prophet positions\npositions['fbp_positions'] = positions.apply(\n    lambda x: fbpPositions(x, short=True), \n    axis=1\n)\n\n# Buy and hold position\npositions['buy_hold'] = 1\n\n# Random positions\npositions['random_positions'] = random.choices(\n    [1,0,-1], k=len(positions)\n)<\/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<h1 class=\"wp-block-heading\" id=\"b8f0\">Performing the Backtest<\/h1>\n\n\n\n<p id=\"364b\">With the positions ready to go, the final thing to do is to get the hour-by-hour returns. This is done by using the logarithmic returns on the \u2018open\u2019 prices:<\/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\"># Getting returns each hour<br>log_returns = prices[['ds', 'open']].set_index(<br>    'ds'<br>).loc[positions.index].apply(np.log).diff()<\/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 id=\"7d19\">With the log returns set, all I have left to do is multiply the returns with the positions DataFrame from before:<\/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\"># The positions to backtest (shifted ahead by 1 to prevent lookahead bias)\nbt_positions = positions[[\n    'buy_hold', \n    'random_positions',\n    'fbp_positions'\n]].shift(1)\n\n# The returns during the backtest\nreturns = bt_positions.multiply(\n    log_returns['open'], \n    axis=0\n)\n\n# Inversing the log returns to get daily portfolio balance\nperformance = returns.cumsum().apply(\n    np.exp\n).dropna().fillna(\n    method='ffill'\n)<\/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 id=\"e2ce\">The backtest is complete! The results of which are stored within the performance variable. However, in order to quickly run different parameters for the backtest, I\u2019ll need to consolidate all of these functions into one which will also include a visualization of the backtest after it has been completed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"da23\">Final Backtest Function<\/h2>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist114141122\" 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-intraday_final_func-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=\"intraday_final_func.py content, created by marcosan93 on 05:23PM on January 14, 2022.\"\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=\"intraday_final_func.py\">\n        <tr>\n          <td id=\"file-intraday_final_func-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def backtestPerformanceVis(ticker, n_hours, training_hours, mov_avg, forecast_hours):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    Consolidates the previous functions that support the backtesting process.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    # Getting Price data<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    print(&quot;Getting price data...&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">    prices = getIntradayPrices(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">        crypto=ticker, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">        n_hours=n_hours, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">        training_hours=training_hours, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">        mov_avg=mov_avg<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">    # Predicting over time<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">    print(&quot;Running predictions...&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">    pred_df = runningFBP(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">        prices, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">        forecast_hours=forecast_hours, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">        training_hours=training_hours<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">    # Adding sentiment positions to the prediction DF<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">    print(&quot;Getting positions...&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">    positions = pred_df<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">    # Getting forecast prophet positions<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">    positions[&#39;fbp_positions&#39;] = positions.apply(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">        lambda x: fbpPositions(x, short=True), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">        axis=1<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">    # Buy and hold position<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">    positions[&#39;buy_hold&#39;] = 1<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC34\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC35\" class=\"blob-code blob-code-inner js-file-line\">    # Random positions<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L36\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"36\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC36\" class=\"blob-code blob-code-inner js-file-line\">    positions[&#39;random_positions&#39;] = random.choices(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L37\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"37\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC37\" class=\"blob-code blob-code-inner js-file-line\">        [1,0,-1], k=len(positions)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L38\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"38\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC38\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L39\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"39\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC39\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L40\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"40\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC40\" class=\"blob-code blob-code-inner js-file-line\">    # Getting returns each hour<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L41\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"41\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC41\" class=\"blob-code blob-code-inner js-file-line\">    print(&quot;Performing the backtest...&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L42\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"42\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC42\" class=\"blob-code blob-code-inner js-file-line\">    log_returns = prices[[&#39;ds&#39;, &#39;open&#39;]].set_index(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L43\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"43\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC43\" class=\"blob-code blob-code-inner js-file-line\">        &#39;ds&#39;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L44\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"44\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC44\" class=\"blob-code blob-code-inner js-file-line\">    ).loc[positions.index].apply(np.log).diff()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L45\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"45\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC45\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L46\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"46\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC46\" class=\"blob-code blob-code-inner js-file-line\">    # The positions to backtest (shifted ahead by 1 to prevent lookahead bias)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L47\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"47\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC47\" class=\"blob-code blob-code-inner js-file-line\">    bt_positions = positions[[<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L48\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"48\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC48\" class=\"blob-code blob-code-inner js-file-line\">        &#39;buy_hold&#39;, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L49\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"49\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC49\" class=\"blob-code blob-code-inner js-file-line\">        &#39;random_positions&#39;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L50\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"50\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC50\" class=\"blob-code blob-code-inner js-file-line\">        &#39;fbp_positions&#39;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L51\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"51\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC51\" class=\"blob-code blob-code-inner js-file-line\">    ]].shift(1)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L52\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"52\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC52\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L53\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"53\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC53\" class=\"blob-code blob-code-inner js-file-line\">    # The returns during the backtest<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L54\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"54\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC54\" class=\"blob-code blob-code-inner js-file-line\">    returns = bt_positions.multiply(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L55\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"55\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC55\" class=\"blob-code blob-code-inner js-file-line\">        log_returns[&#39;open&#39;], <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L56\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"56\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC56\" class=\"blob-code blob-code-inner js-file-line\">        axis=0<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L57\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"57\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC57\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L58\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"58\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC58\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L59\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"59\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC59\" class=\"blob-code blob-code-inner js-file-line\">    # Inversing the log returns to get daily portfolio balance<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L60\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"60\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC60\" class=\"blob-code blob-code-inner js-file-line\">    performance = returns.cumsum().apply(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L61\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"61\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC61\" class=\"blob-code blob-code-inner js-file-line\">        np.exp<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L62\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"62\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC62\" class=\"blob-code blob-code-inner js-file-line\">    ).dropna().fillna(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L63\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"63\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC63\" class=\"blob-code blob-code-inner js-file-line\">        method=&#39;ffill&#39;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L64\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"64\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC64\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L65\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"65\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC65\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L66\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"66\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC66\" class=\"blob-code blob-code-inner js-file-line\">    # Displaying the final balance of the portfolio<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L67\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"67\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC67\" class=\"blob-code blob-code-inner js-file-line\">    print(&quot;Final Performance:&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L68\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"68\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC68\" class=\"blob-code blob-code-inner js-file-line\">    display(performance.tail(1))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L69\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"69\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC69\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L70\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"70\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC70\" class=\"blob-code blob-code-inner js-file-line\">    # Visualizing results<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L71\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"71\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC71\" class=\"blob-code blob-code-inner js-file-line\">    fig = px.line(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L72\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"72\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC72\" class=\"blob-code blob-code-inner js-file-line\">        performance,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L73\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"73\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC73\" class=\"blob-code blob-code-inner js-file-line\">        x=performance.index,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L74\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"74\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC74\" class=\"blob-code blob-code-inner js-file-line\">        y=performance.columns,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L75\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"75\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC75\" class=\"blob-code blob-code-inner js-file-line\">        title=&#39;FBProphet, Buy&amp;Hold, Random Positions&#39;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L76\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"76\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC76\" class=\"blob-code blob-code-inner js-file-line\">        labels={&quot;value&quot;: &quot;Portfolio Balance&quot;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L77\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"77\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC77\" class=\"blob-code blob-code-inner js-file-line\">                &quot;index&quot;: &quot;Date&quot;}<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L78\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"78\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC78\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L79\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"79\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC79\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-intraday_final_func-py-L80\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"80\"><\/td>\n          <td id=\"file-intraday_final_func-py-LC80\" class=\"blob-code blob-code-inner js-file-line\">    return fig.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\/d387964d2550c68bdc280adacc67d9a2\/raw\/955b54927f2d21bd59c62826368c34bb6da97cd9\/intraday_final_func.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/d387964d2550c68bdc280adacc67d9a2#file-intraday_final_func-py\" class=\"Link--inTextBlock\">\n          intraday_final_func.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=\"9377\">The above function consolidates the previous functions and will retrieve data, run predictions, establish trading positions, run the backtest, then return the final numbers and visualization.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4b7c\">Backtesting Visualization<\/h2>\n\n\n\n<p id=\"ebf5\">With the following parameters:<\/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\">backtestPerformanceVis(<br>    ticker=\"BTC\", <br>    n_hours=300, <br>    training_hours=200, <br>    mov_avg=5, <br>    forecast_hours=5<br>)<\/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 id=\"ff1c\">I was able to achieve the following results:<\/p>\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_eU_JrM7a2qv46CvuzOQJYw.png\" alt=\"\" class=\"wp-image-68\"\/><\/figure>\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=\"3db8\">Closing Thoughts<\/h2>\n\n\n\n<p id=\"5a6e\">Based on these results, it looks like Prophet would\u2019ve performed very well in the previous 300 hours. It resulted in a return of 16% in about 300 hours! However, this could be a fluke and may require further testing of different parameters to really assess the robustness of this strategy.<\/p>\n\n\n\n<p id=\"8aa4\">With the final function I created, I can attempt other parameters such as increasing the backtesting length, increasing the training amount, or alter the moving average. Or even with the strategy itself, I can decide different positions based on the predictions. There are many different scenarios that should be tested before this strategy could be used in a real-time trade. But, as of now, the results are much more promising than I would have expected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the past, I\u2019ve experimented with various forms of machine learning models in order to develop a successful cryptocurrency trading strategy. These various strategies would utilize&nbsp;classification models,&nbsp;time-series models, and&nbsp;sentiment analysis. The results of these strategies would range from mediocre to \u201cgood but requires more testing\u201d. I\u2019ve never settled on a specific strategy and hope to [&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":[65],"tags":[],"coding-language":[30],"ready-to-go-solution":[],"qualification":[31,32],"financial-apis-category":[34],"financial-apis-manuals":[38],"class_list":["post-67","post","type-post","status-publish","format-standard","hentry","category-backtesting-strategies-examples","coding-language-python","qualification-experienced","qualification-guru","financial-apis-category-crypto-market-prices","financial-apis-manuals-intraday"],"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>Day Trade Crypto with Facebook Prophet: Boost Your Trading Strategy | EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"Explore the world of cryptocurrency trading with Facebook Prophet. Learn how to day trade crypto using machine learning models and historical data analysis\" \/>\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\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What Happens if you Day Trade Crypto with Facebook Prophet?\" \/>\n<meta property=\"og:description\" content=\"Explore the world of cryptocurrency trading with Facebook Prophet. Learn how to day trade crypto using machine learning models and historical data analysis\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet\" \/>\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=\"2022-01-19T12:53:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T13:23:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2022\/03\/what-happens-if-you-day-trade-crypto-with-facebook-prophet.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet\"},\"author\":{\"name\":\"Marco Santos\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/21a7f35c812f05fb7c4e60a624a3237d\"},\"headline\":\"What Happens if you Day Trade Crypto with Facebook Prophet?\",\"datePublished\":\"2022-01-19T12:53:00+00:00\",\"dateModified\":\"2025-02-05T13:23:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet\"},\"wordCount\":1195,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_eU_JrM7a2qv46CvuzOQJYw.png\",\"articleSection\":[\"Backtesting Strategies Examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet\",\"name\":\"Day Trade Crypto with Facebook Prophet: Boost Your Trading Strategy | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_eU_JrM7a2qv46CvuzOQJYw.png\",\"datePublished\":\"2022-01-19T12:53:00+00:00\",\"dateModified\":\"2025-02-05T13:23:56+00:00\",\"description\":\"Explore the world of cryptocurrency trading with Facebook Prophet. Learn how to day trade crypto using machine learning models and historical data analysis\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#primaryimage\",\"url\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_eU_JrM7a2qv46CvuzOQJYw.png\",\"contentUrl\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_eU_JrM7a2qv46CvuzOQJYw.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What Happens if you Day Trade Crypto with Facebook Prophet?\"}]},{\"@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":"Day Trade Crypto with Facebook Prophet: Boost Your Trading Strategy | EODHD APIs Academy","description":"Explore the world of cryptocurrency trading with Facebook Prophet. Learn how to day trade crypto using machine learning models and historical data analysis","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\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet","og_locale":"en_US","og_type":"article","og_title":"What Happens if you Day Trade Crypto with Facebook Prophet?","og_description":"Explore the world of cryptocurrency trading with Facebook Prophet. Learn how to day trade crypto using machine learning models and historical data analysis","og_url":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2022-01-19T12:53:00+00:00","article_modified_time":"2025-02-05T13:23:56+00:00","og_image":[{"width":800,"height":450,"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2022\/03\/what-happens-if-you-day-trade-crypto-with-facebook-prophet.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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet"},"author":{"name":"Marco Santos","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/21a7f35c812f05fb7c4e60a624a3237d"},"headline":"What Happens if you Day Trade Crypto with Facebook Prophet?","datePublished":"2022-01-19T12:53:00+00:00","dateModified":"2025-02-05T13:23:56+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet"},"wordCount":1195,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#primaryimage"},"thumbnailUrl":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_eU_JrM7a2qv46CvuzOQJYw.png","articleSection":["Backtesting Strategies Examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet","url":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet","name":"Day Trade Crypto with Facebook Prophet: Boost Your Trading Strategy | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#primaryimage"},"thumbnailUrl":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_eU_JrM7a2qv46CvuzOQJYw.png","datePublished":"2022-01-19T12:53:00+00:00","dateModified":"2025-02-05T13:23:56+00:00","description":"Explore the world of cryptocurrency trading with Facebook Prophet. Learn how to day trade crypto using machine learning models and historical data analysis","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#primaryimage","url":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_eU_JrM7a2qv46CvuzOQJYw.png","contentUrl":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_eU_JrM7a2qv46CvuzOQJYw.png"},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/what-happens-if-you-day-trade-crypto-with-facebook-prophet#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"What Happens if you Day Trade Crypto with Facebook Prophet?"}]},{"@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-15","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/67","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=67"}],"version-history":[{"count":2,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/67\/revisions"}],"predecessor-version":[{"id":6285,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/67\/revisions\/6285"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=67"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=67"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=67"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=67"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=67"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=67"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=67"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=67"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}