{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84493,"databundleVersionId":9871156,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfrom pathlib import Path\n\ndef sizeof_fmt(num, suffix=\"B\"):\n    for unit in (\"\", \"Ki\", \"Mi\", \"Gi\", \"Ti\", \"Pi\", \"Ei\", \"Zi\"):\n        if abs(num) < 1024.0:\n            return f\"{num:3.1f}{unit}{suffix}\"\n        num /= 1024.0\n    return f\"{num:.1f}Yi{suffix}\"\n\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n        print(sizeof_fmt(os.stat(Path(dirname) / filename).st_size))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-10-18T06:37:19.724135Z","iopub.execute_input":"2024-10-18T06:37:19.724582Z","iopub.status.idle":"2024-10-18T06:37:19.789340Z","shell.execute_reply.started":"2024-10-18T06:37:19.724539Z","shell.execute_reply":"2024-10-18T06:37:19.787909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\ntrain_df = pd.read_parquet('/kaggle/input/jane-street-real-time-market-data-forecasting/train.parquet/partition_id=0/part-0.parquet')\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-18T06:37:19.791779Z","iopub.execute_input":"2024-10-18T06:37:19.792212Z","iopub.status.idle":"2024-10-18T06:37:21.360514Z","shell.execute_reply.started":"2024-10-18T06:37:19.792168Z","shell.execute_reply":"2024-10-18T06:37:21.359140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# New Time Index\n\nMake up an index incorporating the date and time IDs","metadata":{}},{"cell_type":"code","source":"train_df['new_time_idx'] = train_df['date_id'].map(lambda x: x*1000)+train_df['time_id']\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2024-10-18T06:37:21.362349Z","iopub.execute_input":"2024-10-18T06:37:21.362832Z","iopub.status.idle":"2024-10-18T06:37:23.266057Z","shell.execute_reply.started":"2024-10-18T06:37:21.362777Z","shell.execute_reply":"2024-10-18T06:37:23.264745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot response for given symbol\n\nFor a given symbol, plot the responders","metadata":{}},{"cell_type":"code","source":"symbol_responses = train_df[['new_time_idx', 'symbol_id','responder_0','responder_1','responder_2','responder_3','responder_4','responder_5','responder_6','responder_7','responder_8']]\nsym_1 = symbol_responses[symbol_responses['symbol_id'] == 1]\nplot_data = sym_1[['new_time_idx','responder_0','responder_1','responder_2','responder_3','responder_4','responder_5','responder_6','responder_7','responder_8']]","metadata":{"execution":{"iopub.status.busy":"2024-10-18T06:37:23.268722Z","iopub.execute_input":"2024-10-18T06:37:23.269169Z","iopub.status.idle":"2024-10-18T06:37:23.328702Z","shell.execute_reply.started":"2024-10-18T06:37:23.269125Z","shell.execute_reply":"2024-10-18T06:37:23.327357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_data.set_index('new_time_idx').cumsum().plot.line()","metadata":{"execution":{"iopub.status.busy":"2024-10-18T06:37:23.330287Z","iopub.execute_input":"2024-10-18T06:37:23.330694Z","iopub.status.idle":"2024-10-18T06:37:30.686468Z","shell.execute_reply.started":"2024-10-18T06:37:23.330651Z","shell.execute_reply":"2024-10-18T06:37:30.684928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"symbol_responses","metadata":{"execution":{"iopub.status.busy":"2024-10-18T06:37:30.688194Z","iopub.execute_input":"2024-10-18T06:37:30.688614Z","iopub.status.idle":"2024-10-18T06:37:30.712685Z","shell.execute_reply.started":"2024-10-18T06:37:30.688571Z","shell.execute_reply":"2024-10-18T06:37:30.711363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot responder_6 for select symbols","metadata":{}},{"cell_type":"code","source":"pivot_data = symbol_responses[symbol_responses['symbol_id'] <= 10][['new_time_idx', 'symbol_id','responder_6']]\npivot_data","metadata":{"execution":{"iopub.status.busy":"2024-10-18T06:37:30.714335Z","iopub.execute_input":"2024-10-18T06:37:30.714827Z","iopub.status.idle":"2024-10-18T06:37:30.786311Z","shell.execute_reply.started":"2024-10-18T06:37:30.714777Z","shell.execute_reply":"2024-10-18T06:37:30.784934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.pivot_table(pivot_data, values='responder_6', index='new_time_idx', columns='symbol_id').cumsum().plot.line()","metadata":{"execution":{"iopub.status.busy":"2024-10-18T06:37:30.787819Z","iopub.execute_input":"2024-10-18T06:37:30.788338Z","iopub.status.idle":"2024-10-18T06:37:37.416739Z","shell.execute_reply.started":"2024-10-18T06:37:30.788285Z","shell.execute_reply":"2024-10-18T06:37:37.415258Z"},"trusted":true},"execution_count":null,"outputs":[]}]}