{"id":105,"date":"2022-03-02T14:56:00","date_gmt":"2022-03-02T14:56:00","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=105"},"modified":"2025-02-05T12:45:54","modified_gmt":"2025-02-05T12:45:54","slug":"use-twitter-sentiment-and-facebook-prophet-to-trade-crypto","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto","title":{"rendered":"Use Twitter Sentiment and Facebook Prophet to Trade Crypto?"},"content":{"rendered":"\n<p>Combining two different forms of machine learning is a very exciting concept, especially when it comes to making money. In this case, I combined time series machine learning models with a sentiment analyzer. Two separate forms of machine learning used to create trade signals in the cryptocurrency market. This wasn\u2019t the first time I\u2019ve attempted to do this and it probably won\u2019t be my last.<\/p>\n\n\n\n<p id=\"d520\">In my previous articles, I\u2019ve used&nbsp;<a href=\"https:\/\/medium.com\/geekculture\/i-tested-facebooks-machine-learning-model-in-the-crypto-market-8a8aaf09564f\">Facebook Prophet to forecast Bitcoin prices<\/a>&nbsp;and&nbsp;<a href=\"https:\/\/medium.com\/geekculture\/do-twitter-opinions-lead-to-great-stock-returns-4faaff1ca3a8\">sentiment analysis on Tweets to predict stock price movement<\/a>. However, I have yet to fuse both of these methods together.&nbsp;<em>But<\/em>, even that statement is not&nbsp;<em>entirely<\/em>&nbsp;true. Recently, I combined&nbsp;<a href=\"https:\/\/medium.com\/geekculture\/trading-crypto-with-facebooks-machine-learning-model-and-news-sentiment-d3aadaec84c4\">Facebook Prophet with sentiment analysis on financial news headlines<\/a>,&nbsp;<em>but not tweets<\/em>. So this time around, I will be experimenting with the slightly altered approach of using tweet sentiment.<\/p>\n\n\n\n<p id=\"2a3c\">Anyways \u2014 let\u2019s dive right in and learn how I backtested a trading strategy using Facebook Prophet and Twitter sentiment analysis! Feel free to code along if you wish, I\u2019ll also provide my code on Github for reference at the end of this article.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"9083\">Importing Libraries<\/h2>\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\nfrom tqdm import tqdm\nimport twint\nimport nest_asyncio\nnest_asyncio.apply()\nfrom nltk.sentiment.vader import SentimentIntensityAnalyzer\nimport nltk\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 id=\"9026\">I know it\u2019s a lot of libraries, but it is what is needed in order for this backtest to run correctly. I will explain the two libraries above that you need in order to retrieve the data\u2026<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"0408\">How to Get Crypto Price and Twitter Data<\/h3>\n\n\n\n<p id=\"eaa3\">To get the price data, I used&nbsp;<a href=\"https:\/\/eodhistoricaldata.com\/r\/?ref=31CX3ILN\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>a financial data API from EOD-HD<\/strong><\/a>, which allows me to easily retrieve crypto price history from many different cryptocurrencies. It\u2019s free to sign up and you\u2019ll get your own API key in order to access the price history data.&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=\"c6c6\">Next, I used&nbsp;<a href=\"https:\/\/github.com\/twintproject\/twint\/wiki\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>Twint<\/strong><\/a>&nbsp;to easily retrieve the daily tweets regarding a specific crypto using their \u201ccashtag\u201d. No API key is needed for this one but I suggest reading up on their&nbsp;<a href=\"https:\/\/github.com\/twintproject\/twint\" rel=\"noreferrer noopener\" target=\"_blank\">documentation<\/a>&nbsp;in order to know how to properly access the data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8306\">Retrieving Tweets and Price History<\/h2>\n\n\n\n<p id=\"543f\">Now that I\u2019ve established the required libraries to gather the data, I can code out the entire process of retrieving it. The first piece of data is a year\u2019s worth of tweets regarding a specific cryptocurrency. In this case \u2014 Bitcoin.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"0156\">Gathering Tweet on Bitcoin<\/h3>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist114910291\" 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-tweet_gathering_funcs-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=\"tweet_gathering_funcs.py content, created by marcosan93 on 01:37AM on February 25, 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=\"tweet_gathering_funcs.py\">\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def getTweets(search_term, until, since, limit=20):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    Configures Twint and returns a dataframe of tweets for a specific day.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    # Configuring Twint for search<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    c = twint.Config()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">    # The limit of tweets to retrieve<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">    c.Limit = limit<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">    # Search term<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">    c.Search = search_term<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">    # Removing retweets<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">    c.Filter_retweets = True<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">    # Popular tweets<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">    c.Popular_tweets = True<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">    # Verified users only<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">    c.Verified = True<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">    # Lowercasing tweets<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">    c.Lowercase = False<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">    # English only<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">    c.Lang = &#39;en&#39;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">    # Tweets until a specified date<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">    c.Until = until + &quot; 00:00:00&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">    # Tweets since a specified date<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">    c.Since = since + &quot; 00:00:00&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC34\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC35\" class=\"blob-code blob-code-inner js-file-line\">    # Making the results pandas friendly<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L36\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"36\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC36\" class=\"blob-code blob-code-inner js-file-line\">    c.Pandas = True<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L37\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"37\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC37\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L38\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"38\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC38\" class=\"blob-code blob-code-inner js-file-line\">    # Stopping print in terminal<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L39\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"39\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC39\" class=\"blob-code blob-code-inner js-file-line\">    c.Hide_output = True<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L40\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"40\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC40\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L41\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"41\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC41\" class=\"blob-code blob-code-inner js-file-line\">    # Searching<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L42\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"42\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC42\" class=\"blob-code blob-code-inner js-file-line\">    twint.run.Search(c)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L43\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"43\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC43\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L44\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"44\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC44\" class=\"blob-code blob-code-inner js-file-line\">    # Assigning the DF<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L45\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"45\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC45\" class=\"blob-code blob-code-inner js-file-line\">    df = twint.storage.panda.Tweets_df<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L46\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"46\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC46\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L47\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"47\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC47\" class=\"blob-code blob-code-inner js-file-line\">    # Returning an empty DF if no tweets were found<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L48\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"48\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC48\" class=\"blob-code blob-code-inner js-file-line\">    if len(df)&lt;=0:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L49\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"49\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC49\" class=\"blob-code blob-code-inner js-file-line\">        return pd.DataFrame()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L50\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"50\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC50\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L51\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"51\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC51\" class=\"blob-code blob-code-inner js-file-line\">    # Formatting the date<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L52\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"52\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC52\" class=\"blob-code blob-code-inner js-file-line\">    df[&#39;date&#39;] = df[&#39;date&#39;].apply(lambda x: x.split(&quot; &quot;)[0])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L53\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"53\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC53\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L54\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"54\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC54\" class=\"blob-code blob-code-inner js-file-line\">    # Returning with english filter to account for an issue with the twint language filter<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L55\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"55\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC55\" class=\"blob-code blob-code-inner js-file-line\">    return df[df[&#39;language&#39;]==&#39;en&#39;]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L56\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"56\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC56\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L57\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"57\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC57\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L58\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"58\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC58\" class=\"blob-code blob-code-inner js-file-line\">def tweetByDay(start, end, df, search, limit=20):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L59\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"59\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC59\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L60\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"60\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC60\" class=\"blob-code blob-code-inner js-file-line\">    Runs the twint query everyday between the given dates and returns<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L61\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"61\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC61\" class=\"blob-code blob-code-inner js-file-line\">    the total dataframe. <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L62\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"62\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC62\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L63\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"63\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC63\" class=\"blob-code blob-code-inner js-file-line\">    Start is the first date in the past.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L64\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"64\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC64\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L65\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"65\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC65\" class=\"blob-code blob-code-inner js-file-line\">    End is the last date (usually would be current date)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L66\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"66\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC66\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L67\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"67\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC67\" class=\"blob-code blob-code-inner js-file-line\">    # Finishing the recursive loop<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L68\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"68\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC68\" class=\"blob-code blob-code-inner js-file-line\">    if start==end:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L69\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"69\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC69\" class=\"blob-code blob-code-inner js-file-line\">        # Removing any potential duplicates<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L70\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"70\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC70\" class=\"blob-code blob-code-inner js-file-line\">        df = df.drop_duplicates(subset=&quot;id&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L71\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"71\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC71\" class=\"blob-code blob-code-inner js-file-line\">        print(len(df))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L72\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"72\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC72\" class=\"blob-code blob-code-inner js-file-line\">        return df    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L73\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"73\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC73\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L74\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"74\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC74\" class=\"blob-code blob-code-inner js-file-line\">    # Appending the new set of tweets for specified window of time<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L75\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"75\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC75\" class=\"blob-code blob-code-inner js-file-line\">    tweet_df = getTweets(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L76\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"76\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC76\" class=\"blob-code blob-code-inner js-file-line\">        search, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L77\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"77\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC77\" class=\"blob-code blob-code-inner js-file-line\">        until=(datetime.strptime(start, &quot;%Y-%m-%d&quot;) + timedelta(days=2)).strftime(&quot;%Y-%m-%d&quot;), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L78\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"78\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC78\" class=\"blob-code blob-code-inner js-file-line\">        since=start, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L79\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"79\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC79\" class=\"blob-code blob-code-inner js-file-line\">        limit=limit<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L80\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"80\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC80\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L81\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"81\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC81\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L82\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"82\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC82\" class=\"blob-code blob-code-inner js-file-line\">    # Running the query a few more times in case twint missed some tweets<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L83\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"83\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC83\" class=\"blob-code blob-code-inner js-file-line\">    run = 0 <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L84\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"84\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC84\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L85\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"85\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC85\" class=\"blob-code blob-code-inner js-file-line\">    while len(tweet_df)==0 and run&lt;=2:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L86\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"86\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC86\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L87\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"87\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC87\" class=\"blob-code blob-code-inner js-file-line\">        # Running query again<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L88\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"88\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC88\" class=\"blob-code blob-code-inner js-file-line\">        tweet_df = getTweets(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L89\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"89\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC89\" class=\"blob-code blob-code-inner js-file-line\">            search, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L90\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"90\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC90\" class=\"blob-code blob-code-inner js-file-line\">            until=(datetime.strptime(start, &quot;%Y-%m-%d&quot;) + timedelta(days=2)).strftime(&quot;%Y-%m-%d&quot;), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L91\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"91\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC91\" class=\"blob-code blob-code-inner js-file-line\">            since=start, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L92\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"92\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC92\" class=\"blob-code blob-code-inner js-file-line\">            limit=limit<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L93\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"93\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC93\" class=\"blob-code blob-code-inner js-file-line\">        )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L94\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"94\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC94\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L95\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"95\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC95\" class=\"blob-code blob-code-inner js-file-line\">        # Counting how many times it ran<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L96\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"96\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC96\" class=\"blob-code blob-code-inner js-file-line\">        run += 1<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L97\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"97\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC97\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L98\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"98\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC98\" class=\"blob-code blob-code-inner js-file-line\">    # Adding the new tweets<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L99\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"99\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC99\" class=\"blob-code blob-code-inner js-file-line\">    df = df.append(tweet_df, ignore_index=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L100\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"100\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC100\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L101\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"101\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC101\" class=\"blob-code blob-code-inner js-file-line\">    # Updating the new start date<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L102\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"102\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC102\" class=\"blob-code blob-code-inner js-file-line\">    new_start = (datetime.strptime(start, &quot;%Y-%m-%d&quot;) + timedelta(days=1)).strftime(&quot;%Y-%m-%d&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L103\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"103\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC103\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L104\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"104\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC104\" class=\"blob-code blob-code-inner js-file-line\">    # Printing scraping status<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L105\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"105\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC105\" class=\"blob-code blob-code-inner js-file-line\">    print(f&quot;\\t{len(df)} Total Tweets collected as of {new_start}\\t&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L106\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"106\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC106\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L107\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"107\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC107\" class=\"blob-code blob-code-inner js-file-line\">    # Running the function again<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L108\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"108\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC108\" class=\"blob-code blob-code-inner js-file-line\">    return tweetByDay(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L109\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"109\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC109\" class=\"blob-code blob-code-inner js-file-line\">        start=new_start, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L110\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"110\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC110\" class=\"blob-code blob-code-inner js-file-line\">        end=end, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L111\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"111\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC111\" class=\"blob-code blob-code-inner js-file-line\">        df=df, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L112\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"112\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC112\" class=\"blob-code blob-code-inner js-file-line\">        search=search<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-tweet_gathering_funcs-py-L113\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"113\"><\/td>\n          <td id=\"file-tweet_gathering_funcs-py-LC113\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/40bcae898002637cb610e037ea88e67d\/raw\/0fc0871c90c6e94b4508789125e17f8dbf6e8042\/tweet_gathering_funcs.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/40bcae898002637cb610e037ea88e67d#file-tweet_gathering_funcs-py\" class=\"Link--inTextBlock\">\n          tweet_gathering_funcs.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=\"0892\">Above, I created two functions. The first function (<code>getTweets<\/code>)configures Twint to retrieve tweets with specific parameters. For example, I wanted to filter out any unsubstantial tweets so I configured twint to query only popular tweets from verified users.<\/p>\n\n\n\n<p id=\"91d6\">The second function (<code>tweetByDay<\/code>) implements&nbsp;<code>getTweets<\/code>&nbsp;in order to retrieve tweets on day by day basis. I used a recursive method for this function in order to retrieve the daily tweets from last year (<em>2021<\/em>). If you\u2019re wondering why I decided to call the twint query multiple times instead of just once with a time frame of a year, it was because of my want of uniformity among tweets retrieved each day. In my experience with twint, there is a lack of consistency regarding tweets returned when it used on a longer time frame.<\/p>\n\n\n\n<p id=\"95f7\">Anyways, here is how I called the twint query:<\/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 tweets daily\ndf = tweetByDay(\n    start=\"2021-01-01\", \n    end=\"2022-01-01\", \n    df=pd.DataFrame(), \n    search=\"$BTC\", \n    limit=20\n)\n\n# Saving file for later use\ndf.to_csv(\"tweets.csv\")\n\n# Reading file and saving to DF\ntweet_df = pd.read_csv(\"tweets.csv\", index_col=0)<\/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=\"286a\">Using twint in this case, may take awhile, so I opted to save the year\u2019s worth of tweets as a CSV file for later use if needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1b8a\">Gathering Bitcoin Price History<\/h3>\n\n\n\n<p id=\"3361\">Now that I have the year\u2019s worth of tweets, I can now gather Bitcoin\u2019s price history from around the same time frame:<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist114910563\" 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-crypto_price_history_gathering_funcs-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=\"crypto_price_history_gathering_funcs.py content, created by marcosan93 on 02:07AM on February 25, 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=\"crypto_price_history_gathering_funcs.py\">\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def getPrices(ticker, training_days, tweet_df, mov_avg, forecast_period):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    Using a tweet DataFrame to find the first day and training data from the <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    previous N days to make predictions that coincide with the sentiment date range.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    In order to properly backtest with sentiment, a certain amount of training <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">    days need to come before the initial date from the tweet DF as well <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">    as the moving average and forecast period in order to accurately line up<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">    with the tweet DF.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">    Also prepares the price data for FBProphet forecasting.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">    # The first day from the tweet DF minus the amount of days to train with, moving avg, and forecast period<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">    ago = datetime.strptime(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">        tweet_df.index[0], <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">        &quot;%Y-%m-%d&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">    ) - timedelta(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">        days=training_days+mov_avg+forecast_period<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">    # The last day of the tweet DF<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">    now = datetime.strptime(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">        tweet_df.index[-1], <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">        &quot;%Y-%m-%d&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">    # Getting prices<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">    prices = pd.DataFrame(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">        client.get_prices_eod(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">            ticker+&quot;-USD.CC&quot;, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">            from_=ago.strftime(&quot;%Y-%m-%d&quot;),<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">            to=now.strftime(&quot;%Y-%m-%d&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">        )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC34\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC35\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L36\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"36\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC36\" class=\"blob-code blob-code-inner js-file-line\">    # Set index<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L37\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"37\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC37\" class=\"blob-code blob-code-inner js-file-line\">    prices = prices.set_index(&#39;date&#39;, drop=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L38\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"38\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC38\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L39\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"39\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC39\" 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-crypto_price_history_gathering_funcs-py-L40\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"40\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC40\" 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-crypto_price_history_gathering_funcs-py-L41\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"41\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC41\" class=\"blob-code blob-code-inner js-file-line\">        window=mov_avg<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L42\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"42\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC42\" class=\"blob-code blob-code-inner js-file-line\">    ).mean().apply(lambda x: round(x, 2))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L43\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"43\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC43\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L44\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"44\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC44\" class=\"blob-code blob-code-inner js-file-line\">    # Dropping Nans<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L45\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"45\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC45\" class=\"blob-code blob-code-inner js-file-line\">    prices.dropna(inplace=True)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L46\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"46\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC46\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L47\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"47\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC47\" class=\"blob-code blob-code-inner js-file-line\">    # Resetting format for FBP<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L48\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"48\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC48\" class=\"blob-code blob-code-inner js-file-line\">    prices = prices.reset_index().rename(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L49\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"49\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC49\" class=\"blob-code blob-code-inner js-file-line\">        columns={&quot;date&quot;: &quot;ds&quot;, &quot;MA&quot;: &quot;y&quot;}<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L50\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"50\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC50\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L51\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"51\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC51\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-L52\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"52\"><\/td>\n          <td id=\"file-crypto_price_history_gathering_funcs-py-LC52\" 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\/26d57937f2edbffc06512372eac4956e\/raw\/574dc792c188bccd0b20d277aecfe67cc49cc612\/crypto_price_history_gathering_funcs.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/26d57937f2edbffc06512372eac4956e#file-crypto_price_history_gathering_funcs-py\" class=\"Link--inTextBlock\">\n          crypto_price_history_gathering_funcs.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=\"9cb4\">With this function, I can gather the price history of Bitcoin that fits within the same time frame as the previously gathered Twitter data. In addition to gathering data from the same time frame, this function also gathers price history from further in the past in order to train FB Prophet as well as formatting the data to be compatible with Prophet.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8d02\">Running Facebook Prophet<\/h2>\n\n\n\n<p id=\"8887\">Now that I have the price history for Bitcoin, I can train Prophet to predict prices&nbsp;<em>N<\/em>&nbsp;days into the future. With the following functions I created, I\u2019ll create a Pandas DataFrame containing the predictions containing the last day forecasted:<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist114928774\" 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-init_fbp_running_preds-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=\"init_fbp_running_preds.py content, created by marcosan93 on 04:26AM on February 26, 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=\"init_fbp_running_preds.py\">\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def fbpTrainPredict(df, forecast_period):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-init_fbp_running_preds-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-init_fbp_running_preds-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-init_fbp_running_preds-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-init_fbp_running_preds-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    # Setting up prophet<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">    m = Prophet(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">        daily_seasonality=True, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">        yearly_seasonality=True, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">        weekly_seasonality=True<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">    )<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">    # Fitting to the prices<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-init_fbp_running_preds-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-init_fbp_running_preds-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">    # Future DF<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">    future = m.make_future_dataframe(periods=forecast_period)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">    # Predicting values<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">    forecast = m.predict(future)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC21\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">    # Returning a set of predicted values<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC23\" 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        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">def runningFBP(prices, forecast_period, training_days):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC28\" 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-init_fbp_running_preds-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">    of time. Uses FBP to train and predict every N days and gets the <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">    price forecasts.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">    # DF for the predicted values<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">    pred_df = pd.DataFrame()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC34\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC35\" class=\"blob-code blob-code-inner js-file-line\">    # Running the model each day<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L36\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"36\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC36\" class=\"blob-code blob-code-inner js-file-line\">    for i in tqdm(range(training_days, len(prices)+1)):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L37\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"37\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC37\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L38\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"38\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC38\" class=\"blob-code blob-code-inner js-file-line\">        # Training and Predicting the last day on the forecast<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L39\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"39\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC39\" class=\"blob-code blob-code-inner js-file-line\">        forecast = fbpTrainPredict(<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L40\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"40\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC40\" class=\"blob-code blob-code-inner js-file-line\">            prices[i-training_days:i], <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L41\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"41\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC41\" class=\"blob-code blob-code-inner js-file-line\">            forecast_period<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L42\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"42\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC42\" class=\"blob-code blob-code-inner js-file-line\">        ).tail(1)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L43\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"43\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC43\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L44\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"44\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC44\" class=\"blob-code blob-code-inner js-file-line\">        # Adding the forecast predicted<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L45\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"45\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC45\" 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-init_fbp_running_preds-py-L46\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"46\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC46\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L47\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"47\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC47\" 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-init_fbp_running_preds-py-L48\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"48\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC48\" class=\"blob-code blob-code-inner js-file-line\">    pred_df[&#39;ds&#39;] = pred_df[&#39;ds&#39;].apply(lambda x: str(x)[:10])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L49\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"49\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC49\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L50\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"50\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC50\" class=\"blob-code blob-code-inner js-file-line\">    prices[&#39;ds&#39;] = prices[&#39;ds&#39;].apply(lambda x: str(x)[:10])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L51\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"51\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC51\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L52\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"52\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC52\" 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-init_fbp_running_preds-py-L53\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"53\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC53\" 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_period)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L54\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"54\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC54\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L55\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"55\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC55\" 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-init_fbp_running_preds-py-L56\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"56\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC56\" 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-init_fbp_running_preds-py-L57\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"57\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC57\" class=\"blob-code blob-code-inner js-file-line\">        pred_df,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L58\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"58\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC58\" class=\"blob-code blob-code-inner js-file-line\">        on=&#39;ds&#39;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L59\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"59\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC59\" class=\"blob-code blob-code-inner js-file-line\">        how=&#39;outer&#39;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L60\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"60\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC60\" class=\"blob-code blob-code-inner js-file-line\">    ).dropna().set_index(&#39;ds&#39;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L61\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"61\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC61\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-init_fbp_running_preds-py-L62\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"62\"><\/td>\n          <td id=\"file-init_fbp_running_preds-py-LC62\" 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\/72c33f95822767d42f4ae9cd749d98da\/raw\/5dfdfd5c0d8760b673143bb738e844aa75c1f189\/init_fbp_running_preds.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/72c33f95822767d42f4ae9cd749d98da#file-init_fbp_running_preds-py\" class=\"Link--inTextBlock\">\n          init_fbp_running_preds.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>With the above functions, I can create the prediction DF using 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\"># Pricing Data Parameters\ntraining_days = 200\n\nmov_avg = 3\n\nforecast_period = 3\n\n# Retrieving prices with the above parameters\nprices = getPrices(\n    \"BTC\", \n    training_days=training_days, \n    tweet_df=tweet_df, \n    mov_avg=mov_avg,\n    forecast_period=forecast_period\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>With these parameters (which can be changed to whatever you see fit) I created the DF of predictions below:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_IwQQxvL6X_jyIysCcVO9Ig.png\" alt=\"\" class=\"wp-image-113\" style=\"width:700px;height:565px\"\/><figcaption class=\"wp-element-caption\">DataFrame of Predictions<\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"81fb\">Running Tweet Sentiment Analysis<\/h2>\n\n\n\n<p id=\"83e6\">With the price predictions ready, I can move on to creating a DF consisting of the daily average sentiment score:<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist111697348\" 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-sentiment_analyzer_tweets-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=\"sentiment_analyzer_tweets.py content, created by marcosan93 on 12:07AM on September 09, 2021.\"\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=\"sentiment_analyzer_tweets.py\">\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def getSentiment(df, measurement=&quot;compound&quot;):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC2\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    Given a DF of tweets, analyzes the tweets and returns a new DF<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    of sentiment scores based on the given measurement.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    Accepted sentiment measurements: [&quot;pos&quot;, &quot;neg&quot;, &quot;neu&quot;, &quot;compound&quot;]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">    # Sentiment Analyzer<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">    sia = SentimentIntensityAnalyzer()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">    # Getting the sentiment score<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">    df[&#39;sentiment&#39;] = df[&#39;tweet&#39;].apply(lambda x: sia.polarity_scores(x)[measurement])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">    # Creating a DF with the average sentiment score each day<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC15\" class=\"blob-code blob-code-inner js-file-line\">    sent_df = df.groupby(&#39;date&#39;)[&#39;sentiment&#39;].mean().reset_index()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">    # Converting the dates to datetime<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">    sent_df[&#39;date&#39;] = sent_df[&#39;date&#39;].apply(lambda x: datetime.strptime(x, &quot;%Y-%m-%d&quot;))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC19\" class=\"blob-code blob-code-inner js-file-line\">    <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-sentiment_analyzer_tweets-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-sentiment_analyzer_tweets-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">    return sent_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\/6ead14235afb05ec85c6dcfdce010098\/raw\/476cb331b119f81af8ac98be94b58e73a2ffa6c2\/sentiment_analyzer_tweets.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/6ead14235afb05ec85c6dcfdce010098#file-sentiment_analyzer_tweets-py\" class=\"Link--inTextBlock\">\n          sentiment_analyzer_tweets.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=\"8f09\">With the above function, I can analyze the sentiment of tweets for each day and return the average score for that day:<\/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 sentiment scores\nsent_df = getSentiment(tweet_df)<\/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>Running this function returns a DataFrame of sentiment scores for the past year:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_D4S4jwtZpxs-XDrKCl6B3A.png\" alt=\"\" class=\"wp-image-114\"\/><figcaption class=\"wp-element-caption\">Sentiment scores for the past year<\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"6598\">Getting Trade Positions<\/h2>\n\n\n\n<p id=\"783b\">The next step is to establish trading positions for each DF. The following functions will form the trading positions for the price prediction DF, tweet sentiment DF, and the combination of both:<\/p>\n\n\n\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist114928995\" 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_tweet_sentiment_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_tweet_sentiment_positions.py content, created by marcosan93 on 05:00AM on February 26, 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_tweet_sentiment_positions.py\">\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC1\" class=\"blob-code blob-code-inner js-file-line\">def sentimentPositions(val, thresh=0.1, short=True):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_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_tweet_sentiment_positions-py-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC3\" class=\"blob-code blob-code-inner js-file-line\">    Returns position as 1, -1, or 0 for Buy, Sell, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC4\" class=\"blob-code blob-code-inner js-file-line\">    and Do Nothing respectively based on the given <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC5\" class=\"blob-code blob-code-inner js-file-line\">    sentiment value and threshold.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC6\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC7\" class=\"blob-code blob-code-inner js-file-line\">    if val &gt; thresh:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC8\" class=\"blob-code blob-code-inner js-file-line\">        return 1<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC9\" class=\"blob-code blob-code-inner js-file-line\">    elif val &lt; -thresh and short:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC10\" class=\"blob-code blob-code-inner js-file-line\">        return -1<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC11\" class=\"blob-code blob-code-inner js-file-line\">    else:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC12\" class=\"blob-code blob-code-inner js-file-line\">        return 0<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC13\" class=\"blob-code blob-code-inner js-file-line\">      <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC14\" class=\"blob-code blob-code-inner js-file-line\">      <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC15\" 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_tweet_sentiment_positions-py-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC16\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC17\" class=\"blob-code blob-code-inner js-file-line\">    Gets positions based on the predictions and the actual values.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC18\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC19\" 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_tweet_sentiment_positions-py-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC20\" class=\"blob-code blob-code-inner js-file-line\">        return 1<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC21\" 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_tweet_sentiment_positions-py-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC22\" class=\"blob-code blob-code-inner js-file-line\">        return -1<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC23\" class=\"blob-code blob-code-inner js-file-line\">    else:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC24\" class=\"blob-code blob-code-inner js-file-line\">        return 0<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC25\" class=\"blob-code blob-code-inner js-file-line\">      <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC26\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC27\" class=\"blob-code blob-code-inner js-file-line\">def overallPosition(df):<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC28\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC29\" class=\"blob-code blob-code-inner js-file-line\">    Returns the position if both values in the DF are the same.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC30\" class=\"blob-code blob-code-inner js-file-line\">    Otherwise, the position will be to do nothing.<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC31\" class=\"blob-code blob-code-inner js-file-line\">    &quot;&quot;&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC32\" class=\"blob-code blob-code-inner js-file-line\">    if df[&#39;sentiment_positions&#39;]==df[&#39;fbp_positions&#39;]:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC33\" class=\"blob-code blob-code-inner js-file-line\">        return df[&#39;sentiment_positions&#39;]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC34\" class=\"blob-code blob-code-inner js-file-line\">    else:<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-fbp_tweet_sentiment_positions-py-LC35\" 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\/4a3b2b0a19d50cf271624f27b6491c92\/raw\/a88289df89fce402ea3298de6c0372e2fea0993a\/fbp_tweet_sentiment_positions.py\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/marcosan93\/4a3b2b0a19d50cf271624f27b6491c92#file-fbp_tweet_sentiment_positions-py\" class=\"Link--inTextBlock\">\n          fbp_tweet_sentiment_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>In the above functions, positions are set as 1, 0, -1 representing&nbsp;<em>buy, hold\/exit from previous position, and short<\/em>. The&nbsp;<code>sentimentPositions<\/code>&nbsp;function has a customizable threshold parameter for the sentiment score which determines the given position. The&nbsp;<code>fbpPosition<\/code>&nbsp;function bases the positions on Prophet\u2019s predicted upper and lower bound forecasts (<em>yhat<\/em>). The&nbsp;<code>overallPositions<\/code>&nbsp;function observes the positions set by the two previous functions and returns the same position if they both match. Below I applied all the functions to create a new positions DF:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Applying the position function\nsent_df['sentiment_positions'] = sent_df['sentiment'].apply(\n    lambda x: sentimentPositions(x, thresh=0.2, short=True)\n)\n\n# Filling in missing days with the most recent position value\ndate_index = pd.date_range(sent_df.index[0], sent_df.index[-1])sent_df = sent_df.reindex(\n    date_index,\n    method='ffill'\n)\n\n# Converting index to string\nsent_df.index = sent_df.index.map(lambda x: str(x)[:10])# Adding sentiment positions to the forecast DF\npositions = pred_df.merge(\n    sent_df, \n    right_index=True, \n    left_index=True, \n    how='inner'\n)\n\n# Getting forecast prophet positions\npositions['fbp_positions'] = positions.apply(\n    lambda x: fbpPositions(x, short=True), \n    axis=1\n)\n\n# Getting the overall positions of prophet and sentiment\npositions['tweets_and_fbp'] = positions.apply(\n    lambda x: overallPosition(x), \n    axis=1\n)\n\n# Buy and hold position\npositions['buy_hold'] = 1# Random positions\nrandom.seed(123)\npositions['random_positions'] = random.choices(\n    [1,0,-1], k=len(positions)\n)<\/pre>\n\n\n\n<p>Now each position for each day has been established in a new DF containing positions:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_HcYyE8VfhzEWnTwJyoFIKA.png\" alt=\"\" class=\"wp-image-115\"\/><figcaption class=\"wp-element-caption\">Positions for each trading strategy<\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"2ab1\">Backtesting each Strategy<\/h2>\n\n\n\n<p id=\"a790\">Finally, I can perform the backtest using vectorized backtesting. To do so I need to get the log returns for the entire year of 2021 or at least the returns during the same time frame as the positions DF.<\/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 log returns during the time period set by the positions before\nlog_returns = prices[['ds', 'close']].set_index(\n    'ds'\n).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=\"7c0c\">With the log returns, I can now perform the backtest by multiplying the log return values with the positions DF:<\/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    'tweets_and_fbp', \n    'buy_hold', \n    'random_positions',\n    'sentiment_positions',\n    'fbp_positions'\n]].shift(1)\n\n# The returns during the backtest\nreturns = bt_positions.multiply(\n    log_returns['close'], \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=\"cce8\">In order to compensate for any lookahead bias, I shifted the predictions ahead by 1 day. It is also why I used the \u201c<em>open<\/em>\u201d prices instead of \u201c<em>close<\/em>\u201d when determining trading positions. After the positions have been shifted, I multiplied the log returns with the DF containing the positions, calculated the cumulative sum of each strategy, then inversed the log returns.<\/p>\n\n\n\n<p id=\"71ea\">The final performance of the backtest for each position is now stored within the&nbsp;<code>performance<\/code>&nbsp;variable, which will be visualized in the next section\u2026<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"24b6\">Backtest Visualization<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_Gk3hbKMJ1gc2P53HgEs0eA.png\" alt=\"\" class=\"wp-image-118\" style=\"width:700px;height:371px\"\/><figcaption class=\"wp-element-caption\">The final performance of each strategy<br><\/figcaption><\/figure>\n<\/div>\n\n\n<p>In the visualization above, you can see how well each strategy performed and the final portfolio balance at the end of the year. Let\u2019s clear up the visualization by removing several of the other strategies in order to get a closer look at the Tweet &amp; FBProphet strategy:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_S3g7ZTAM2rGf2ozjST7bIQ.png\" alt=\"\" class=\"wp-image-119\"\/><figcaption class=\"wp-element-caption\">Tweet Sentiment &amp; FBProphet vs Buying &amp; Holding<\/figcaption><\/figure>\n<\/div>\n\n\n<p id=\"12a8\">Here you can see the final performance of the combined strategy of tweet sentiment and Prophet compared to a regular buy and hold strategy.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"816a\">Closing Thoughts<\/h2>\n\n\n\n<p id=\"327c\">This tweet sentiment and Prophet strategy performed fairly well even compared to the simple buy and hold approach. Although it may have started out similar, the strategies later diverged with one eventually outperforming the other.<\/p>\n\n\n\n<p id=\"90b9\">After running the backtest multiple times, I found this performance, based on the parameters I set above, to be one of the better performing backtests. Even though the Prophet positions strategy alone appeared to perform better, overall, it was still more volatile than the sentiment and Prophet strategy, albeit with a slightly higher ending balance. There could be other approaches or strategies to compare this performance to, however, these are probably the most obvious ones. If you feel like another strategy should be included, feel free to try it out yourself by referring to my code in my Github link below.<\/p>\n\n\n\n<p id=\"0992\">The next step, perhaps would be to take this strategy and forward test it with a small amount of capital but first I will need to build a trading bot integrated with a crypto exchange.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Combining two different forms of machine learning is a very exciting concept, especially when it comes to making money. In this case, I combined time series machine learning models with a sentiment analyzer. Two separate forms of machine learning used to create trade signals in the cryptocurrency market. This wasn\u2019t the first time I\u2019ve attempted [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[62],"tags":[],"coding-language":[30],"ready-to-go-solution":[],"qualification":[31,32],"financial-apis-category":[34],"financial-apis-manuals":[39,47,49,75],"class_list":["post-105","post","type-post","status-publish","format-standard","hentry","category-stocks-price-prediction-examples","coding-language-python","qualification-experienced","qualification-guru","financial-apis-category-crypto-market-prices","financial-apis-manuals-end-of-day","financial-apis-manuals-exchanges-data","financial-apis-manuals-financial-news","financial-apis-manuals-newstweets-sentiment"],"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>Use Twitter Sentiment and Facebook Prophet to Trade Crypto? | EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"Discover how combining machine learning and sentiment analysis can help you trade cryptocurrencies and make money.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Use Twitter Sentiment and Facebook Prophet to Trade Crypto?\" \/>\n<meta property=\"og:description\" content=\"Discover how combining machine learning and sentiment analysis can help you trade cryptocurrencies and make money.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto\" \/>\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-03-02T14:56:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T12:45:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2022\/03\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"452\" \/>\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=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto\"},\"author\":{\"name\":\"Marco Santos\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/21a7f35c812f05fb7c4e60a624a3237d\"},\"headline\":\"Use Twitter Sentiment and Facebook Prophet to Trade Crypto?\",\"datePublished\":\"2022-03-02T14:56:00+00:00\",\"dateModified\":\"2025-02-05T12:45:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto\"},\"wordCount\":1418,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_IwQQxvL6X_jyIysCcVO9Ig.png\",\"articleSection\":[\"Stocks Price Predictions Examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto\",\"name\":\"Use Twitter Sentiment and Facebook Prophet to Trade Crypto? | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_IwQQxvL6X_jyIysCcVO9Ig.png\",\"datePublished\":\"2022-03-02T14:56:00+00:00\",\"dateModified\":\"2025-02-05T12:45:54+00:00\",\"description\":\"Discover how combining machine learning and sentiment analysis can help you trade cryptocurrencies and make money.\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#primaryimage\",\"url\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_IwQQxvL6X_jyIysCcVO9Ig.png\",\"contentUrl\":\"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_IwQQxvL6X_jyIysCcVO9Ig.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Use Twitter Sentiment and Facebook Prophet to Trade Crypto?\"}]},{\"@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":"Use Twitter Sentiment and Facebook Prophet to Trade Crypto? | EODHD APIs Academy","description":"Discover how combining machine learning and sentiment analysis can help you trade cryptocurrencies and make money.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto","og_locale":"en_US","og_type":"article","og_title":"Use Twitter Sentiment and Facebook Prophet to Trade Crypto?","og_description":"Discover how combining machine learning and sentiment analysis can help you trade cryptocurrencies and make money.","og_url":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2022-03-02T14:56:00+00:00","article_modified_time":"2025-02-05T12:45:54+00:00","og_image":[{"width":800,"height":452,"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2022\/03\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto.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":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto"},"author":{"name":"Marco Santos","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/21a7f35c812f05fb7c4e60a624a3237d"},"headline":"Use Twitter Sentiment and Facebook Prophet to Trade Crypto?","datePublished":"2022-03-02T14:56:00+00:00","dateModified":"2025-02-05T12:45:54+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto"},"wordCount":1418,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#primaryimage"},"thumbnailUrl":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_IwQQxvL6X_jyIysCcVO9Ig.png","articleSection":["Stocks Price Predictions Examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto","url":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto","name":"Use Twitter Sentiment and Facebook Prophet to Trade Crypto? | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#primaryimage"},"thumbnailUrl":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_IwQQxvL6X_jyIysCcVO9Ig.png","datePublished":"2022-03-02T14:56:00+00:00","dateModified":"2025-02-05T12:45:54+00:00","description":"Discover how combining machine learning and sentiment analysis can help you trade cryptocurrencies and make money.","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#primaryimage","url":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_IwQQxvL6X_jyIysCcVO9Ig.png","contentUrl":"https:\/\/eodhistoricaldata.com\/financial-academy\/wp-content\/uploads\/2022\/03\/1_IwQQxvL6X_jyIysCcVO9Ig.png"},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/use-twitter-sentiment-and-facebook-prophet-to-trade-crypto#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"Use Twitter Sentiment and Facebook Prophet to Trade Crypto?"}]},{"@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-1H","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/105","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=105"}],"version-history":[{"count":3,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"predecessor-version":[{"id":6267,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/105\/revisions\/6267"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=105"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=105"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=105"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=105"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=105"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}