{"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\n\n# 14 assets, 60 minutes an hour, 24 hours, 14 days\ncount = 14*60*24*14\n\ntrain = pd.read_csv(\"../input/g-research-crypto-forecasting/supplemental_train.csv\", nrows=count)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-21T23:37:53.044136Z","iopub.execute_input":"2022-02-21T23:37:53.044998Z","iopub.status.idle":"2022-02-21T23:37:53.382246Z","shell.execute_reply.started":"2022-02-21T23:37:53.044962Z","shell.execute_reply":"2022-02-21T23:37:53.381426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"targets = train['Target'].to_numpy()\n\nprint(\"NaN values found:\", len(targets[np.isnan(targets)]))\n\ntargets = targets[~np.isnan(targets)] # Ignore the few NaN values\n\nmax_corr = -np.inf # Track the best correlation over time\n\n# Go through the data with step size 50\nfor i in range(0, len(targets)-500, 50):\n    if i % 1000 == 0:\n        print(i, \"/\", len(targets) - 500, end='\\r')\n    \n    preds = np.zeros(len(targets))\n    preds[i:i+500] = 1 # Set 500 consecutive values to 1, starting from i. The rest of the values stay 0.\n    \n    corr = np.corrcoef(targets, preds)[0, 1] # Calculate the correlation\n    \n    # Save new best result\n    if corr > max_corr:\n        max_corr = corr\n        print(\"New best after\", i, \"minutes: {:.6f}\".format(corr))\n        \nprint(\"Maximum correlation found: {:.6f}\".format(max_corr))","metadata":{"execution":{"iopub.status.busy":"2022-02-21T23:37:53.383764Z","iopub.execute_input":"2022-02-21T23:37:53.384023Z","iopub.status.idle":"2022-02-21T23:38:06.720362Z","shell.execute_reply.started":"2022-02-21T23:37:53.383990Z","shell.execute_reply":"2022-02-21T23:38:06.719549Z"},"trusted":true},"execution_count":null,"outputs":[]}]}