{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install plotly","metadata":{"execution":{"iopub.status.busy":"2021-12-09T13:24:07.103582Z","iopub.execute_input":"2021-12-09T13:24:07.104033Z","iopub.status.idle":"2021-12-09T13:24:17.657608Z","shell.execute_reply.started":"2021-12-09T13:24:07.103919Z","shell.execute_reply":"2021-12-09T13:24:17.656731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# G-Research Crypto Forecasting","metadata":{"id":"6bf88c79"}},{"cell_type":"markdown","source":"Cryptocurrencies are very popular but have the disavantage to be more volatile than classical stock prices. The first cryptocurrency, Bitcoin, was created in 2008 by Satoshi Nakamoto. Bitcoin is created as a decentralized system based on the blockchain technology. However, in the next years, creation of many other cryptocurrencies has been exploded. The expansion and democratization of these methods have opened new horizons for stock market. \n\nIn this Kaggle competition, the aim is to predict trends about cryptocurrencies by using the most well-knowledge currencies. It is important to keep in mind that forecasting stock market is a hard task and thus, forecasting trends in cryptocurrencies is harder. ","metadata":{"id":"5a4e32b5"}},{"cell_type":"markdown","source":"__Datasets__","metadata":{"id":"29d046b6"}},{"cell_type":"markdown","source":"In this competition, 5 files are available : \n- A first train set,\n- A supplementary train set,\n- An asset set with information about cryptocurrencies,\n- An example test,\n- An example test submission.","metadata":{"id":"32f12177"}},{"cell_type":"markdown","source":"Only three datasets (*the two train sets & the asset set*) were used in this exploration. ","metadata":{"id":"sZywJ3-7rbZ7"}},{"cell_type":"markdown","source":"__Configuration and Utils__","metadata":{"id":"7da81c8c"}},{"cell_type":"code","source":"# system libraries\nimport warnings\nwarnings.filterwarnings('ignore')\nwarnings.simplefilter(action='ignore', category=FutureWarning)\nimport logging\nlogging.disable(logging.CRITICAL)\nimport gc\n\n# data manipulation libraries\nimport pandas as pd\nimport numpy as np\n\n# graphical libraries\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as px\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\n\nfrom functools import reduce\nfrom datetime import datetime\nimport time","metadata":{"id":"d9c81e0b","execution":{"iopub.status.busy":"2021-12-09T13:24:17.660937Z","iopub.execute_input":"2021-12-09T13:24:17.661215Z","iopub.status.idle":"2021-12-09T13:24:20.093661Z","shell.execute_reply.started":"2021-12-09T13:24:17.661185Z","shell.execute_reply":"2021-12-09T13:24:20.092691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dtype_dict ={\"open\" : \"float16\",\n             \"close\" : \"float16\",\n             \"high\" : \"float16\",\n             \"low\" : \"float16\",\n             \"volume\" : \"float16\",\n             \"vwap\" : \"float16\",\n             \"target\" : \"float16\"}","metadata":{"execution":{"iopub.status.busy":"2021-12-09T13:24:20.095271Z","iopub.execute_input":"2021-12-09T13:24:20.095821Z","iopub.status.idle":"2021-12-09T13:24:20.101625Z","shell.execute_reply.started":"2021-12-09T13:24:20.095771Z","shell.execute_reply":"2021-12-09T13:24:20.100367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def crypto_df(asset_id, data):\n    # Copied from https://www.kaggle.com/odins0n/g-research-plots-eda\n    df = data[data[\"asset_name\"] == asset_id].reset_index(drop=True)\n    df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')\n    df = df.set_index('timestamp')\n    return df\n\n\ndef candelstick_chart(data, title):\n    # Copied from https://www.kaggle.com/odins0n/g-research-plots-eda\n    candlestick = go.Figure(data=[go.Candlestick(x=data.index,\n                                                 open=data[('open')],\n                                                 high=data[('high')],\n                                                 low=data[('low')],\n                                                 close=data[('close')])])\n    candlestick.update_xaxes(title_text='Time',\n                             rangeslider_visible=False)\n\n    candlestick.update_layout(\n        title={\n            'text': '{:} Candelstick Chart'.format(title),\n            'y': 0.90,\n            'x': 0.5,\n            'xanchor': 'center',\n            'yanchor': 'top'})\n\n    candlestick.update_yaxes(title_text='Price in USD', ticksuffix='$')\n    return candlestick\n\n\ndef vol_traded(data, title, color):\n    # Copied from https://www.kaggle.com/odins0n/g-research-plots-eda\n    area = px.area(data_frame=data,\n                   x=data.index,\n                   y=\"volume\")\n    area.update_traces(line_color=color)\n    area.update_xaxes(\n        title_text='Time',\n        rangeslider_visible=False)\n    area.update_yaxes(title_text='Number of trades every minute')\n    area.update_layout(showlegend=True,\n                       title={\n                           'text': '{:} Volume Traded'.format(title),\n                           'y': 0.94,\n                           'x': 0.5,\n                           'xanchor': 'center',\n                           'yanchor': 'top'})\n    return area","metadata":{"id":"7a408d2b","execution":{"iopub.status.busy":"2021-12-09T13:24:20.104516Z","iopub.execute_input":"2021-12-09T13:24:20.104875Z","iopub.status.idle":"2021-12-09T13:24:20.117847Z","shell.execute_reply.started":"2021-12-09T13:24:20.104831Z","shell.execute_reply":"2021-12-09T13:24:20.117042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1) Preprocessing","metadata":{"id":"da5412fc"}},{"cell_type":"code","source":"# Importing datasets\n\ndf = pd.read_csv(\"../input/g-research-crypto-forecasting/train.csv\", dtype=dtype_dict)\ndf_sup = pd.read_csv(\"../input/g-research-crypto-forecasting/supplemental_train.csv\", dtype=dtype_dict)\nasset = pd.read_csv(\"../input/g-research-crypto-forecasting/asset_details.csv\")\ndf.head()","metadata":{"id":"7bc602a8","outputId":"3168b840-437e-416d-89a4-afa33ad672a3","execution":{"iopub.status.busy":"2021-12-09T13:24:20.119319Z","iopub.execute_input":"2021-12-09T13:24:20.120101Z","iopub.status.idle":"2021-12-09T13:25:32.647000Z","shell.execute_reply.started":"2021-12-09T13:24:20.120055Z","shell.execute_reply":"2021-12-09T13:25:32.645762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"id":"_ijHaMygqdO-","outputId":"83e4ce42-b5d8-407b-be7b-488d1b838ad0","execution":{"iopub.status.busy":"2021-12-09T13:25:32.649294Z","iopub.execute_input":"2021-12-09T13:25:32.650872Z","iopub.status.idle":"2021-12-09T13:25:32.660586Z","shell.execute_reply.started":"2021-12-09T13:25:32.650790Z","shell.execute_reply":"2021-12-09T13:25:32.659416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Columns of the dataset :\n* timestamp - A timestamp for the minute covered by the row.\n* Asset_ID - An ID code for the cryptoasset.\n* Count - The number of trades that took place this minute.\n* Open - The USD price at the beginning of the minute.\n* High - The highest USD price during the minute.\n* Low - The lowest USD price during the minute.\n* Close - The USD price at the end of the minute.\n* Volume - The number of cryptoasset units traded during the minute.\n* VWAP - The volume weighted average price for the minute.\n* Target - 15 minute residualized returns.","metadata":{"id":"7cbe3ea0"}},{"cell_type":"markdown","source":"Target column contains values to predict ([Information about target calculus](https://www.kaggle.com/cstein06/tutorial-to-the-g-research-crypto-competition?cellIds=49&kernelSessionId=78721864)). ","metadata":{"id":"OCdQMer5r3B8"}},{"cell_type":"code","source":"# Creating an unique df with data\ndf = df.append(df_sup,\n               ignore_index=True,\n               verify_integrity=True)","metadata":{"id":"hpDUHBRBo3Jl","execution":{"iopub.status.busy":"2021-12-09T13:25:32.662278Z","iopub.execute_input":"2021-12-09T13:25:32.663006Z","iopub.status.idle":"2021-12-09T13:25:33.513637Z","shell.execute_reply.started":"2021-12-09T13:25:32.662952Z","shell.execute_reply":"2021-12-09T13:25:33.512624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"id":"EFpozEDlqg6z","outputId":"39c8f68b-020e-40d5-af43-f95d7363a1e8","execution":{"iopub.status.busy":"2021-12-09T13:25:33.515509Z","iopub.execute_input":"2021-12-09T13:25:33.515866Z","iopub.status.idle":"2021-12-09T13:25:33.523506Z","shell.execute_reply.started":"2021-12-09T13:25:33.515821Z","shell.execute_reply":"2021-12-09T13:25:33.522502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Merging dataset to obtain name of each cryptocurrency\ndf = pd.merge(df, asset, on=\"Asset_ID\")\ndf = df[[\"timestamp\", \"Asset_Name\", \"Count\",\n         \"Open\", \"High\", \"Low\",\n         \"Close\", \"Volume\", \"VWAP\",\n         \"Target\"]]\ndf.columns = [\"timestamp\", \"asset_name\", \"count\",\n              \"open\", \"high\", \"low\",\n              \"close\", \"volume\", \"vwap\",\n              \"target\"]\ndf.head()","metadata":{"id":"3a5f228d","outputId":"25c58fb2-8141-4d22-fd16-6e5d6e794af1","execution":{"iopub.status.busy":"2021-12-09T13:25:33.525021Z","iopub.execute_input":"2021-12-09T13:25:33.525264Z","iopub.status.idle":"2021-12-09T13:25:42.867538Z","shell.execute_reply.started":"2021-12-09T13:25:33.525236Z","shell.execute_reply":"2021-12-09T13:25:42.866536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Missing values exploration\ndf.isnull().mean() * 100","metadata":{"id":"b8fa098a","outputId":"20bef8fc-000b-4eb6-bb08-544245c04f0b","execution":{"iopub.status.busy":"2021-12-09T13:25:42.871719Z","iopub.execute_input":"2021-12-09T13:25:42.871974Z","iopub.status.idle":"2021-12-09T13:25:46.121632Z","shell.execute_reply.started":"2021-12-09T13:25:42.871942Z","shell.execute_reply":"2021-12-09T13:25:46.120727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Only 3% of data is missing in the target column. Choice was taken to drop these data. ","metadata":{"id":"73c71964"}},{"cell_type":"code","source":"# Deleting missing data\ndf.dropna(inplace=True)","metadata":{"id":"25976221","execution":{"iopub.status.busy":"2021-12-09T13:25:46.122878Z","iopub.execute_input":"2021-12-09T13:25:46.123116Z","iopub.status.idle":"2021-12-09T13:25:51.369555Z","shell.execute_reply.started":"2021-12-09T13:25:46.123086Z","shell.execute_reply":"2021-12-09T13:25:51.368417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 2) Exploratory Analysis","metadata":{"id":"f0cec8f0"}},{"cell_type":"markdown","source":"### a) Candlestick representation","metadata":{"id":"af50152d"}},{"cell_type":"markdown","source":"In this part, data will be visualised with the help of candlestick graphs. This kind of graph is used to see information about open, close, high and low values of a currency during a certain period of time. Here, the last 120 minutes were reprensented.\nTo realize the graph, a dataframe for each currency was created. Then, Plotly library was used to displayed the graphs.","metadata":{"id":"bC7wRLU5uPIN"}},{"cell_type":"code","source":"btc = crypto_df(\"Bitcoin\", data=df)\neth = crypto_df(\"Ethereum\", data=df)\niota = crypto_df(\"IOTA\", data=df)","metadata":{"id":"f25388a5","execution":{"iopub.status.busy":"2021-12-09T13:25:51.371310Z","iopub.execute_input":"2021-12-09T13:25:51.371638Z","iopub.status.idle":"2021-12-09T13:26:03.379938Z","shell.execute_reply.started":"2021-12-09T13:25:51.371566Z","shell.execute_reply":"2021-12-09T13:26:03.378971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- Bitcoin","metadata":{"id":"8fe15b7d"}},{"cell_type":"code","source":"btc_plot = candelstick_chart(btc[-120:], title=\"Bitcoin\")\nbtc_plot.show()","metadata":{"id":"b95a958f","outputId":"5690915f-3df4-451d-88eb-68752a2788bc","execution":{"iopub.status.busy":"2021-12-09T13:26:03.381147Z","iopub.execute_input":"2021-12-09T13:26:03.381369Z","iopub.status.idle":"2021-12-09T13:26:03.563210Z","shell.execute_reply.started":"2021-12-09T13:26:03.381343Z","shell.execute_reply":"2021-12-09T13:26:03.562303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- Ethereum","metadata":{"id":"329bef39"}},{"cell_type":"code","source":"eth_plot = candelstick_chart(eth[-120:], title=\"Ethereum\")\neth_plot.show()","metadata":{"id":"ea21011c","outputId":"998d22b8-8cfe-4382-b375-4c6a51297432","execution":{"iopub.status.busy":"2021-12-09T13:26:03.564432Z","iopub.execute_input":"2021-12-09T13:26:03.564704Z","iopub.status.idle":"2021-12-09T13:26:03.588628Z","shell.execute_reply.started":"2021-12-09T13:26:03.564671Z","shell.execute_reply":"2021-12-09T13:26:03.587824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- IOTA","metadata":{"id":"4aa8447a"}},{"cell_type":"code","source":"iota_plot = candelstick_chart(iota[-120:], title=\"IOTA\")\niota_plot.show()","metadata":{"id":"66a6b393","outputId":"fd698318-2af1-4cb4-fd69-c58d0edb6b17","execution":{"iopub.status.busy":"2021-12-09T13:26:03.589978Z","iopub.execute_input":"2021-12-09T13:26:03.590800Z","iopub.status.idle":"2021-12-09T13:26:03.615183Z","shell.execute_reply.started":"2021-12-09T13:26:03.590754Z","shell.execute_reply":"2021-12-09T13:26:03.614526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Visually, we can conclude that some currencies are more stable than others. The ups and downs seems to follow the same series but the amplitude are variable. For instance, IOTA shows great difference between the parameters ohlc.","metadata":{"id":"i0E1QP6Vw9px"}},{"cell_type":"markdown","source":"### b) Volume exchange","metadata":{"id":"085d2677"}},{"cell_type":"markdown","source":"Second visualisation is about volume traded during the last 60 minutes. ","metadata":{"id":"Siuq-Goz1VQX"}},{"cell_type":"markdown","source":"- Bitcoin","metadata":{"id":"kpLVdL5p1gb0"}},{"cell_type":"code","source":"vol_traded(btc[-60:], \"Bitcoin\", color=\"Blue\")","metadata":{"id":"748000da","outputId":"c07a89ff-2581-4ec1-bfc1-0debbc8fe207","execution":{"iopub.status.busy":"2021-12-09T13:26:03.616243Z","iopub.execute_input":"2021-12-09T13:26:03.616848Z","iopub.status.idle":"2021-12-09T13:26:04.917145Z","shell.execute_reply.started":"2021-12-09T13:26:03.616795Z","shell.execute_reply":"2021-12-09T13:26:04.916219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- Ethereum","metadata":{"id":"GgvnuQ_Y1rVp"}},{"cell_type":"code","source":"vol_traded(eth[-60:], \"Ethereum\", color=\"Green\")","metadata":{"id":"c6644420","outputId":"ef226b86-510c-4a9a-b044-dc1487fbba70","execution":{"iopub.status.busy":"2021-12-09T13:26:04.918523Z","iopub.execute_input":"2021-12-09T13:26:04.918809Z","iopub.status.idle":"2021-12-09T13:26:05.007921Z","shell.execute_reply.started":"2021-12-09T13:26:04.918776Z","shell.execute_reply":"2021-12-09T13:26:05.006686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- IOTA","metadata":{"id":"WzqU68uN1ylt"}},{"cell_type":"code","source":"vol_traded(iota[-60:], \"IOTA\", color=\"Green\")","metadata":{"id":"c1982f1c","outputId":"389d8ae3-961c-4681-9299-086cedbdc8e4","execution":{"iopub.status.busy":"2021-12-09T13:26:05.009726Z","iopub.execute_input":"2021-12-09T13:26:05.010010Z","iopub.status.idle":"2021-12-09T13:26:05.094987Z","shell.execute_reply.started":"2021-12-09T13:26:05.009976Z","shell.execute_reply":"2021-12-09T13:26:05.093833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### c) Central tendency analysis","metadata":{"id":"4ab1965e"}},{"cell_type":"code","source":"df.groupby(\"asset_name\").mean()","metadata":{"id":"4ae63b97","outputId":"8978815b-5ffc-459a-9b3b-35114a58f877","execution":{"iopub.status.busy":"2021-12-09T13:26:05.096924Z","iopub.execute_input":"2021-12-09T13:26:05.097254Z","iopub.status.idle":"2021-12-09T13:26:09.867361Z","shell.execute_reply.started":"2021-12-09T13:26:05.097210Z","shell.execute_reply":"2021-12-09T13:26:09.866543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.groupby(\"asset_name\").median()","metadata":{"id":"56c18d67","outputId":"1cb8d7fb-b827-4695-aed4-b90a8f46ea33","execution":{"iopub.status.busy":"2021-12-09T13:26:09.868889Z","iopub.execute_input":"2021-12-09T13:26:09.869680Z","iopub.status.idle":"2021-12-09T13:26:17.605192Z","shell.execute_reply.started":"2021-12-09T13:26:09.869619Z","shell.execute_reply":"2021-12-09T13:26:17.604278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.groupby(\"asset_name\").std()","metadata":{"id":"14113778","outputId":"2db77343-d170-4a4e-d005-66aee2cd5c90","execution":{"iopub.status.busy":"2021-12-09T13:26:17.606546Z","iopub.execute_input":"2021-12-09T13:26:17.606802Z","iopub.status.idle":"2021-12-09T13:26:23.385749Z","shell.execute_reply.started":"2021-12-09T13:26:17.606770Z","shell.execute_reply":"2021-12-09T13:26:23.384780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### d) Correlation between cryptocurrencies","metadata":{"id":"f5df25d9"}},{"cell_type":"code","source":"df_close = df.copy()\ndf_close = df_close[[\"timestamp\", \"asset_name\", \"close\"]]\ndf_close[\"timestamp\"] = df_close[\"timestamp\"].apply(\n    lambda x: datetime.fromtimestamp(x))\ndf_close[\"date\"] = df_close[\"timestamp\"].astype('datetime64[s]')\ndf_close.set_index(\"date\", inplace=True)\ndf_close.drop(\"timestamp\", axis=1, inplace=True)\ndf_close = df_close[[\"asset_name\", \"close\"]]\ndf_close[\"close\"] = df_close[\"close\"].apply(lambda x: np.log(x))","metadata":{"id":"82d44784","execution":{"iopub.status.busy":"2021-12-09T13:26:23.386941Z","iopub.execute_input":"2021-12-09T13:26:23.387186Z","iopub.status.idle":"2021-12-09T13:27:50.554578Z","shell.execute_reply.started":"2021-12-09T13:26:23.387158Z","shell.execute_reply":"2021-12-09T13:27:50.553569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_close_2021 = df_close.loc['01/01/2021':'01/06/2021']\ndf_close_2021.reset_index(inplace=True)\ndf_close_2021 = pd.pivot_table(\n    df_close_2021, values=\"close\", columns=\"asset_name\", index=\"date\")","metadata":{"id":"ed4c5e7e","execution":{"iopub.status.busy":"2021-12-09T13:27:50.556013Z","iopub.execute_input":"2021-12-09T13:27:50.556349Z","iopub.status.idle":"2021-12-09T13:27:53.431061Z","shell.execute_reply.started":"2021-12-09T13:27:50.556309Z","shell.execute_reply":"2021-12-09T13:27:53.430035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nsns.heatmap(df_close_2021.diff().corr(),\n            linewidths=.5,\n            annot=True,\n            square=True,\n            cmap=\"viridis\")\nplt.xlabel(\"Asset Name\")\nplt.ylabel(\"Asset Name\")\nplt.title(\"Correlation matrix between each cryptocurrency during the first semester (2021)\")\nplt.show()","metadata":{"id":"11f2bdeb","outputId":"d854ec5f-26f1-4e06-fd7c-ac1fa3f37cb1","execution":{"iopub.status.busy":"2021-12-09T13:27:53.432747Z","iopub.execute_input":"2021-12-09T13:27:53.433292Z","iopub.status.idle":"2021-12-09T13:27:54.702450Z","shell.execute_reply.started":"2021-12-09T13:27:53.433255Z","shell.execute_reply":"2021-12-09T13:27:54.701629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del df_close\ndel df_close_2021\ngc.collect()","metadata":{"id":"453cd74c","outputId":"39b94d65-5cbc-4574-f985-fcbedaedc4e2","execution":{"iopub.status.busy":"2021-12-09T13:27:54.704037Z","iopub.execute_input":"2021-12-09T13:27:54.704711Z","iopub.status.idle":"2021-12-09T13:27:54.957564Z","shell.execute_reply.started":"2021-12-09T13:27:54.704665Z","shell.execute_reply":"2021-12-09T13:27:54.956564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 3) Features Engineering","metadata":{"id":"8819ae51"}},{"cell_type":"code","source":"dataset = [btc, eth, iota]\n\n\ncols = ['open', 'close', \"high\", \"low\"]\n\nfor i in dataset:\n    for j in cols:\n        i[\"log_\"+j] = i[j].apply(lambda x: np.log(x))","metadata":{"execution":{"iopub.status.busy":"2021-12-09T13:27:54.959120Z","iopub.execute_input":"2021-12-09T13:27:54.959386Z","iopub.status.idle":"2021-12-09T13:28:43.379976Z","shell.execute_reply.started":"2021-12-09T13:27:54.959353Z","shell.execute_reply":"2021-12-09T13:28:43.378802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- Variables from *Vijha et al. 2020*","metadata":{"id":"c7c633c9"}},{"cell_type":"markdown","source":"1. Stock High minus Low price (H-L)\n2. Stock Close minus Open price (O-C)\n3. Stock price’s seven days’ moving average (7 DAYS MA)\n4. Stock price’s fourteen days’ moving average (14 DAYS MA)\n5. Stock price’s twenty one days’ moving average (21 DAYS MA)\n6. Stock price’s standard deviation for the past seven days (7 DAYS STD DEV)","metadata":{"id":"5f47d652"}},{"cell_type":"code","source":"for i in dataset:\n    i[\"H-L\"] = i[\"log_high\"] - i[\"log_low\"]\n    i[\"O-C\"] = i[\"log_open\"] - i[\"log_close\"]\n    i[\"MA_7d\"] = i[\"log_close\"].rolling(10080).mean()\n    i[\"MA_14d\"] = i[\"log_close\"].rolling(20160).mean()\n    i[\"MA_21d\"] = i[\"log_close\"].rolling(30240).mean()\n    i[\"STD_7d\"] = i[\"log_close\"].rolling(10080).std()","metadata":{"id":"8238042a","execution":{"iopub.status.busy":"2021-12-09T13:28:43.381439Z","iopub.execute_input":"2021-12-09T13:28:43.381964Z","iopub.status.idle":"2021-12-09T13:28:44.114001Z","shell.execute_reply.started":"2021-12-09T13:28:43.381913Z","shell.execute_reply":"2021-12-09T13:28:44.113179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = btc.append(eth)\ndata = data.append(iota)","metadata":{"execution":{"iopub.status.busy":"2021-12-09T13:28:44.118311Z","iopub.execute_input":"2021-12-09T13:28:44.118668Z","iopub.status.idle":"2021-12-09T13:28:44.851655Z","shell.execute_reply.started":"2021-12-09T13:28:44.118630Z","shell.execute_reply":"2021-12-09T13:28:44.850615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.tail(3)","metadata":{"execution":{"iopub.status.busy":"2021-12-09T13:28:44.853244Z","iopub.execute_input":"2021-12-09T13:28:44.853633Z","iopub.status.idle":"2021-12-09T13:28:44.881876Z","shell.execute_reply.started":"2021-12-09T13:28:44.853518Z","shell.execute_reply":"2021-12-09T13:28:44.880997Z"},"trusted":true},"execution_count":null,"outputs":[]}]}