Function to pre-process LOBSTER data. The data must be stored in the input_path directory as 'daily message LOB' and 'orderbook' files. The data are treated in the following way: - Orderbook's states with crossed quotes are removed. - Each state in the orderbook is time-stamped, wi
(
ticker: str,
input_path: str,
output_path: str,
logs_path: str,
horizons: list[int],
normalization_window: int,
time_index: str = "seconds",
features: str = "orderbooks",
scaling: bool = True,
)
| 9 | |
| 10 | |
| 11 | def process_data( |
| 12 | ticker: str, |
| 13 | input_path: str, |
| 14 | output_path: str, |
| 15 | logs_path: str, |
| 16 | horizons: list[int], |
| 17 | normalization_window: int, |
| 18 | time_index: str = "seconds", |
| 19 | features: str = "orderbooks", |
| 20 | scaling: bool = True, |
| 21 | ) -> None: |
| 22 | """ |
| 23 | Function to pre-process LOBSTER data. The data must be stored in the input_path directory as 'daily message LOB' and 'orderbook' files. |
| 24 | |
| 25 | The data are treated in the following way: |
| 26 | - Orderbook's states with crossed quotes are removed. |
| 27 | - Each state in the orderbook is time-stamped, with states occurring at the same time collapsed onto the last occurring state. |
| 28 | - The first and last 10 minutes of market activity (inside usual opening times) are dropped. |
| 29 | - Rolling z-score normalization is applied to the data, i.e. the mean and standard deviation of the previous 5 days is used to normalize current day's data. |
| 30 | Hence, the first 5 days are dropped. |
| 31 | - Smoothed returns at the requested horizons (in orderbook's changes) are returned: |
| 32 | - if smoothing = "horizon": l = (m+ - m)/m, where m+ denotes the mean of the next h mid-prices, m(.) is current mid-price. |
| 33 | - if smoothing = "uniform": l = (m+ - m)/m, where m+ denotes the mean of the k+1 mid-prices centered at m(. + h), m(.) is current mid-price. |
| 34 | |
| 35 | A log file is produced tracking: |
| 36 | - Orderbook's files with problems. |
| 37 | - Message orderbook's files with problems. |
| 38 | - Trading days with unusual opening - closing times. |
| 39 | - Trading days with crossed quotes. |
| 40 | |
| 41 | A statistics.csv file summarizes the following (daily) statistics: |
| 42 | - # Updates (000): the total number of changes in the orderbook file. |
| 43 | - # Trades (000): the total number of trades, computed by counting the number of message book events corresponding to the execution of (possibly hidden) |
| 44 | limit orders ('event_type' 4 or 5 in LOBSTER orderbook's message file). |
| 45 | - # Price Changes (000): the total number of price changes per day. |
| 46 | - # Price (USD): average price on the day, weighted average by time. |
| 47 | - # Spread (bps): average spread on the day, weighted average by time. |
| 48 | - # Volume (USD MM): total volume traded on the day, computed as the sum of the volumes of all the executed trades ('event_type' 4 or 5 in LOBSTER orderbook's message file). |
| 49 | The volume of a single trade is given by size*price. |
| 50 | - # Tick size: the fraction of time that the bid-ask spread is equal to one tick for each stock. |
| 51 | |
| 52 | Args: |
| 53 | ticker (str): The ticker to be considered. |
| 54 | input_path (str): The path where the order book and message book files are stored, order book files have shape (:, 4*levels): |
| 55 | ["ASKp1", "ASKs1", "BIDp1", "BIDs1", ..., "ASKp10", "ASKs10", "BIDp10", "BIDs10"]. |
| 56 | output_path (str): The path where we wish to save the processed datasets. |
| 57 | logs_path (str): The path where we wish to save the logs. |
| 58 | time_index (str): The time-index to use ("seconds" or "datetime"). |
| 59 | horizons (list): Forecasting horizons for labels. |
| 60 | normalization_window (int): Window for rolling z-score normalization. |
| 61 | features (str): Whether to return 'orderbooks' or 'orderflows'. |
| 62 | scaling (bool): Whether to apply rolling z-score normalization. |
| 63 | |
| 64 | Returns: |
| 65 | None. |
| 66 | """ |
| 67 | |
| 68 | csv_file_list = glob.glob( |
nothing calls this directly
no test coverage detected