{"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":"import os\n\nimport pandas as pd\nimport polars as pl\n\ndf = pd.read_parquet('/kaggle/input/jane-street-real-time-market-data-forecasting/train.parquet/partition_id=0/part-0.parquet')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-11-01T02:36:04.228192Z","iopub.execute_input":"2024-11-01T02:36:04.228624Z","iopub.status.idle":"2024-11-01T02:36:08.283799Z","shell.execute_reply.started":"2024-11-01T02:36:04.228581Z","shell.execute_reply":"2024-11-01T02:36:08.282604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\n\n# Enable inline plotting\n%matplotlib inline\n\ndf['date_id'] = pd.to_datetime(df['date_id'])  # Convert date_id to datetime if not already\ndf['time_id'] = pd.to_timedelta(df['time_id'], unit='s')  # Convert time_id to timedelta assuming it's in seconds\n\n# Combine date_id and time_id into a single timestamp\ndf['timestamp'] = df['date_id'] + df['time_id']\n\n# Sort for accurate rolling calculations\ndf.sort_values(by=['timestamp'], inplace=True)  # Sort by the new timestamp\n\n# Filter for symbol_id 1\ndf_symbol_1 = df[df['symbol_id'] == 1]\n\n# Set the moving average window size for half a year (182 days)\nwindow_size = 182  # Approximate number of days in half a year\n\n# Iterate over each numeric column (excluding the first three)\nfor column in df.columns[3:]:  # Assuming the first three are date_id, time_id, symbol_id\n    # Calculate the moving average for symbol_id 1\n    moving_avg = df_symbol_1.groupby(['timestamp'])[column].rolling(window=window_size, min_periods=1).mean().reset_index(level=0, drop=False)\n\n    plt.figure(figsize=(10, 6))  # Set the size of the plot\n    plt.plot(moving_avg['timestamp'], moving_avg[column], label='Symbol 1', color='blue')\n\n    plt.title(f'Half-Year Moving Average of {column} for Symbol ID 1')\n    plt.xlabel('Timestamp')\n    plt.ylabel('Half-Year Moving Average')\n    plt.legend()\n    plt.grid(True)\n    plt.xticks(rotation=45)  # Rotate x-ticks for better visibility\n    plt.tight_layout()  # Adjust layout to prevent clipping of labels\n    plt.show()  # Display the plot inline\n\n","metadata":{"execution":{"iopub.status.busy":"2024-11-01T02:43:36.024168Z","iopub.execute_input":"2024-11-01T02:43:36.024618Z","iopub.status.idle":"2024-11-01T02:44:29.715322Z","shell.execute_reply.started":"2024-11-01T02:43:36.02457Z","shell.execute_reply":"2024-11-01T02:44:29.713508Z"},"trusted":true},"execution_count":null,"outputs":[]}]}