{"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-10T13:34:56.223625Z","iopub.execute_input":"2022-01-10T13:34:56.224063Z","iopub.status.idle":"2022-01-10T13:34:57.346864Z","shell.execute_reply.started":"2022-01-10T13:34:56.22394Z","shell.execute_reply":"2022-01-10T13:34:57.345734Z"},"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-10T13:34:57.348655Z","iopub.execute_input":"2022-01-10T13:34:57.348878Z","iopub.status.idle":"2022-01-10T13:36:10.618678Z","shell.execute_reply.started":"2022-01-10T13:34:57.348844Z","shell.execute_reply":"2022-01-10T13:36:10.61774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-10T13:36:10.619758Z","iopub.execute_input":"2022-01-10T13:36:10.619981Z","iopub.status.idle":"2022-01-10T13:36:10.646418Z","shell.execute_reply.started":"2022-01-10T13:36:10.619954Z","shell.execute_reply":"2022-01-10T13:36:10.645507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-10T13:36:10.648271Z","iopub.execute_input":"2022-01-10T13:36:10.649078Z","iopub.status.idle":"2022-01-10T13:36:10.672596Z","shell.execute_reply.started":"2022-01-10T13:36:10.649044Z","shell.execute_reply":"2022-01-10T13:36:10.671984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_asset_details.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-10T13:36:10.67378Z","iopub.execute_input":"2022-01-10T13:36:10.674285Z","iopub.status.idle":"2022-01-10T13:36:10.686296Z","shell.execute_reply.started":"2022-01-10T13:36:10.674247Z","shell.execute_reply":"2022-01-10T13:36:10.685445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train[\"Asset_ID\"].unique()","metadata":{"execution":{"iopub.status.busy":"2022-01-10T13:36:10.688743Z","iopub.execute_input":"2022-01-10T13:36:10.689582Z","iopub.status.idle":"2022-01-10T13:36:10.839042Z","shell.execute_reply.started":"2022-01-10T13:36:10.689518Z","shell.execute_reply":"2022-01-10T13:36:10.838191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'figure.figsize':(15,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-10T13:36:10.840777Z","iopub.execute_input":"2022-01-10T13:36:10.841064Z","iopub.status.idle":"2022-01-10T13:36:11.9151Z","shell.execute_reply.started":"2022-01-10T13:36:10.841031Z","shell.execute_reply":"2022-01-10T13:36:11.914136Z"},"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-10T13:36:11.916759Z","iopub.execute_input":"2022-01-10T13:36:11.917088Z","iopub.status.idle":"2022-01-10T13:36:11.924078Z","shell.execute_reply.started":"2022-01-10T13:36:11.917043Z","shell.execute_reply":"2022-01-10T13:36:11.923402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_asset_details","metadata":{"execution":{"iopub.status.busy":"2022-01-10T13:36:11.925225Z","iopub.execute_input":"2022-01-10T13:36:11.925718Z","iopub.status.idle":"2022-01-10T13:36:11.945927Z","shell.execute_reply.started":"2022-01-10T13:36:11.92568Z","shell.execute_reply":"2022-01-10T13:36:11.944901Z"},"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-10T13:36:11.948845Z","iopub.execute_input":"2022-01-10T13:36:11.949307Z","iopub.status.idle":"2022-01-10T13:36:18.361532Z","shell.execute_reply.started":"2022-01-10T13:36:11.94926Z","shell.execute_reply":"2022-01-10T13:36:18.360292Z"},"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='coolwarm', linewidths=0.1)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-10T13:36:18.362992Z","iopub.execute_input":"2022-01-10T13:36:18.363347Z","iopub.status.idle":"2022-01-10T13:36:19.544834Z","shell.execute_reply.started":"2022-01-10T13:36:18.363304Z","shell.execute_reply":"2022-01-10T13:36:19.543871Z"},"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-10T13:36:19.546155Z","iopub.execute_input":"2022-01-10T13:36:19.5464Z","iopub.status.idle":"2022-01-10T13:36:19.883581Z","shell.execute_reply.started":"2022-01-10T13:36:19.546367Z","shell.execute_reply":"2022-01-10T13:36:19.882976Z"},"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-10T13:36:19.884436Z","iopub.execute_input":"2022-01-10T13:36:19.884635Z","iopub.status.idle":"2022-01-10T13:36:43.631188Z","shell.execute_reply.started":"2022-01-10T13:36:19.88461Z","shell.execute_reply":"2022-01-10T13:36:43.630191Z"},"trusted":true},"execution_count":null,"outputs":[]}]}