{"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":"markdown","source":"**Created by Sanskar Hasija**\n\n**📊 G-Research Plots + EDA 📊**\n\n**3 NOVEMBER 2021**\n","metadata":{}},{"cell_type":"markdown","source":"# <center>📊G-RESEARCH PLOTS + EDA 📊 </center>","metadata":{"execution":{"iopub.status.busy":"2021-11-02T21:18:08.783444Z","iopub.execute_input":"2021-11-02T21:18:08.784369Z","iopub.status.idle":"2021-11-02T21:18:08.789148Z","shell.execute_reply.started":"2021-11-02T21:18:08.784318Z","shell.execute_reply":"2021-11-02T21:18:08.788509Z"}}},{"cell_type":"markdown","source":"# <center>IMPORTS</center> ","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport plotly.express as px\nimport plotly.graph_objects as go","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-01-03T13:35:15.725245Z","iopub.execute_input":"2022-01-03T13:35:15.725578Z","iopub.status.idle":"2022-01-03T13:35:17.351573Z","shell.execute_reply.started":"2022-01-03T13:35:15.725543Z","shell.execute_reply":"2022-01-03T13:35:17.350593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv('../input/g-research-crypto-forecasting/train.csv') \nasset_details = pd.read_csv('../input/g-research-crypto-forecasting/asset_details.csv') ","metadata":{"execution":{"iopub.status.busy":"2022-01-03T13:35:17.353377Z","iopub.execute_input":"2022-01-03T13:35:17.353646Z","iopub.status.idle":"2022-01-03T13:36:20.627936Z","shell.execute_reply.started":"2022-01-03T13:35:17.353614Z","shell.execute_reply":"2022-01-03T13:36:20.626971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <center>EDA</center> ","metadata":{}},{"cell_type":"markdown","source":"## Column Description\n*   **timestamp**: All timestamps are returned as second Unix timestamps (the number of seconds elapsed since 1970-01-01 00:00:00.000 UTC). Timestamps in this dataset are multiple of 60, indicating minute-by-minute data.\n*   **Asset_ID**: The asset ID corresponding to one of the crytocurrencies (e.g. `Asset_ID = 1` for Bitcoin). The mapping from `Asset_ID` to crypto asset is contained in `asset_details.csv`.\n*   **Count**: Total number of trades in the time interval (last minute).\n*   **Open**:\tOpening price of the time interval (in USD).\n*   **High**:\tHighest price reached during time interval (in USD).\n*   **Low**: Lowest price reached during time interval (in USD).\n*   **Close**:\tClosing price of the time interval (in USD).\n*   **Volume**:\tThe number of cryptoasset units traded during the minute.\n*   **VWAP**: The average price of the asset over the time interval, weighted by volume. VWAP is an aggregated form of trade data.\n*   **Target**: Residual log-returns for the asset over a 15 minute horizon. \n","metadata":{}},{"cell_type":"code","source":"data.head() ","metadata":{"execution":{"iopub.status.busy":"2022-01-03T13:36:20.629237Z","iopub.execute_input":"2022-01-03T13:36:20.629522Z","iopub.status.idle":"2022-01-03T13:36:20.660014Z","shell.execute_reply.started":"2022-01-03T13:36:20.629484Z","shell.execute_reply":"2022-01-03T13:36:20.659083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Checking Null Rows","metadata":{}},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T13:36:20.662643Z","iopub.execute_input":"2022-01-03T13:36:20.663312Z","iopub.status.idle":"2022-01-03T13:36:21.176123Z","shell.execute_reply.started":"2022-01-03T13:36:20.663257Z","shell.execute_reply":"2022-01-03T13:36:21.175115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Total Null Target Rows = \" ,data[\"Target\"].isnull().sum())\nprint(\"Percentage of NUll rows in Training Data = {:.2f}%\".format(data[\"Target\"].isnull().sum()*100 / data.shape[0] ))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:36:21.177762Z","iopub.execute_input":"2022-01-03T13:36:21.178532Z","iopub.status.idle":"2022-01-03T13:36:21.301617Z","shell.execute_reply.started":"2022-01-03T13:36:21.178478Z","shell.execute_reply":"2022-01-03T13:36:21.300681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <center>DATA DISTRIBUTION</center> ","metadata":{}},{"cell_type":"markdown","source":"### Training Data Distribution among differnet Assets (Crypto Currencies)","metadata":{}},{"cell_type":"code","source":"asset_count= []\nfor i in range(14):\n    count = (data[\"Asset_ID\"]==i).sum()\n    asset_count.append(count)\nfig = px.bar(x = asset_details.sort_values(\"Asset_ID\")[\"Asset_Name\"],\n             y = asset_count , \n             color = asset_count ,\n             color_continuous_scale=\"Emrld\") \nfig.update_xaxes(title=\"Assets\")\nfig.update_yaxes(title = \"Number of Rows\")\nfig.update_layout(showlegend = True,\n    title = {\n        'text': 'Data Distribution ',\n        'y':0.95,\n        'x':0.5,\n        'xanchor': 'center',\n        'yanchor': 'top'} ,\n        template=\"plotly_white\")\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:36:21.303631Z","iopub.execute_input":"2022-01-03T13:36:21.304062Z","iopub.status.idle":"2022-01-03T13:36:23.126393Z","shell.execute_reply.started":"2022-01-03T13:36:21.304007Z","shell.execute_reply":"2022-01-03T13:36:23.125358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <center>CANDELSTICK CHARTS</center> ","metadata":{}},{"cell_type":"code","source":"def crypto_df(asset_id ,data= data ):\n    df = data[data[\"Asset_ID\"]==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\nbtc = crypto_df(asset_id = 1)\neth = crypto_df (asset_id = 6 )\nltc = crypto_df(asset_id = 9 )","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:27:14.589892Z","iopub.execute_input":"2022-01-03T13:27:14.59021Z","iopub.status.idle":"2022-01-03T13:27:15.765936Z","shell.execute_reply.started":"2022-01-03T13:27:14.59017Z","shell.execute_reply":"2022-01-03T13:27:15.764925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def candelstick_chart(data,title):\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 = True)\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    template=\"plotly_white\")\n\n    candlestick.update_yaxes(title_text = 'Price in USD', ticksuffix = '$')\n    return candlestick","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:27:15.767155Z","iopub.execute_input":"2022-01-03T13:27:15.76741Z","iopub.status.idle":"2022-01-03T13:27:15.775415Z","shell.execute_reply.started":"2022-01-03T13:27:15.767379Z","shell.execute_reply":"2022-01-03T13:27:15.774467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Bitcoin(BTC) Candelstick Chart for last 100 rows","metadata":{}},{"cell_type":"code","source":"btc_plot = candelstick_chart(btc[-100:],title = \"Bitcoin(BTC)\")\nbtc_plot.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:27:15.77767Z","iopub.execute_input":"2022-01-03T13:27:15.778062Z","iopub.status.idle":"2022-01-03T13:27:15.833418Z","shell.execute_reply.started":"2022-01-03T13:27:15.778025Z","shell.execute_reply":"2022-01-03T13:27:15.832841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Litecoin(LTC) Candelstick Chart for last 2500 rows","metadata":{}},{"cell_type":"code","source":"ltc_plot = candelstick_chart(ltc[-2500:],title = \"Litecoin(LTC)\")\nltc_plot.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:27:15.834369Z","iopub.execute_input":"2022-01-03T13:27:15.834994Z","iopub.status.idle":"2022-01-03T13:27:15.947984Z","shell.execute_reply.started":"2022-01-03T13:27:15.834959Z","shell.execute_reply":"2022-01-03T13:27:15.94731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <center>OHLC CHARTS</center> ","metadata":{}},{"cell_type":"code","source":"def ohlc_chart(data,title):\n    ohlc = go.Figure(data = [go.Ohlc(x =data.index, \n                                               open = data[('Open')], \n                                               high = data[('High')], \n                                               low = data[('Low')], \n                                               close = data[('Close')])])\n    ohlc.update_xaxes(title_text = 'Time',\n                             rangeslider_visible = True)\n\n    ohlc.update_layout(\n    title = {\n        'text': '{:} OHLC Chart'.format(title),\n        'y':0.9,\n        'x':0.5,\n        'xanchor': 'center',\n        'yanchor': 'top'},\n        template=\"plotly_white\")\n\n    ohlc.update_yaxes(title_text = 'Price in USD', ticksuffix = '$')\n    return ohlc","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:27:15.949218Z","iopub.execute_input":"2022-01-03T13:27:15.949799Z","iopub.status.idle":"2022-01-03T13:27:15.957147Z","shell.execute_reply.started":"2022-01-03T13:27:15.949765Z","shell.execute_reply":"2022-01-03T13:27:15.956249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Bitcoin(BTC) OHLC Chart for first 200 rows","metadata":{}},{"cell_type":"code","source":"ohlc_chart(btc[:200], title = \"Bitcoin(BTC)\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:27:15.95908Z","iopub.execute_input":"2022-01-03T13:27:15.95937Z","iopub.status.idle":"2022-01-03T13:27:16.014167Z","shell.execute_reply.started":"2022-01-03T13:27:15.959328Z","shell.execute_reply":"2022-01-03T13:27:16.013608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Ethereum(ETH) OHLC Chart for last 100 rows","metadata":{}},{"cell_type":"code","source":"ohlc_chart(eth[-100:], title = \"Ethereum(ETH)\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:27:16.168937Z","iopub.execute_input":"2022-01-03T13:27:16.169427Z","iopub.status.idle":"2022-01-03T13:27:16.218705Z","shell.execute_reply.started":"2022-01-03T13:27:16.169375Z","shell.execute_reply":"2022-01-03T13:27:16.217658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <center>AREA PLOTS</center> ","metadata":{}},{"cell_type":"code","source":"def vol_traded(data ,title,color):\n    area = px.area(data_frame=data,\n               x = data.index ,\n               y = \"Volume\",\n               markers = True)\n    area.update_traces(line_color=color)\n    area.update_xaxes(\n        title_text = 'Time',\n        rangeslider_visible = True)\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        template=\"plotly_white\")\n    return area","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:27:16.48578Z","iopub.execute_input":"2022-01-03T13:27:16.486074Z","iopub.status.idle":"2022-01-03T13:27:16.493078Z","shell.execute_reply.started":"2022-01-03T13:27:16.486039Z","shell.execute_reply":"2022-01-03T13:27:16.492333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Ethereum(ETH) Volume Traded for last 50 rows","metadata":{}},{"cell_type":"code","source":"vol_traded(eth[-50:], \"Ethereum (ETH)\",color = \"Red\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:27:16.779932Z","iopub.execute_input":"2022-01-03T13:27:16.780249Z","iopub.status.idle":"2022-01-03T13:27:16.879352Z","shell.execute_reply.started":"2022-01-03T13:27:16.780215Z","shell.execute_reply":"2022-01-03T13:27:16.878514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Litecoin(LTC) Volume Traded for last 300 rows","metadata":{}},{"cell_type":"code","source":"vol_traded(ltc[-300:], \"Litecoin(LTC)\",color = \"Blue\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-03T13:26:59.03295Z","iopub.execute_input":"2022-01-03T13:26:59.033366Z","iopub.status.idle":"2022-01-03T13:26:59.139089Z","shell.execute_reply.started":"2022-01-03T13:26:59.033335Z","shell.execute_reply":"2022-01-03T13:26:59.138265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <center>If you find this notebook useful, support with an upvote👍</center>","metadata":{}}]}