{"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 os\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nimport time\nfrom datetime import datetime\nfrom sklearn.preprocessing import MinMaxScaler\nfrom keras.preprocessing.sequence import TimeseriesGenerator\nfrom tensorflow.keras.optimizers import Adam\nfrom keras.models import Sequential\nfrom tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint, TensorBoard\nfrom keras.layers import SimpleRNN, LSTM, Dense, Dropout, Masking, Embedding, Dense, Activation, Flatten, LSTM, TimeDistributed, RepeatVector,Input\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:18:39.033828Z","iopub.status.busy":"2022-01-12T13:18:39.027262Z","iopub.status.idle":"2022-01-12T13:18:45.968825Z","shell.execute_reply":"2022-01-12T13:18:45.968084Z","shell.execute_reply.started":"2022-01-12T12:36:56.773061Z"},"papermill":{"duration":7.002152,"end_time":"2022-01-12T13:18:45.969016","exception":false,"start_time":"2022-01-12T13:18:38.966864","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_train = pd.read_csv('/kaggle/input/g-research-crypto-forecasting/train.csv')","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:18:46.052887Z","iopub.status.busy":"2022-01-12T13:18:46.052294Z","iopub.status.idle":"2022-01-12T13:19:40.721360Z","shell.execute_reply":"2022-01-12T13:19:40.721924Z","shell.execute_reply.started":"2022-01-12T12:37:03.754172Z"},"papermill":{"duration":54.711578,"end_time":"2022-01-12T13:19:40.722126","exception":false,"start_time":"2022-01-12T13:18:46.010548","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_asset = pd.read_csv('/kaggle/input/g-research-crypto-forecasting/asset_details.csv')\nds_example = pd.read_csv('/kaggle/input/g-research-crypto-forecasting/example_test.csv')\nds_suplement_train = pd.read_csv('/kaggle/input/g-research-crypto-forecasting/supplemental_train.csv')\nds_example_submission = pd.read_csv('/kaggle/input/g-research-crypto-forecasting/example_sample_submission.csv')","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:40.805128Z","iopub.status.busy":"2022-01-12T13:19:40.804195Z","iopub.status.idle":"2022-01-12T13:19:45.618897Z","shell.execute_reply":"2022-01-12T13:19:45.618050Z","shell.execute_reply.started":"2022-01-12T12:38:11.502482Z"},"papermill":{"duration":4.857309,"end_time":"2022-01-12T13:19:45.619054","exception":false,"start_time":"2022-01-12T13:19:40.761745","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_train.head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:45.704528Z","iopub.status.busy":"2022-01-12T13:19:45.699102Z","iopub.status.idle":"2022-01-12T13:19:45.720600Z","shell.execute_reply":"2022-01-12T13:19:45.720134Z","shell.execute_reply.started":"2022-01-12T12:38:17.149045Z"},"papermill":{"duration":0.062915,"end_time":"2022-01-12T13:19:45.720738","exception":false,"start_time":"2022-01-12T13:19:45.657823","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_asset.head(100).sort_values(by=['Asset_ID'])","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:45.816690Z","iopub.status.busy":"2022-01-12T13:19:45.811729Z","iopub.status.idle":"2022-01-12T13:19:45.819897Z","shell.execute_reply":"2022-01-12T13:19:45.820282Z","shell.execute_reply.started":"2022-01-12T12:38:17.180867Z"},"papermill":{"duration":0.059857,"end_time":"2022-01-12T13:19:45.820469","exception":false,"start_time":"2022-01-12T13:19:45.760612","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_example.head()\nds_example[ds_example['Asset_ID']==3]","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:45.915168Z","iopub.status.busy":"2022-01-12T13:19:45.914272Z","iopub.status.idle":"2022-01-12T13:19:45.918358Z","shell.execute_reply":"2022-01-12T13:19:45.917872Z","shell.execute_reply.started":"2022-01-12T12:38:17.203413Z"},"papermill":{"duration":0.057983,"end_time":"2022-01-12T13:19:45.918523","exception":false,"start_time":"2022-01-12T13:19:45.860540","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_suplement_train.head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:46.013468Z","iopub.status.busy":"2022-01-12T13:19:46.012502Z","iopub.status.idle":"2022-01-12T13:19:46.016644Z","shell.execute_reply":"2022-01-12T13:19:46.016125Z","shell.execute_reply.started":"2022-01-12T12:38:17.222613Z"},"papermill":{"duration":0.057324,"end_time":"2022-01-12T13:19:46.016781","exception":false,"start_time":"2022-01-12T13:19:45.959457","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_example_submission.head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:46.106187Z","iopub.status.busy":"2022-01-12T13:19:46.105252Z","iopub.status.idle":"2022-01-12T13:19:46.108721Z","shell.execute_reply":"2022-01-12T13:19:46.109158Z","shell.execute_reply.started":"2022-01-12T12:38:17.247098Z"},"papermill":{"duration":0.052043,"end_time":"2022-01-12T13:19:46.109317","exception":false,"start_time":"2022-01-12T13:19:46.057274","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_train[ds_train['timestamp']==1514764860]","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:46.208762Z","iopub.status.busy":"2022-01-12T13:19:46.207773Z","iopub.status.idle":"2022-01-12T13:19:46.283241Z","shell.execute_reply":"2022-01-12T13:19:46.282730Z","shell.execute_reply.started":"2022-01-12T12:38:17.266209Z"},"papermill":{"duration":0.132559,"end_time":"2022-01-12T13:19:46.283379","exception":false,"start_time":"2022-01-12T13:19:46.150820","status":"completed"},"scrolled":true,"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_train[ds_train['Target']==np.nan]\nds_train.isna().sum()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:46.371913Z","iopub.status.busy":"2022-01-12T13:19:46.371284Z","iopub.status.idle":"2022-01-12T13:19:46.859294Z","shell.execute_reply":"2022-01-12T13:19:46.858787Z","shell.execute_reply.started":"2022-01-12T12:38:17.368266Z"},"papermill":{"duration":0.534903,"end_time":"2022-01-12T13:19:46.859444","exception":false,"start_time":"2022-01-12T13:19:46.324541","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define plot space\nfig, ax = plt.subplots(figsize=(10, 6))\n\n# Create bar plot\nax.bar(ds_asset['Asset_Name'], \n       ds_asset['Weight'])\nplt.xlabel('Asset Name')\nplt.ylabel('Weight')\nplt.xticks(rotation=70)\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:46.954301Z","iopub.status.busy":"2022-01-12T13:19:46.953673Z","iopub.status.idle":"2022-01-12T13:19:47.222581Z","shell.execute_reply":"2022-01-12T13:19:47.222031Z","shell.execute_reply.started":"2022-01-12T12:38:17.875908Z"},"papermill":{"duration":0.320383,"end_time":"2022-01-12T13:19:47.222721","exception":false,"start_time":"2022-01-12T13:19:46.902338","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_train_copy = ds_train\nds_train_copy['date'] = pd.to_datetime(ds_train_copy['timestamp'], unit='s')\nds_train_copy.head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:47.318032Z","iopub.status.busy":"2022-01-12T13:19:47.317360Z","iopub.status.idle":"2022-01-12T13:19:48.972584Z","shell.execute_reply":"2022-01-12T13:19:48.973041Z","shell.execute_reply.started":"2022-01-12T12:38:18.176858Z"},"papermill":{"duration":1.706508,"end_time":"2022-01-12T13:19:48.973208","exception":false,"start_time":"2022-01-12T13:19:47.266700","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eth = ds_train_copy[ds_train_copy['Asset_ID']==6].set_index('timestamp')\neth.head(100)","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:49.073924Z","iopub.status.busy":"2022-01-12T13:19:49.072825Z","iopub.status.idle":"2022-01-12T13:19:49.440586Z","shell.execute_reply":"2022-01-12T13:19:49.440092Z","shell.execute_reply.started":"2022-01-12T12:38:19.942753Z"},"papermill":{"duration":0.42481,"end_time":"2022-01-12T13:19:49.440733","exception":false,"start_time":"2022-01-12T13:19:49.015923","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eth.info(show_counts=True)","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:49.535266Z","iopub.status.busy":"2022-01-12T13:19:49.534578Z","iopub.status.idle":"2022-01-12T13:19:49.588278Z","shell.execute_reply":"2022-01-12T13:19:49.587683Z","shell.execute_reply.started":"2022-01-12T12:38:20.359341Z"},"papermill":{"duration":0.102742,"end_time":"2022-01-12T13:19:49.588425","exception":false,"start_time":"2022-01-12T13:19:49.485683","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eth.isna().sum()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:49.677926Z","iopub.status.busy":"2022-01-12T13:19:49.677276Z","iopub.status.idle":"2022-01-12T13:19:49.721882Z","shell.execute_reply":"2022-01-12T13:19:49.721443Z","shell.execute_reply.started":"2022-01-12T12:38:20.420514Z"},"papermill":{"duration":0.090117,"end_time":"2022-01-12T13:19:49.722016","exception":false,"start_time":"2022-01-12T13:19:49.631899","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"btcsh = ds_train_copy[ds_train_copy['Asset_ID']==2].set_index('timestamp')\nbnc = ds_train_copy[ds_train_copy['Asset_ID']==0].set_index('timestamp')\nbtc = ds_train_copy[ds_train_copy['Asset_ID']==1].set_index('timestamp')\neos = ds_train_copy[ds_train_copy['Asset_ID']==5].set_index('timestamp')\neth_csc = ds_train_copy[ds_train_copy['Asset_ID']==7].set_index('timestamp')\nltc = ds_train_copy[ds_train_copy['Asset_ID']==9].set_index('timestamp')\nmon = ds_train_copy[ds_train_copy['Asset_ID']==11].set_index('timestamp')\ntro = ds_train_copy[ds_train_copy['Asset_ID']==13].set_index('timestamp')\nste = ds_train_copy[ds_train_copy['Asset_ID']==12].set_index('timestamp')\ncar = ds_train_copy[ds_train_copy['Asset_ID']==3].set_index('timestamp')\niot = ds_train_copy[ds_train_copy['Asset_ID']==8].set_index('timestamp')\nmak = ds_train_copy[ds_train_copy['Asset_ID']==10].set_index('timestamp')\ndog = ds_train_copy[ds_train_copy['Asset_ID']==4].set_index('timestamp')","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:49.812937Z","iopub.status.busy":"2022-01-12T13:19:49.812362Z","iopub.status.idle":"2022-01-12T13:19:53.993279Z","shell.execute_reply":"2022-01-12T13:19:53.992761Z","shell.execute_reply.started":"2022-01-12T12:38:20.469817Z"},"papermill":{"duration":4.227755,"end_time":"2022-01-12T13:19:53.993436","exception":false,"start_time":"2022-01-12T13:19:49.765681","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dog.head().count()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:54.085285Z","iopub.status.busy":"2022-01-12T13:19:54.084253Z","iopub.status.idle":"2022-01-12T13:19:54.092876Z","shell.execute_reply":"2022-01-12T13:19:54.093396Z","shell.execute_reply.started":"2022-01-12T12:38:24.929447Z"},"papermill":{"duration":0.056383,"end_time":"2022-01-12T13:19:54.093576","exception":false,"start_time":"2022-01-12T13:19:54.037193","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"btcsh.head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:54.187484Z","iopub.status.busy":"2022-01-12T13:19:54.186499Z","iopub.status.idle":"2022-01-12T13:19:54.201750Z","shell.execute_reply":"2022-01-12T13:19:54.202195Z","shell.execute_reply.started":"2022-01-12T12:38:24.942066Z"},"papermill":{"duration":0.062662,"end_time":"2022-01-12T13:19:54.202357","exception":false,"start_time":"2022-01-12T13:19:54.139695","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"beg_btcsh = btcsh.index[0].astype('datetime64[s]')\nend_btcsh = btcsh.index[-1].astype('datetime64[s]')\nbeg_bnc = bnc.index[0].astype('datetime64[s]')\nend_bnc = bnc.index[-1].astype('datetime64[s]')\nbeg_btc = btc.index[0].astype('datetime64[s]')\nend_btc = btc.index[-1].astype('datetime64[s]')\nbeg_eos = eos.index[0].astype('datetime64[s]')\nend_eos = eos.index[-1].astype('datetime64[s]')\nbeg_eth_csc = eth_csc.index[0].astype('datetime64[s]')\nend_eth_csc = eth_csc.index[-1].astype('datetime64[s]')\nbeg_ltc = ltc.index[0].astype('datetime64[s]')\nend_ltc = ltc.index[-1].astype('datetime64[s]')\nbeg_mon = mon.index[0].astype('datetime64[s]')\nend_mon = mon.index[-1].astype('datetime64[s]')\nbeg_tro = tro.index[0].astype('datetime64[s]')\nend_tro = tro.index[-1].astype('datetime64[s]')\nbeg_eth = eth.index[0].astype('datetime64[s]')\nend_eth = eth.index[-1].astype('datetime64[s]')\nbeg_ste = ste.index[0].astype('datetime64[s]')\nend_ste = ste.index[-1].astype('datetime64[s]')\nbeg_car = car.index[0].astype('datetime64[s]')\nend_car = car.index[-1].astype('datetime64[s]')\nbeg_iot = iot.index[0].astype('datetime64[s]')\nend_iot = iot.index[-1].astype('datetime64[s]')\nbeg_mak = mak.index[0].astype('datetime64[s]')\nend_mak = mak.index[-1].astype('datetime64[s]')\n# beg_dog = dog.index[0].astype('datetime64[s]')\n# end_dog = dog.index[-1].astype('datetime64[s]')\nprint('Bitcoin Cash     :', beg_btcsh, 'to', end_btcsh)\nprint('Binance Coin     :', beg_bnc, 'to', end_bnc)\nprint('Bitcoin          :', beg_btc, 'to', end_btc)\nprint('EOS IO           :', beg_eos, 'to', end_eos)\nprint('Etherium Classic :', beg_eth_csc, 'to', end_eth_csc)\nprint('Ethereum         :', beg_eth, 'to', end_eth)\nprint('Lite Coin        :', beg_ltc, 'to', end_ltc)\nprint('Monero           :', beg_mon, 'to', end_mon)\nprint('TRON             :', beg_tro, 'to', end_tro)\nprint('Stellar          :', beg_ste, 'to', end_ste)\nprint('Cardano          :', beg_car, 'to', end_car)\nprint('IOTA             :', beg_iot, 'to', end_iot)\nprint('Maker            :', beg_mak, 'to', end_mak)\n# print('Dogecoin         :', beg_dog, 'to', end_dog)","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:54.296536Z","iopub.status.busy":"2022-01-12T13:19:54.295456Z","iopub.status.idle":"2022-01-12T13:19:54.315378Z","shell.execute_reply":"2022-01-12T13:19:54.315975Z","shell.execute_reply.started":"2022-01-12T12:38:24.967549Z"},"papermill":{"duration":0.068539,"end_time":"2022-01-12T13:19:54.316142","exception":false,"start_time":"2022-01-12T13:19:54.247603","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(eth.index[1:]-eth.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:54.410998Z","iopub.status.busy":"2022-01-12T13:19:54.410380Z","iopub.status.idle":"2022-01-12T13:19:54.434459Z","shell.execute_reply":"2022-01-12T13:19:54.434925Z","shell.execute_reply.started":"2022-01-12T12:38:24.997212Z"},"papermill":{"duration":0.073166,"end_time":"2022-01-12T13:19:54.435103","exception":false,"start_time":"2022-01-12T13:19:54.361937","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eth = eth.reindex(range(eth.index[0],eth.index[-1]+60,60),method='pad')","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:54.530682Z","iopub.status.busy":"2022-01-12T13:19:54.530013Z","iopub.status.idle":"2022-01-12T13:19:54.950068Z","shell.execute_reply":"2022-01-12T13:19:54.949533Z","shell.execute_reply.started":"2022-01-12T12:38:25.031436Z"},"papermill":{"duration":0.470071,"end_time":"2022-01-12T13:19:54.950206","exception":false,"start_time":"2022-01-12T13:19:54.480135","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(eth.index[1:]-eth.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:55.045753Z","iopub.status.busy":"2022-01-12T13:19:55.044809Z","iopub.status.idle":"2022-01-12T13:19:55.095946Z","shell.execute_reply":"2022-01-12T13:19:55.096493Z","shell.execute_reply.started":"2022-01-12T12:38:25.498374Z"},"papermill":{"duration":0.101492,"end_time":"2022-01-12T13:19:55.096668","exception":false,"start_time":"2022-01-12T13:19:54.995176","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(btc.index[1:]-btc.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:55.191968Z","iopub.status.busy":"2022-01-12T13:19:55.191278Z","iopub.status.idle":"2022-01-12T13:19:55.217590Z","shell.execute_reply":"2022-01-12T13:19:55.217096Z","shell.execute_reply.started":"2022-01-12T12:38:25.577033Z"},"papermill":{"duration":0.074266,"end_time":"2022-01-12T13:19:55.217734","exception":false,"start_time":"2022-01-12T13:19:55.143468","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"btc = btc.reindex(range(btc.index[0],btc.index[-1]+60,60),method='pad')\n(btc.index[1:]-btc.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:55.314851Z","iopub.status.busy":"2022-01-12T13:19:55.314203Z","iopub.status.idle":"2022-01-12T13:19:55.731190Z","shell.execute_reply":"2022-01-12T13:19:55.730590Z","shell.execute_reply.started":"2022-01-12T12:38:25.605062Z"},"papermill":{"duration":0.468038,"end_time":"2022-01-12T13:19:55.731327","exception":false,"start_time":"2022-01-12T13:19:55.263289","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(btcsh.index[1:]-btcsh.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:55.851910Z","iopub.status.busy":"2022-01-12T13:19:55.848849Z","iopub.status.idle":"2022-01-12T13:19:55.880272Z","shell.execute_reply":"2022-01-12T13:19:55.880738Z","shell.execute_reply.started":"2022-01-12T12:38:26.086434Z"},"papermill":{"duration":0.093831,"end_time":"2022-01-12T13:19:55.880911","exception":false,"start_time":"2022-01-12T13:19:55.787080","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"btcsh = btcsh.reindex(range(btcsh.index[0],btcsh.index[-1]+60,60),method='pad')\n(btcsh.index[1:]-btcsh.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:55.979293Z","iopub.status.busy":"2022-01-12T13:19:55.978714Z","iopub.status.idle":"2022-01-12T13:19:56.349315Z","shell.execute_reply":"2022-01-12T13:19:56.348801Z","shell.execute_reply.started":"2022-01-12T12:38:26.117169Z"},"papermill":{"duration":0.4215,"end_time":"2022-01-12T13:19:56.349479","exception":false,"start_time":"2022-01-12T13:19:55.927979","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(bnc.index[1:]-bnc.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:56.450720Z","iopub.status.busy":"2022-01-12T13:19:56.449311Z","iopub.status.idle":"2022-01-12T13:19:56.469123Z","shell.execute_reply":"2022-01-12T13:19:56.469647Z","shell.execute_reply.started":"2022-01-12T12:38:26.526403Z"},"papermill":{"duration":0.073989,"end_time":"2022-01-12T13:19:56.469809","exception":false,"start_time":"2022-01-12T13:19:56.395820","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bnc = bnc.reindex(range(bnc.index[0],bnc.index[-1]+60,60),method='pad')\n(bnc.index[1:]-bnc.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:56.569555Z","iopub.status.busy":"2022-01-12T13:19:56.566427Z","iopub.status.idle":"2022-01-12T13:19:56.908595Z","shell.execute_reply":"2022-01-12T13:19:56.909096Z","shell.execute_reply.started":"2022-01-12T12:38:26.552635Z"},"papermill":{"duration":0.392659,"end_time":"2022-01-12T13:19:56.909266","exception":false,"start_time":"2022-01-12T13:19:56.516607","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(eos.index[1:]-eos.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:57.011329Z","iopub.status.busy":"2022-01-12T13:19:57.010704Z","iopub.status.idle":"2022-01-12T13:19:57.033085Z","shell.execute_reply":"2022-01-12T13:19:57.033646Z","shell.execute_reply.started":"2022-01-12T12:38:27.075525Z"},"papermill":{"duration":0.074998,"end_time":"2022-01-12T13:19:57.033816","exception":false,"start_time":"2022-01-12T13:19:56.958818","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eos = eos.reindex(range(eos.index[0],eos.index[-1]+60,60),method='pad')\n(eos.index[1:]-eos.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:57.135642Z","iopub.status.busy":"2022-01-12T13:19:57.133070Z","iopub.status.idle":"2022-01-12T13:19:57.459005Z","shell.execute_reply":"2022-01-12T13:19:57.458509Z","shell.execute_reply.started":"2022-01-12T12:38:27.108298Z"},"papermill":{"duration":0.375615,"end_time":"2022-01-12T13:19:57.459148","exception":false,"start_time":"2022-01-12T13:19:57.083533","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(eth_csc.index[1:]-eth_csc.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:57.558819Z","iopub.status.busy":"2022-01-12T13:19:57.557814Z","iopub.status.idle":"2022-01-12T13:19:57.580507Z","shell.execute_reply":"2022-01-12T13:19:57.580975Z","shell.execute_reply.started":"2022-01-12T12:38:27.474522Z"},"papermill":{"duration":0.074752,"end_time":"2022-01-12T13:19:57.581183","exception":false,"start_time":"2022-01-12T13:19:57.506431","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eth_csc = eth_csc.reindex(range(eth_csc.index[0],eth_csc.index[-1]+60,60),method='pad')\n(eth_csc.index[1:]-eth_csc.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:57.679900Z","iopub.status.busy":"2022-01-12T13:19:57.679141Z","iopub.status.idle":"2022-01-12T13:19:57.997058Z","shell.execute_reply":"2022-01-12T13:19:57.996404Z","shell.execute_reply.started":"2022-01-12T12:38:27.500132Z"},"papermill":{"duration":0.367842,"end_time":"2022-01-12T13:19:57.997198","exception":false,"start_time":"2022-01-12T13:19:57.629356","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(ltc.index[1:]-ltc.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:58.098659Z","iopub.status.busy":"2022-01-12T13:19:58.098037Z","iopub.status.idle":"2022-01-12T13:19:58.120438Z","shell.execute_reply":"2022-01-12T13:19:58.120982Z","shell.execute_reply.started":"2022-01-12T12:38:27.823641Z"},"papermill":{"duration":0.075202,"end_time":"2022-01-12T13:19:58.121165","exception":false,"start_time":"2022-01-12T13:19:58.045963","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ltc = ltc.reindex(range(ltc.index[0],ltc.index[-1]+60,60),method='pad')\n(ltc.index[1:]-ltc.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:58.222469Z","iopub.status.busy":"2022-01-12T13:19:58.221776Z","iopub.status.idle":"2022-01-12T13:19:58.540576Z","shell.execute_reply":"2022-01-12T13:19:58.539919Z","shell.execute_reply.started":"2022-01-12T12:38:27.853196Z"},"papermill":{"duration":0.370116,"end_time":"2022-01-12T13:19:58.540711","exception":false,"start_time":"2022-01-12T13:19:58.170595","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(mon.index[1:]-mon.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:58.645026Z","iopub.status.busy":"2022-01-12T13:19:58.644277Z","iopub.status.idle":"2022-01-12T13:19:58.663245Z","shell.execute_reply":"2022-01-12T13:19:58.663777Z","shell.execute_reply.started":"2022-01-12T12:38:28.183206Z"},"papermill":{"duration":0.072441,"end_time":"2022-01-12T13:19:58.663941","exception":false,"start_time":"2022-01-12T13:19:58.591500","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mon = mon.reindex(range(mon.index[0],mon.index[-1]+60,60),method='pad')\n(mon.index[1:]-mon.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:58.768606Z","iopub.status.busy":"2022-01-12T13:19:58.767667Z","iopub.status.idle":"2022-01-12T13:19:59.063616Z","shell.execute_reply":"2022-01-12T13:19:59.062942Z","shell.execute_reply.started":"2022-01-12T12:38:28.207593Z"},"papermill":{"duration":0.350549,"end_time":"2022-01-12T13:19:59.063758","exception":false,"start_time":"2022-01-12T13:19:58.713209","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(tro.index[1:]-tro.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:59.169139Z","iopub.status.busy":"2022-01-12T13:19:59.168500Z","iopub.status.idle":"2022-01-12T13:19:59.189540Z","shell.execute_reply":"2022-01-12T13:19:59.190035Z","shell.execute_reply.started":"2022-01-12T12:38:28.521418Z"},"papermill":{"duration":0.075988,"end_time":"2022-01-12T13:19:59.190205","exception":false,"start_time":"2022-01-12T13:19:59.114217","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tro = tro.reindex(range(tro.index[0],tro.index[-1]+60,60),method='pad')\n(tro.index[1:]-tro.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:59.294248Z","iopub.status.busy":"2022-01-12T13:19:59.293427Z","iopub.status.idle":"2022-01-12T13:19:59.595356Z","shell.execute_reply":"2022-01-12T13:19:59.594801Z","shell.execute_reply.started":"2022-01-12T12:38:28.547848Z"},"papermill":{"duration":0.356378,"end_time":"2022-01-12T13:19:59.595508","exception":false,"start_time":"2022-01-12T13:19:59.239130","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(ste.index[1:]-ste.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:59.696482Z","iopub.status.busy":"2022-01-12T13:19:59.695907Z","iopub.status.idle":"2022-01-12T13:19:59.717983Z","shell.execute_reply":"2022-01-12T13:19:59.717425Z","shell.execute_reply.started":"2022-01-12T12:38:28.872287Z"},"papermill":{"duration":0.07354,"end_time":"2022-01-12T13:19:59.718137","exception":false,"start_time":"2022-01-12T13:19:59.644597","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ste = ste.reindex(range(ste.index[0],ste.index[-1]+60,60),method='pad')\n(ste.index[1:]-ste.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:19:59.824724Z","iopub.status.busy":"2022-01-12T13:19:59.824051Z","iopub.status.idle":"2022-01-12T13:20:00.121281Z","shell.execute_reply":"2022-01-12T13:20:00.120776Z","shell.execute_reply.started":"2022-01-12T12:38:28.903187Z"},"papermill":{"duration":0.352769,"end_time":"2022-01-12T13:20:00.121433","exception":false,"start_time":"2022-01-12T13:19:59.768664","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(car.index[1:]-car.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:00.226627Z","iopub.status.busy":"2022-01-12T13:20:00.226006Z","iopub.status.idle":"2022-01-12T13:20:00.246913Z","shell.execute_reply":"2022-01-12T13:20:00.247490Z","shell.execute_reply.started":"2022-01-12T12:38:29.246199Z"},"papermill":{"duration":0.076636,"end_time":"2022-01-12T13:20:00.247662","exception":false,"start_time":"2022-01-12T13:20:00.171026","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"car = car.reindex(range(car.index[0],car.index[-1]+60,60),method='pad')\n(car.index[1:]-car.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:00.351253Z","iopub.status.busy":"2022-01-12T13:20:00.350646Z","iopub.status.idle":"2022-01-12T13:20:00.652233Z","shell.execute_reply":"2022-01-12T13:20:00.651711Z","shell.execute_reply.started":"2022-01-12T12:38:29.273607Z"},"papermill":{"duration":0.354286,"end_time":"2022-01-12T13:20:00.652369","exception":false,"start_time":"2022-01-12T13:20:00.298083","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(iot.index[1:]-iot.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:00.760954Z","iopub.status.busy":"2022-01-12T13:20:00.759757Z","iopub.status.idle":"2022-01-12T13:20:00.777592Z","shell.execute_reply":"2022-01-12T13:20:00.776995Z","shell.execute_reply.started":"2022-01-12T12:38:29.595930Z"},"papermill":{"duration":0.074517,"end_time":"2022-01-12T13:20:00.777729","exception":false,"start_time":"2022-01-12T13:20:00.703212","status":"completed"},"scrolled":true,"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"iot = iot.reindex(range(iot.index[0],iot.index[-1]+60,60),method='pad')\n(iot.index[1:]-iot.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:00.886313Z","iopub.status.busy":"2022-01-12T13:20:00.885456Z","iopub.status.idle":"2022-01-12T13:20:01.082977Z","shell.execute_reply":"2022-01-12T13:20:01.083426Z","shell.execute_reply.started":"2022-01-12T12:38:29.620509Z"},"papermill":{"duration":0.25513,"end_time":"2022-01-12T13:20:01.083605","exception":false,"start_time":"2022-01-12T13:20:00.828475","status":"completed"},"scrolled":true,"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(mak.index[1:]-mak.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:01.189872Z","iopub.status.busy":"2022-01-12T13:20:01.189140Z","iopub.status.idle":"2022-01-12T13:20:01.201065Z","shell.execute_reply":"2022-01-12T13:20:01.201525Z","shell.execute_reply.started":"2022-01-12T12:38:29.834645Z"},"papermill":{"duration":0.067433,"end_time":"2022-01-12T13:20:01.201701","exception":false,"start_time":"2022-01-12T13:20:01.134268","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mak = mak.reindex(range(mak.index[0],mak.index[-1]+60,60),method='pad')\n(mak.index[1:]-mak.index[:-1]).value_counts().head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:01.310698Z","iopub.status.busy":"2022-01-12T13:20:01.310081Z","iopub.status.idle":"2022-01-12T13:20:01.441572Z","shell.execute_reply":"2022-01-12T13:20:01.442082Z","shell.execute_reply.started":"2022-01-12T12:38:29.852579Z"},"papermill":{"duration":0.189023,"end_time":"2022-01-12T13:20:01.442246","exception":false,"start_time":"2022-01-12T13:20:01.253223","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define plot space\nfig, ax = plt.subplots(5, 3, figsize=(18, 22))\n\n# Bitcoin Cash\nax[0, 0].plot(btcsh['Close'], label='BTCSH')\nax[0, 0].set_title('Bitcoin Cash')\nax[0, 1].plot(bnc['Close'], label='BNC')\nax[0, 1].set_title('Binance Coin')\nax[0, 2].plot(btc['Close'], label='BTC')\nax[0, 2].set_title('Bitcoin')\nax[1, 0].plot(eos['Close'], label='EOS')\nax[1, 0].set_title('EOS.IO')\nax[1, 1].plot(eth_csc['Close'], label='ETH_CSC')\nax[1, 1].set_title('Etherium Cash')\nax[1, 2].plot(ltc['Close'], label='LTC')\nax[1, 2].set_title('Lite Coin')\nax[2, 0].plot(mon['Close'], label='MON')\nax[2, 0].set_title('Monero')\nax[2, 1].plot(tro['Close'], label='TRO')\nax[2, 1].set_title('TRON')\nax[2, 2].plot(eth['Close'], label='ETH')\nax[2, 2].set_title('Etherium')\nax[3, 0].plot(ste['Close'], label='STE')\nax[3, 0].set_title('Stelar')\nax[3, 1].plot(car['Close'], label='CAR')\nax[3, 1].set_title('Cardano')\nax[3, 2].plot(iot['Close'], label='IOT')\nax[3, 2].set_title('IOTA')\nax[4, 0].plot(mak['Close'], label='MAK')\nax[4, 0].set_title('Maker')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:01.565867Z","iopub.status.busy":"2022-01-12T13:20:01.551664Z","iopub.status.idle":"2022-01-12T13:20:05.969286Z","shell.execute_reply":"2022-01-12T13:20:05.969785Z","shell.execute_reply.started":"2022-01-12T12:38:30.002320Z"},"papermill":{"duration":4.475517,"end_time":"2022-01-12T13:20:05.969948","exception":false,"start_time":"2022-01-12T13:20:01.494431","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# define function to compute log returns\ndef log_return(series, periods=1):\n    return np.log(series).diff(periods=periods)","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:06.087580Z","iopub.status.busy":"2022-01-12T13:20:06.086638Z","iopub.status.idle":"2022-01-12T13:20:06.091655Z","shell.execute_reply":"2022-01-12T13:20:06.091048Z","shell.execute_reply.started":"2022-01-12T12:38:35.581628Z"},"papermill":{"duration":0.064596,"end_time":"2022-01-12T13:20:06.091799","exception":false,"start_time":"2022-01-12T13:20:06.027203","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# auxiliary function, from datetime to timestamp\ntotimestamp = lambda s: np.int32(time.mktime(datetime.strptime(s, \"%d/%m/%Y\").timetuple()))\n\nall_assets_2021 = pd.DataFrame([])\nfor asset_id, asset_name in zip(ds_asset.Asset_ID, ds_asset.Asset_Name):\n    asset = ds_train[ds_train[\"Asset_ID\"]==asset_id].set_index(\"timestamp\")\n    asset = asset.loc[totimestamp('01/01/2021'):totimestamp('01/05/2021')]\n    asset = asset.reindex(range(asset.index[0],asset.index[-1]+60,60),method='pad')\n    lret = log_return(asset.Close.fillna(0))[1:]\n    all_assets_2021 = all_assets_2021.join(lret, rsuffix=asset_name, how=\"outer\")","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:06.207678Z","iopub.status.busy":"2022-01-12T13:20:06.207008Z","iopub.status.idle":"2022-01-12T13:20:11.065794Z","shell.execute_reply":"2022-01-12T13:20:11.065116Z","shell.execute_reply.started":"2022-01-12T12:38:35.588967Z"},"papermill":{"duration":4.917884,"end_time":"2022-01-12T13:20:11.065929","exception":false,"start_time":"2022-01-12T13:20:06.148045","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(all_assets_2021.corr());\nplt.yticks(ds_asset.Asset_ID.values, ds_asset.Asset_Name.values);\nplt.xticks(ds_asset.Asset_ID.values, ds_asset.Asset_Name.values, rotation='vertical');\nplt.colorbar();","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:11.186671Z","iopub.status.busy":"2022-01-12T13:20:11.185998Z","iopub.status.idle":"2022-01-12T13:20:11.641194Z","shell.execute_reply":"2022-01-12T13:20:11.640561Z","shell.execute_reply.started":"2022-01-12T12:38:40.757313Z"},"papermill":{"duration":0.516472,"end_time":"2022-01-12T13:20:11.641332","exception":false,"start_time":"2022-01-12T13:20:11.124860","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_asset.head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:11.765576Z","iopub.status.busy":"2022-01-12T13:20:11.764942Z","iopub.status.idle":"2022-01-12T13:20:11.768807Z","shell.execute_reply":"2022-01-12T13:20:11.768291Z","shell.execute_reply.started":"2022-01-12T12:38:41.262303Z"},"papermill":{"duration":0.069311,"end_time":"2022-01-12T13:20:11.768942","exception":false,"start_time":"2022-01-12T13:20:11.699631","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"frames = [btcsh, bnc, btc, eos, eth_csc, eth, ltc, mon, tro, ste, car, iot, mak, dog]\nfinal_dataset = pd.concat(frames)\nfinal_dataset_sorted = final_dataset.sort_index()\nfinal_dataset_sorted.head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:11.891475Z","iopub.status.busy":"2022-01-12T13:20:11.888206Z","iopub.status.idle":"2022-01-12T13:20:17.582152Z","shell.execute_reply":"2022-01-12T13:20:17.581648Z","shell.execute_reply.started":"2022-01-12T12:38:41.276866Z"},"papermill":{"duration":5.755145,"end_time":"2022-01-12T13:20:17.582301","exception":false,"start_time":"2022-01-12T13:20:11.827156","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_dataset_sorted[final_dataset_sorted['Asset_ID']==6].head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:17.716876Z","iopub.status.busy":"2022-01-12T13:20:17.703969Z","iopub.status.idle":"2022-01-12T13:20:18.051879Z","shell.execute_reply":"2022-01-12T13:20:18.051189Z","shell.execute_reply.started":"2022-01-12T12:38:46.502780Z"},"papermill":{"duration":0.411526,"end_time":"2022-01-12T13:20:18.052018","exception":false,"start_time":"2022-01-12T13:20:17.640492","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_dataset_sorted.join(ds_asset['Weight'], on='Asset_ID')","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:18.176317Z","iopub.status.busy":"2022-01-12T13:20:18.175345Z","iopub.status.idle":"2022-01-12T13:20:23.200603Z","shell.execute_reply":"2022-01-12T13:20:23.199698Z","shell.execute_reply.started":"2022-01-12T12:38:46.831270Z"},"papermill":{"duration":5.090027,"end_time":"2022-01-12T13:20:23.200758","exception":false,"start_time":"2022-01-12T13:20:18.110731","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_dataset_2021 = final_dataset_sorted[final_dataset_sorted['date']>'2021-01-01 00:00:00']\nfinal_dataset_2021.head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:23.331549Z","iopub.status.busy":"2022-01-12T13:20:23.330871Z","iopub.status.idle":"2022-01-12T13:20:24.191768Z","shell.execute_reply":"2022-01-12T13:20:24.192192Z","shell.execute_reply.started":"2022-01-12T12:38:51.117672Z"},"papermill":{"duration":0.928043,"end_time":"2022-01-12T13:20:24.192369","exception":false,"start_time":"2022-01-12T13:20:23.264326","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_dataset_2021.isna().sum()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:24.317135Z","iopub.status.busy":"2022-01-12T13:20:24.316471Z","iopub.status.idle":"2022-01-12T13:20:24.437253Z","shell.execute_reply":"2022-01-12T13:20:24.436765Z","shell.execute_reply.started":"2022-01-12T12:38:51.818282Z"},"papermill":{"duration":0.185281,"end_time":"2022-01-12T13:20:24.437414","exception":false,"start_time":"2022-01-12T13:20:24.252133","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_dataset_2021['Target'] = final_dataset_2021['Target'].ffill()\nfinal_dataset_2021['Target'] = final_dataset_2021['Target'].bfill()\nfinal_dataset_2021.isna().sum()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:24.563725Z","iopub.status.busy":"2022-01-12T13:20:24.563008Z","iopub.status.idle":"2022-01-12T13:20:24.880792Z","shell.execute_reply":"2022-01-12T13:20:24.880160Z","shell.execute_reply.started":"2022-01-12T12:38:51.941297Z"},"papermill":{"duration":0.382155,"end_time":"2022-01-12T13:20:24.880930","exception":false,"start_time":"2022-01-12T13:20:24.498775","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Bitcoin Cash\nds_btcsh = final_dataset_2021[final_dataset_2021['Asset_ID']==2]\nds_btcsh = ds_btcsh[ds_btcsh['date']>='2021-07-01 00:01:00']\nds_btcsh = ds_btcsh[ds_btcsh['date']<='2021-08-30 23:59:59']\n# Binance Coin\nds_bnc = final_dataset_2021[final_dataset_2021['Asset_ID']==0]\nds_bnc = ds_bnc[ds_bnc['date']>='2021-07-01 00:01:00']\nds_bnc = ds_bnc[ds_bnc['date']<='2021-08-30 23:59:59']\n# Bitcoin\nds_btc = final_dataset_2021[final_dataset_2021['Asset_ID']==1]\nds_btc = ds_btc[ds_btc['date']>='2021-07-01 00:01:00']\nds_btc = ds_btc[ds_btc['date']<='2021-08-30 23:59:59']\n# EOS\nds_eos = final_dataset_2021[final_dataset_2021['Asset_ID']==5]\nds_eos = ds_eos[ds_eos['date']>='2021-07-01 00:01:00']\nds_eos = ds_eos[ds_eos['date']<='2021-08-30 23:59:59']\n# Etherium Classic\nds_eth_csc = final_dataset_2021[final_dataset_2021['Asset_ID']==7]\nds_eth_csc = ds_eth_csc[ds_eth_csc['date']>='2021-07-01 00:01:00']\nds_eth_csc = ds_eth_csc[ds_eth_csc['date']<='2021-08-30 23:59:59']\n# Litecoin\nds_ltc = final_dataset_2021[final_dataset_2021['Asset_ID']==9]\nds_ltc = ds_ltc[ds_ltc['date']>='2021-07-01 00:01:00']\nds_ltc = ds_ltc[ds_ltc['date']<='2021-08-30 23:59:59']\n# Monero\nds_mon = final_dataset_2021[final_dataset_2021['Asset_ID']==11]\nds_mon = ds_mon[ds_mon['date']>='2021-07-01 00:01:00']\nds_mon = ds_mon[ds_mon['date']<='2021-08-30 23:59:59']\n# TRON\nds_tro = final_dataset_2021[final_dataset_2021['Asset_ID']==13]\nds_tro = ds_tro[ds_tro['date']>='2021-07-01 00:01:00']\nds_tro = ds_tro[ds_tro['date']<='2021-08-30 23:59:59']\n# Stellar\nds_ste = final_dataset_2021[final_dataset_2021['Asset_ID']==12]\nds_ste = ds_ste[ds_ste['date']>='2021-07-01 00:01:00']\nds_ste = ds_ste[ds_ste['date']<='2021-08-30 23:59:59']\n# Cardano\nds_car = final_dataset_2021[final_dataset_2021['Asset_ID']==3]\nds_car = ds_car[ds_car['date']>='2021-07-01 00:01:00']\nds_car = ds_car[ds_car['date']<='2021-08-30 23:59:59']\n# IOTA\nds_iot = final_dataset_2021[final_dataset_2021['Asset_ID']==8]\nds_iot = ds_iot[ds_iot['date']>='2021-07-01 00:01:00']\nds_iot = ds_iot[ds_iot['date']<='2021-08-30 23:59:59']\n# Maker \nds_mak = final_dataset_2021[final_dataset_2021['Asset_ID']==10]\nds_mak = ds_mak[ds_mak['date']>='2021-07-01 00:01:00']\nds_mak = ds_mak[ds_mak['date']<='2021-08-30 23:59:59']\n# Dogecoin \nds_dog = final_dataset_2021[final_dataset_2021['Asset_ID']==4]\nds_dog = ds_dog[ds_dog['date']>='2021-07-01 00:01:00']\nds_dog = ds_dog[ds_dog['date']<='2021-08-30 23:59:59']\nds_dog.head()\n# Etherium\nds_eth = final_dataset_2021[final_dataset_2021['Asset_ID']==6]\nds_eth = ds_eth[ds_eth['date']>='2021-07-01 00:01:00']\nds_eth = ds_eth[ds_eth['date']<='2021-08-30 23:59:59']\nds_eth.head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:25.019856Z","iopub.status.busy":"2022-01-12T13:20:25.006069Z","iopub.status.idle":"2022-01-12T13:20:26.035208Z","shell.execute_reply":"2022-01-12T13:20:26.034610Z","shell.execute_reply.started":"2022-01-12T12:38:52.335219Z"},"papermill":{"duration":1.092462,"end_time":"2022-01-12T13:20:26.035344","exception":false,"start_time":"2022-01-12T13:20:24.942882","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list_asset = [['Bitcoin Cash',ds_btcsh], \n              ['Binance Coin',ds_bnc], \n              ['Bitcoin',ds_btc], \n              ['EOS.IO',ds_eos], \n              ['Etherium Classic',ds_eth_csc], \n              ['Lite Coin',ds_ltc], \n              ['Monero',ds_mon], \n              ['TRON',ds_tro], \n              ['Stellar',ds_ste], \n              ['Cardano',ds_car], \n              ['IOT',ds_iot], \n              ['Maker',ds_mak], \n              ['Dogecoin',ds_dog],\n              ['Etherium',ds_eth]]","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:26.161493Z","iopub.status.busy":"2022-01-12T13:20:26.160876Z","iopub.status.idle":"2022-01-12T13:20:26.165992Z","shell.execute_reply":"2022-01-12T13:20:26.166475Z","shell.execute_reply.started":"2022-01-12T12:38:53.397002Z"},"papermill":{"duration":0.070005,"end_time":"2022-01-12T13:20:26.166653","exception":false,"start_time":"2022-01-12T13:20:26.096648","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list_asset[13][1].head()","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:26.294242Z","iopub.status.busy":"2022-01-12T13:20:26.293621Z","iopub.status.idle":"2022-01-12T13:20:26.309463Z","shell.execute_reply":"2022-01-12T13:20:26.309986Z","shell.execute_reply.started":"2022-01-12T12:38:53.408649Z"},"papermill":{"duration":0.080835,"end_time":"2022-01-12T13:20:26.310161","exception":false,"start_time":"2022-01-12T13:20:26.229326","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler, MinMaxScaler\ndef x_normalization(dataset):\n    data = dataset[['Target']].values\n    sc   = MinMaxScaler()\n    data_sc = sc.fit(data)\n    x = data_sc.transform(data)\n    return data","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:26.440471Z","iopub.status.busy":"2022-01-12T13:20:26.439838Z","iopub.status.idle":"2022-01-12T13:20:26.443911Z","shell.execute_reply":"2022-01-12T13:20:26.444346Z","shell.execute_reply.started":"2022-01-12T12:38:53.437729Z"},"papermill":{"duration":0.069493,"end_time":"2022-01-12T13:20:26.444523","exception":false,"start_time":"2022-01-12T13:20:26.375030","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def split_dataset(dataset):\n    X_samples = list()\n    y_samples = list()\n    NumberOfRows = len(dataset)\n    TimeSteps    = 15  \n   \n    for i in range(TimeSteps , NumberOfRows , 1):\n        x_sample = dataset[i-TimeSteps:i]\n        y_sample = dataset[i]\n        X_samples.append(x_sample)\n        y_samples.append(y_sample)\n\n    X_data=np.array(X_samples)\n    X_data=X_data.reshape(X_data.shape[0], X_data.shape[1], 1)\n    \n    y_data=np.array(y_samples)\n    y_data=y_data.reshape(y_data.shape[0], 1)\n    \n    TestingRecords=500\n\n    X_train=X_data[:-TestingRecords]\n    X_test=X_data[-TestingRecords:]\n    y_train=y_data[:-TestingRecords]\n    y_test=y_data[-TestingRecords:]\n    \n    return X_train, y_train, X_test, y_test","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:26.569026Z","iopub.status.busy":"2022-01-12T13:20:26.568274Z","iopub.status.idle":"2022-01-12T13:20:26.574839Z","shell.execute_reply":"2022-01-12T13:20:26.575284Z","shell.execute_reply.started":"2022-01-12T12:38:53.446095Z"},"papermill":{"duration":0.070608,"end_time":"2022-01-12T13:20:26.575495","exception":false,"start_time":"2022-01-12T13:20:26.504887","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_model_ltsm(x_train):\n    TimeSteps=x_train.shape[1]\n    TotalFeatures=x_train.shape[2]\n    model = Sequential()\n    model.add(LSTM(units = 15, activation = 'relu', input_shape = (TimeSteps, TotalFeatures), return_sequences=True))\n    model.add(LSTM(units = 10, activation = 'relu', input_shape = (TimeSteps, TotalFeatures), return_sequences=True))\n    model.add(LSTM(units = 5, activation = 'relu', return_sequences=False ))\n    model.add(Dropout(0.3))\n    model.add(Dense(units = 1))\n    model.compile(optimizer = 'adam', loss = 'mean_squared_error')\n    return model","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:26.702310Z","iopub.status.busy":"2022-01-12T13:20:26.701740Z","iopub.status.idle":"2022-01-12T13:20:26.707033Z","shell.execute_reply":"2022-01-12T13:20:26.707461Z","shell.execute_reply.started":"2022-01-12T12:38:53.462040Z"},"papermill":{"duration":0.069502,"end_time":"2022-01-12T13:20:26.707637","exception":false,"start_time":"2022-01-12T13:20:26.638135","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import time\nfor dataset in list_asset:\n    asset_name = dataset[0]\n    data       = x_normalization(dataset[1])\n    x_train, y_train, x_test, y_test = split_dataset(data)\n    model      = get_model_ltsm(x_train)\n    model.summary()\n    checkpoint = ModelCheckpoint(asset_name+'.h5', verbose=1, monitor='loss', save_best_only=True, mode='auto')\n    StartTime  = time.time()\n    print('Train for ' + asset_name)\n    model.fit(x_train, \n              y_train, \n              batch_size = 15, \n              epochs = 3, \n              callbacks = [checkpoint])\n    EndTime = time.time()\n    print(\"## Total \" + asset_name + \" Time Taken: \", round((EndTime-StartTime)/60), 'Minutes ##')","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:20:26.837072Z","iopub.status.busy":"2022-01-12T13:20:26.836513Z","iopub.status.idle":"2022-01-12T13:38:49.339143Z","shell.execute_reply":"2022-01-12T13:38:49.339895Z","shell.execute_reply.started":"2022-01-12T12:38:53.474545Z"},"papermill":{"duration":1102.570844,"end_time":"2022-01-12T13:38:49.340149","exception":false,"start_time":"2022-01-12T13:20:26.769305","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Making predictions on test data\nmodel.load_weights('./'+asset_name+'.h5')\npredicted_Price = model.predict(x_test)\n#predicted_Price = DataScaler.inverse_transform(predicted_Price)\nprint('#### Predicted Prices ####')\nprint(predicted_Price)\n \n# Getting the original price values for testing data\norig=y_test\n#orig=DataScaler.inverse_transform(y_test)\nprint('\\n#### Original Prices ####')\nprint(orig)","metadata":{"execution":{"iopub.execute_input":"2022-01-12T13:38:57.687665Z","iopub.status.busy":"2022-01-12T13:38:57.686993Z","iopub.status.idle":"2022-01-12T13:38:58.386759Z","shell.execute_reply":"2022-01-12T13:38:58.387495Z","shell.execute_reply.started":"2022-01-12T13:14:37.937088Z"},"papermill":{"duration":4.750215,"end_time":"2022-01-12T13:38:58.387757","exception":false,"start_time":"2022-01-12T13:38:53.637542","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import gresearch_crypto\nenv = gresearch_crypto.make_env()\niter_test = env.iter_test()\n\ntrainDF = pd.read_csv('/kaggle/input/g-research-crypto-forecasting/train.csv', \n                 usecols=['Target', 'Asset_ID','timestamp'], dtype={'Asset_ID': 'int8'})\ntrainDF['datetime'] = pd.to_datetime(trainDF['timestamp'], unit='s')\ntrainDF = trainDF.set_index('datetime').drop('timestamp', axis=1)\ntrainDF = trainDF[(trainDF.index.year == 2021) & (trainDF.index.month > 5)]\ndfs = {asset_id: trainDF[trainDF['Asset_ID'] == asset_id].resample('1min').interpolate().copy() for asset_id in trainDF['Asset_ID'].unique()}\ndel trainDF\nfor df_test, df_pred in iter_test:\n    df_test['datetime'] = pd.to_datetime(df_test['timestamp'], unit='s')\n    for _, row in df_test.iterrows():\n        try:\n            df = dfs[row['Asset_ID']]\n            predicted = df.predict(pd.DataFrame([x_test]))[0]\n            df_pred.loc[df_pred['row_id'] == row['row_id'], 'Target'] = predicted\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.execute_input":"2022-01-12T13:39:06.734256Z","iopub.status.busy":"2022-01-12T13:39:06.733626Z","iopub.status.idle":"2022-01-12T13:39:59.945262Z","shell.execute_reply":"2022-01-12T13:39:59.946108Z","shell.execute_reply.started":"2022-01-12T13:15:50.062460Z"},"papermill":{"duration":57.37114,"end_time":"2022-01-12T13:39:59.946375","exception":false,"start_time":"2022-01-12T13:39:02.575235","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":4.214584,"end_time":"2022-01-12T13:40:08.321634","exception":false,"start_time":"2022-01-12T13:40:04.107050","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]}]}