The mid_price_prediction
package provides tools for analyzing and predicting mid prices in financial trading using order book data. It includes classes and methods for processing trading data, constructing order books, and predicting price movements.
To install the mid_price_prediction
package, run the following command:
bashCopy codepip install mid_price_prediction
The OrderBook
class in OrderBookClass.py
represents and manipulates an order book for trading data. It provides functionalities to update the order book based on transaction data, retrieve top price levels, and process trading data for a given day.
- Update the order book with new transaction data.
- Retrieve top k price levels from the order book.
- Process and output data for trading days.
pythonCopy codefrom mid_price_prediction.OrderBookClass import OrderBook # Create an instance of OrderBook order_book = OrderBook() # Example: Processing a day's trading data day_files = ['res_20190610.csv', 'res_20190611.csv', 'res_20190612.csv'] for day_file in day_files: order_book.create_output_for_dayfile(day_file, 5)
The PricePredictionModel
class in PredictionModel.py
is used for predicting future price movements based on historical order book data.
- Reads and transforms trading data.
- Normalizes features for model training.
- Performs feature engineering.
- Trains a logistic regression model for price prediction.
- Evaluates the model and plots the coefficients.
- Performs feature selection and quantile analysis.
pythonCopy codefrom mid_price_prediction.PredictionModel import PricePredictionModel # Initialize the model with data files data_files = ['day1.csv', 'day2.csv', 'day3.csv', 'day4.csv', 'day5.csv'] model = PricePredictionModel(data_files) # Prepare data and train the model model.prepare_data() model.train_model() # Evaluate the model model.evaluate_model() # Pass test data as needed model.plot_coefficients() # Perform feature selection model.perform_feature_selection(3) # Quantile analysis on timestamp differences quantile_list = [0.1, 0.2, 0.3, 0.4, 0.5] model.plot_timestamp_difference_distribution(quantile_list)
The mid_price_prediction
package requires the following libraries:
- numpy
- pandas
- scikit-learn
- matplotlib
- mlxtend