{"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":"# <span style='color:#A80808'>Goal</span>\nForecast short term returns in 14 popular cryptocurrencies.\n\n# <span style='color:#A80808'>Metric</span>\nSubmissions are evaluated on a weighted version of the Pearson correlation coefficient.\n\n![](https://point-banque.fr/wp-content/uploads/2021/09/crypto-802x485.jpg)","metadata":{}},{"cell_type":"markdown","source":"# <span style='color:#A80808'>Data</span>\n\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":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nplt.rcParams['axes.facecolor'] = 'gray'\nimport plotly.express as px\nimport seaborn as sns\n\nimport warnings\nwarnings.simplefilter('ignore')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-03-17T19:43:10.416421Z","iopub.execute_input":"2022-03-17T19:43:10.417409Z","iopub.status.idle":"2022-03-17T19:43:12.893980Z","shell.execute_reply.started":"2022-03-17T19:43:10.417297Z","shell.execute_reply":"2022-03-17T19:43:12.892972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <span style='color:#A80808'>Load Data</span>","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv('../input/g-research-crypto-forecasting/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-17T19:43:53.933367Z","iopub.execute_input":"2022-03-17T19:43:53.933677Z","iopub.status.idle":"2022-03-17T19:44:55.918194Z","shell.execute_reply.started":"2022-03-17T19:43:53.933643Z","shell.execute_reply":"2022-03-17T19:44:55.917321Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['time'] = pd.to_datetime(train.timestamp, unit='s')\ntrain = train.drop('timestamp', axis=1)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T19:48:56.772578Z","iopub.execute_input":"2022-03-17T19:48:56.773479Z","iopub.status.idle":"2022-03-17T19:48:59.788838Z","shell.execute_reply.started":"2022-03-17T19:48:56.773422Z","shell.execute_reply":"2022-03-17T19:48:59.788059Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <span style='color:#A80808'>Assets</span>","metadata":{}},{"cell_type":"code","source":"train.Asset_ID.unique()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T19:49:55.196972Z","iopub.execute_input":"2022-03-17T19:49:55.197541Z","iopub.status.idle":"2022-03-17T19:49:55.346165Z","shell.execute_reply.started":"2022-03-17T19:49:55.197489Z","shell.execute_reply":"2022-03-17T19:49:55.345041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"asset_details = pd.read_csv('../input/g-research-crypto-forecasting/asset_details.csv')\nasset_details","metadata":{"execution":{"iopub.status.busy":"2022-03-17T19:50:33.298590Z","iopub.execute_input":"2022-03-17T19:50:33.299516Z","iopub.status.idle":"2022-03-17T19:50:33.342209Z","shell.execute_reply.started":"2022-03-17T19:50:33.299465Z","shell.execute_reply":"2022-03-17T19:50:33.341320Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,7))\nplt.bar(asset_details.Asset_Name, asset_details.Weight, color='y')\nplt.title(f'Asset weights', fontsize=16)\nplt.ylabel('Weight', fontsize=16)\nplt.xticks(rotation=90, fontsize=16)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T19:53:39.254341Z","iopub.execute_input":"2022-03-17T19:53:39.255217Z","iopub.status.idle":"2022-03-17T19:53:39.525166Z","shell.execute_reply.started":"2022-03-17T19:53:39.255175Z","shell.execute_reply":"2022-03-17T19:53:39.524247Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <span style='color:#A80808'>Target: 15mn residualized returns</span>","metadata":{}},{"cell_type":"code","source":"# Histogram\nplt.figure(figsize=(10,5))\ntrain.Target.hist(bins=100, color='yellow')\nplt.xlabel('Return', fontsize=16)\nplt.ylabel('Log count', fontsize=16)\nplt.yscale('log')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T19:56:49.414470Z","iopub.execute_input":"2022-03-17T19:56:49.414934Z","iopub.status.idle":"2022-03-17T19:56:51.139129Z","shell.execute_reply.started":"2022-03-17T19:56:49.414900Z","shell.execute_reply":"2022-03-17T19:56:51.138065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <span style='color:#A80808'>Morning vs Afternoon</span>","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\n\nplt.subplot(1,2,1)\ntrain[train.time.dt.hour<12].Target.hist(bins=100, color='orange', label='Morning')\ntrain[train.time.dt.hour>=12].Target.hist(bins=100, color='yellow', label='Afternoon')\nplt.xlabel('Return', fontsize=16)\nplt.ylabel('Log count', fontsize=16)\nplt.yscale('log')\nplt.legend()\n\nplt.subplot(1,2,2)\ntrain[train.time.dt.hour>=12].Target.hist(bins=100, color='yellow', label='Afternoon')\ntrain[train.time.dt.hour<12].Target.hist(bins=100, color='orange', label='Morning')\nplt.xlabel('Return', fontsize=16)\nplt.ylabel('Log count', fontsize=16)\nplt.yscale('log')\nplt.legend()\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T19:58:38.152831Z","iopub.execute_input":"2022-03-17T19:58:38.153198Z","iopub.status.idle":"2022-03-17T19:58:53.706315Z","shell.execute_reply.started":"2022-03-17T19:58:38.153160Z","shell.execute_reply":"2022-03-17T19:58:53.705607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for Asset_ID in train.Asset_ID.unique():\n    plt.figure(figsize=(10,5))\n    # extract data for each asset\n    df = train[train.Asset_ID==Asset_ID]\n    df.Target.hist(bins=100, color='yellow')\n    plt.title(f'{asset_details.Asset_Name[asset_details.Asset_ID==Asset_ID].iloc[0]}', fontsize=16)\n    plt.xlabel('Return', fontsize=16)\n    plt.ylabel('Log count', fontsize=16)\n    plt.yscale('log')\n    plt.tight_layout()\n\n    plt.show()\n\n    print('\\n\\n')\n    ","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:05:43.311943Z","iopub.execute_input":"2022-03-17T20:05:43.312286Z","iopub.status.idle":"2022-03-17T20:06:02.325219Z","shell.execute_reply.started":"2022-03-17T20:05:43.312248Z","shell.execute_reply":"2022-03-17T20:06:02.323985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}