{"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 numpy as np\nimport pandas as pd\nimport gresearch_crypto","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:00:26.838146Z","iopub.execute_input":"2022-01-04T14:00:26.838524Z","iopub.status.idle":"2022-01-04T14:00:26.887577Z","shell.execute_reply.started":"2022-01-04T14:00:26.838433Z","shell.execute_reply":"2022-01-04T14:00:26.886924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/g-research-crypto-forecasting/train.csv', dtype={'Asset_ID': 'int8'})\ndf['datetime'] = pd.to_datetime(df['timestamp'], unit='s')\ndf = df.set_index('datetime').drop('timestamp', axis=1)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:00:26.888870Z","iopub.execute_input":"2022-01-04T14:00:26.889102Z","iopub.status.idle":"2022-01-04T14:01:23.540438Z","shell.execute_reply.started":"2022-01-04T14:00:26.889076Z","shell.execute_reply":"2022-01-04T14:01:23.539673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#df_train = df[((df.index.year < 2021) | ((df.index.year == 2021) & (df.index.month <= 8) ))].copy()\ntrain = len(df) - 20174\ndf_train = df[:train]\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:01:23.541912Z","iopub.execute_input":"2022-01-04T14:01:23.542225Z","iopub.status.idle":"2022-01-04T14:01:23.557487Z","shell.execute_reply.started":"2022-01-04T14:01:23.542184Z","shell.execute_reply":"2022-01-04T14:01:23.556553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#df_test = df[(df.index.year == 2021) & (df.index.month > 8)].copy()\ndf_test = df[train:]\ndf_test.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:01:23.559440Z","iopub.execute_input":"2022-01-04T14:01:23.560170Z","iopub.status.idle":"2022-01-04T14:01:23.586895Z","shell.execute_reply.started":"2022-01-04T14:01:23.560136Z","shell.execute_reply":"2022-01-04T14:01:23.586288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(df.shape, df_train.shape, df_test.shape, df_train.shape[0]+df_test.shape[0])","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:01:23.587859Z","iopub.execute_input":"2022-01-04T14:01:23.588084Z","iopub.status.idle":"2022-01-04T14:01:23.593323Z","shell.execute_reply.started":"2022-01-04T14:01:23.588058Z","shell.execute_reply":"2022-01-04T14:01:23.592682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = df_test.dropna()\ndf_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:01:23.594214Z","iopub.execute_input":"2022-01-04T14:01:23.594732Z","iopub.status.idle":"2022-01-04T14:01:23.614554Z","shell.execute_reply.started":"2022-01-04T14:01:23.594703Z","shell.execute_reply":"2022-01-04T14:01:23.613556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Your code here to train a model (or multiple models) using df_train","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:01:23.616190Z","iopub.execute_input":"2022-01-04T14:01:23.616866Z","iopub.status.idle":"2022-01-04T14:01:23.620267Z","shell.execute_reply.started":"2022-01-04T14:01:23.616789Z","shell.execute_reply":"2022-01-04T14:01:23.619677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['Prediction'] = 0","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:01:23.621603Z","iopub.execute_input":"2022-01-04T14:01:23.622380Z","iopub.status.idle":"2022-01-04T14:01:23.639156Z","shell.execute_reply.started":"2022-01-04T14:01:23.622333Z","shell.execute_reply":"2022-01-04T14:01:23.638455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, row in df_test.iterrows():\n    # your code here \n    # asset = row['Asset_ID']\n    # model = models[row['Asset_ID']]\n    # x_test = get_features(row)\n    # y_pred = model.predict(pd.DataFrame([x_test]))[0]\n    y_pred = np.random.rand()\n    df_test.loc[i, 'Prediction'] = y_pred","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:01:23.640499Z","iopub.execute_input":"2022-01-04T14:01:23.640805Z","iopub.status.idle":"2022-01-04T14:01:31.152482Z","shell.execute_reply.started":"2022-01-04T14:01:23.640747Z","shell.execute_reply":"2022-01-04T14:01:31.151503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mse = np.mean(((df_test['Prediction'].to_numpy() - df_test['Target'].to_numpy()))**2)\nprint(mse)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:02:20.686632Z","iopub.execute_input":"2022-01-04T14:02:20.686928Z","iopub.status.idle":"2022-01-04T14:02:20.692537Z","shell.execute_reply.started":"2022-01-04T14:02:20.686897Z","shell.execute_reply":"2022-01-04T14:02:20.691943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"real_pred = False\nif real_pred:\n    env = gresearch_crypto.make_env()\n    iter_test = env.iter_test()\n    for df_x, df_pred in iter_test:\n        df_x['datetime'] = pd.to_datetime(df_x['timestamp'], unit='s')\n        for _, row in df_x.iterrows():\n            try:\n                # Your code here\n                # model = models[row['Asset_ID']]\n                # x_test = get_features(row)\n                # y_pred = model.predict(pd.DataFrame([x_test]))[0]\n                y_pred = 0\n                df_pred.loc[df_pred['row_id'] == row['row_id'], 'Target'] = y_pred\n            except:\n                df_pred.loc[df_pred['row_id'] == row['row_id'], 'Target'] = 0\n        df_pred['Target'] = df_pred['Target'].fillna(0)\n        env.predict(df_pred)","metadata":{"execution":{"iopub.status.busy":"2022-01-04T14:01:31.163020Z","iopub.execute_input":"2022-01-04T14:01:31.163235Z","iopub.status.idle":"2022-01-04T14:01:31.178143Z","shell.execute_reply.started":"2022-01-04T14:01:31.163210Z","shell.execute_reply":"2022-01-04T14:01:31.177461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}