Project Structure
│
└─── Part 1 : BTCUSDT-26Sep25 (Bitcoin derivative contract against Tether, with expiry on 26th Sept 2025)
│ │
│ └─── Started with a Naive Market Making Strategy, as a benchmark.
│ └─── Compared it with our Inventory Aware Market Making Strategy.
│ └─── Implemented realistic slippage and execution.
│ └─── Tested our strategy on three consecutive days.
│
└─── Part 2 : (Further Improvements)
│ │
│ └─── Bayesian Hyperparameter Tuning using Optuna
│ └─── (future) Paper Trading using Alpaca APIThis part of the project aims to implement an intelligent market-making strategy, generating calculated quotes on order book data. It is structured as Python notebooks designed to simulate quoting, execution, and inventory management in a high-frequency trading environment. The simulator aims to help understand and evaluate simple market-making behaviors under realistic market conditions.
Contains the base version of the simulator. Quotes are placed deterministically at spread-adjusted prices, and fills are assumed to happen immediately when a price match occurs. Useful for understanding core logic: quoting, execution, inventory management, and mark-to-market PnL tracking.
-
- Quote Generation :
$$min\_price : \Delta = 0.1$$ - Price
$$bid\_quote = best\_bid + \Delta$$ $$ask\_quote = best\_ask - \Delta$$ - Volume
$$base\_volume : Q_0 = 0.001$$ $$bid\_vol = Q_0$$ $$ask\_vol = Q_0$$
- Quote Generation :
-
- Quote Generation :
$$min\_price : \Delta = 0.1$$ $$price\_factor : \alpha = 3.0$$ $$Inventory\_bias : \phi = \min(\frac{|I_{volume}|}{I_{margin}},\alpha)$$ $$I_{margin} = 10$$ - Price
$$bid\_quote = best\_bid + \Delta - \lfloor\phi\rfloor . \Delta$$ $$ask\_quote = best\_ask - \Delta - \lfloor\phi\rfloor . \Delta$$ - Volume
$$base\_volume : Q_0 = 0.001$$ $$vol\_factor : \beta = 0.25$$ $$bid\_vol = Q_0 (1 - \beta . \phi)$$ $$ask\_vol = Q_0 (1 + \beta . \phi)$$ - NOTE :
$$\alpha \cdot \beta \lt 1.0$$
- Quote Generation :
This strategy saves us from the risk due to holding a big position.
Extends the base simulator with two realism enhancements:
- Execution Probability: Not all limit orders are assumed to be filled. Each order has a probabilistic chance of execution, simulating queue position and competition.
- Gaussian Slippage: When trades are executed, the price is adjusted with a small random noise to reflect market slippage and non-instant execution.
As expected, this leads to more volatile PnL outcomes, and emphasizes the risk of non-execution and price impact.
-
We to build a personalised
Cold_Tuner. The name 'cold' because it takes some time (~5-15 minutes) to find the parameters, without using any initial guess. -
It uses Optuna's TPESampler (Tree-structured Parzen Estimator).
Details:
- It's a Bayesian optimization method based on probabilistic modeling.
- It builds two models: one for "good" hyperparameter values and one for "bad" ones, and then chooses values that are more likely to improve performance.
- Works well for non-convex, noisy, and high-dimensional search spaces. (default sampler in Optuna)
-
To improve the time taken, we use Optuna's Median Pruner.
Details:
- Since our
Realistic_Market_Makingis randomised. During the HpTuning, we might end up getting a set of Hps which performed well once (got lucky), but don't reflect a robust and promising strategy otherwise. - To prevent against this, we run
MAX_REPS = 7times and report the$\frac{mean(score)}{std(score)}$ to the tuner. - This would demand 7 times the compute. To reduce that factor, We prune the runs with a poor score starting from
PRUNE_AFTER=3.
- Since our
Hyperparameters we're interested in, and their typical ranges :
-
Price_factordiscrete vales in$[1,\infty)$ -
Vol_factorcontinuous values in$(0,1)$ -
inventory_capcontinuous values in$(0,\infty)$
Score :
(The Metric which optuna maximizes)
Potential Improvements :
-
The hidden variables of Market are bound to drift with time.
-
We can build a fast
Hot_Tunerto frequently adjust the parameters. (more like a re-tuner) -
One could use local search on the initial guess given by the previous iterations, with Optuna's GPS Sampler
-
Alpaca does not allow one to have a negative position in some instruments, including Bitcoin. This would not let us do Market Making as we want to.
-
Moreover, the contract of our choice (BTCUSDT-26Sep25) is not available on Alpaca. So we are chose some other instrument.
-
Moving to another instrument implies having to tune the hyperparameters again. Our
Hp_Tunersaves the manual effort. -
So let's chose Coca Cola (KO) because it's my favorite drink ;)

