{"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":"# Import","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-04T11:15:48.962607Z","iopub.execute_input":"2021-12-04T11:15:48.962927Z","iopub.status.idle":"2021-12-04T11:15:48.967938Z","shell.execute_reply.started":"2021-12-04T11:15:48.962885Z","shell.execute_reply":"2021-12-04T11:15:48.966985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load Data","metadata":{}},{"cell_type":"code","source":"df=pd.read_csv('../input/g-research-crypto-forecasting/train.csv')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T11:15:48.969404Z","iopub.execute_input":"2021-12-04T11:15:48.969900Z","iopub.status.idle":"2021-12-04T11:16:31.351287Z","shell.execute_reply.started":"2021-12-04T11:15:48.969854Z","shell.execute_reply":"2021-12-04T11:16:31.350399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=df[df['Asset_ID']==0]# Only use 0 asset id","metadata":{"execution":{"iopub.status.busy":"2021-12-04T11:16:31.487781Z","iopub.execute_input":"2021-12-04T11:16:31.488019Z","iopub.status.idle":"2021-12-04T11:16:33.477806Z","shell.execute_reply.started":"2021-12-04T11:16:31.487990Z","shell.execute_reply":"2021-12-04T11:16:33.476785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#  Compuation\n\nif you are confused about np.exp(r)-1 then you can see Sylvain Thibault 's comment on this notebook  https://www.kaggle.com/swaralipibose/explaining-the-target-variable-clearly-with-proof/comments","metadata":{}},{"cell_type":"code","source":"# make sure that df only has samples for 1 asset id\ndef compute(df):\n    \n    R=list()\n    c=list(df['Close'])\n    for i in range(df.shape[0]):\n        future=c[min([i+16,df.shape[0]-1])]\n        past=c[min([i+1,df.shape[0]-1])]\n        R.append(future/past)\n    df['R']=R\n    df['R']=np.log(df['R'])\n    df['pred']=np.exp(df['R'])-1\n    return df\ndf=compute(df)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T11:27:12.477843Z","iopub.execute_input":"2021-12-04T11:27:12.478257Z","iopub.status.idle":"2021-12-04T11:27:19.577460Z","shell.execute_reply.started":"2021-12-04T11:27:12.478214Z","shell.execute_reply":"2021-12-04T11:27:19.576276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T11:27:21.661922Z","iopub.execute_input":"2021-12-04T11:27:21.662259Z","iopub.status.idle":"2021-12-04T11:27:21.686525Z","shell.execute_reply.started":"2021-12-04T11:27:21.662226Z","shell.execute_reply":"2021-12-04T11:27:21.685503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Evaluation","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nk,_,_=plt.hist((df['pred']==df['Target']).astype(int))","metadata":{"execution":{"iopub.status.busy":"2021-12-04T11:33:22.744748Z","iopub.execute_input":"2021-12-04T11:33:22.745590Z","iopub.status.idle":"2021-12-04T11:33:23.018924Z","shell.execute_reply.started":"2021-12-04T11:33:22.745537Z","shell.execute_reply":"2021-12-04T11:33:23.017112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Percentage of erros:',k[-1]/np.sum(k))","metadata":{"execution":{"iopub.status.busy":"2021-12-04T11:34:06.811216Z","iopub.execute_input":"2021-12-04T11:34:06.811546Z","iopub.status.idle":"2021-12-04T11:34:06.817564Z","shell.execute_reply.started":"2021-12-04T11:34:06.811503Z","shell.execute_reply":"2021-12-04T11:34:06.816138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.mean(np.square(df['pred']-df['Target']))","metadata":{"execution":{"iopub.status.busy":"2021-12-04T11:29:46.777459Z","iopub.execute_input":"2021-12-04T11:29:46.778549Z","iopub.status.idle":"2021-12-04T11:29:46.799175Z","shell.execute_reply.started":"2021-12-04T11:29:46.778493Z","shell.execute_reply":"2021-12-04T11:29:46.798383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Thank you","metadata":{}}]}