{"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":"import pandas as pd\nimport numpy as np\nfrom datetime import datetime\nimport time\nfrom datetime import datetime\nimport matplotlib.pyplot as plt\nimport plotly.graph_objects as go\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-01-11T17:12:45.755935Z","iopub.execute_input":"2022-01-11T17:12:45.75627Z","iopub.status.idle":"2022-01-11T17:12:46.583884Z","shell.execute_reply.started":"2022-01-11T17:12:45.756166Z","shell.execute_reply":"2022-01-11T17:12:46.583183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = \"/kaggle/input/g-research-crypto-forecasting/\"\ndf_train = pd.read_csv(path + \"train.csv\")\ndf_test = pd.read_csv(path + \"example_test.csv\")\ndf_asset_details = pd.read_csv(path + \"asset_details.csv\")\ndf_supp_train = pd.read_csv(path + \"supplemental_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:12:46.585608Z","iopub.execute_input":"2022-01-11T17:12:46.585865Z","iopub.status.idle":"2022-01-11T17:13:53.521979Z","shell.execute_reply.started":"2022-01-11T17:12:46.585825Z","shell.execute_reply":"2022-01-11T17:13:53.521265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:53.523424Z","iopub.execute_input":"2022-01-11T17:13:53.523692Z","iopub.status.idle":"2022-01-11T17:13:53.54943Z","shell.execute_reply.started":"2022-01-11T17:13:53.523651Z","shell.execute_reply":"2022-01-11T17:13:53.548776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.info(10)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:53.551266Z","iopub.execute_input":"2022-01-11T17:13:53.551638Z","iopub.status.idle":"2022-01-11T17:13:53.571495Z","shell.execute_reply.started":"2022-01-11T17:13:53.5516Z","shell.execute_reply":"2022-01-11T17:13:53.570571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_asset_details.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:53.572987Z","iopub.execute_input":"2022-01-11T17:13:53.573389Z","iopub.status.idle":"2022-01-11T17:13:53.585119Z","shell.execute_reply.started":"2022-01-11T17:13:53.57335Z","shell.execute_reply":"2022-01-11T17:13:53.584278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train[\"Asset_ID\"].unique()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:53.586693Z","iopub.execute_input":"2022-01-11T17:13:53.586992Z","iopub.status.idle":"2022-01-11T17:13:53.709931Z","shell.execute_reply.started":"2022-01-11T17:13:53.586957Z","shell.execute_reply":"2022-01-11T17:13:53.709128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'figure.figsize':(20,10)})\nasset_count= []\nfor i in range(14):\n    count = (df_train[\"Asset_ID\"]==i).sum()\n    asset_count.append(count)\nfig = sns.barplot(x = df_asset_details.sort_values(\"Asset_ID\")[\"Asset_Name\"],\n             y = asset_count,palette=\"Blues_d\") \nfig.set(xlabel =\"Assets\", ylabel = \"Number of Rows\", title ='Data Distribution')","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:53.711076Z","iopub.execute_input":"2022-01-11T17:13:53.711415Z","iopub.status.idle":"2022-01-11T17:13:54.685459Z","shell.execute_reply.started":"2022-01-11T17:13:53.711378Z","shell.execute_reply":"2022-01-11T17:13:54.684777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_asset_details['Name'] = df_asset_details['Asset_Name'].str.replace(\" \",\"_\")","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:54.6865Z","iopub.execute_input":"2022-01-11T17:13:54.687342Z","iopub.status.idle":"2022-01-11T17:13:54.693271Z","shell.execute_reply.started":"2022-01-11T17:13:54.687304Z","shell.execute_reply":"2022-01-11T17:13:54.692495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_asset_details","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:54.694595Z","iopub.execute_input":"2022-01-11T17:13:54.694843Z","iopub.status.idle":"2022-01-11T17:13:54.709537Z","shell.execute_reply.started":"2022-01-11T17:13:54.694809Z","shell.execute_reply":"2022-01-11T17:13:54.708756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Checking Time Range\ndict1={}\nfor i in range(14):\n    dict1[df_asset_details[df_asset_details['Asset_ID']==i]['Name'].values[0]] = df_train[df_train[\"Asset_ID\"]==i].set_index(\"timestamp\") \n    beg = datetime.fromtimestamp(dict1[df_asset_details[df_asset_details['Asset_ID']==i]['Name'].values[0]].index[0]).strftime(\"%A, %B %d, %Y %I:%M:%S\") \n    end = datetime.fromtimestamp(dict1[df_asset_details[df_asset_details['Asset_ID']==i]['Name'].values[0]].index[-1]).strftime(\"%A, %B %d, %Y %I:%M:%S\") \n    print(df_asset_details[df_asset_details['Asset_ID']==i]['Name'].values[0],'data goes from ', beg, ' to ', end) ","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:54.713071Z","iopub.execute_input":"2022-01-11T17:13:54.71364Z","iopub.status.idle":"2022-01-11T17:13:58.677181Z","shell.execute_reply.started":"2022-01-11T17:13:54.713611Z","shell.execute_reply":"2022-01-11T17:13:58.676301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Heatmap: Features of BTC","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(8,6))\nsns.heatmap(dict1['Bitcoin'][['Count','Open','High','Low','Close','Volume','VWAP','Target']].corr(), \n            vmin=-1.0, vmax=1.0, annot=True, cmap='PuBu_r', linewidths=0.1)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:58.678738Z","iopub.execute_input":"2022-01-11T17:13:58.679019Z","iopub.status.idle":"2022-01-11T17:13:59.591Z","shell.execute_reply.started":"2022-01-11T17:13:58.67898Z","shell.execute_reply":"2022-01-11T17:13:59.590298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Candlesticks Charts For Last 200 Minutes","metadata":{}},{"cell_type":"code","source":"for i in dict1: \n    mini = dict1[i].iloc[-200:] # Select recent data rows\n\n    fig = go.Figure(data=[go.Candlestick(x=mini.index, open=mini['Open'], high=mini['High'], low=mini['Low'], close=mini['Close'])])\n    fig.update_xaxes(title_text=\"$\")\n    fig.update_yaxes(title_text=\"Index\")\n    fig.update_layout(title=i+\" Price, 200 Last Minutes\")\n    fig.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:59.592211Z","iopub.execute_input":"2022-01-11T17:13:59.592592Z","iopub.status.idle":"2022-01-11T17:13:59.850292Z","shell.execute_reply.started":"2022-01-11T17:13:59.592555Z","shell.execute_reply":"2022-01-11T17:13:59.849527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Plotting closing prices","metadata":{}},{"cell_type":"code","source":"for i in dict1: \n    plt.figure(figsize=(15,4))\n    dict1[i] = dict1[i].reindex(range(dict1[i].index[0],dict1[i].index[-1]+60,60),method='pad')\n    plt.plot(dict1[i]['Close'], color='green', label=i)\n    plt.legend()\n    plt.xlabel('Time (timestamp)')\n    plt.ylabel(i)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-11T17:13:59.851703Z","iopub.execute_input":"2022-01-11T17:13:59.851956Z","iopub.status.idle":"2022-01-11T17:14:19.831693Z","shell.execute_reply.started":"2022-01-11T17:13:59.85192Z","shell.execute_reply":"2022-01-11T17:14:19.831038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Finished","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}