Trading Sys Design
Trading Sys Design
Open in app
Search
Bhavin Follow
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 1/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
I started out with just backtesting using pandas data frame and calculating
percent change of returns based on the frequency I was testing and quickly
realized that this apporach will not work in reality. In the course of 1.5 years since
then I have learned a lot and evolved my trading systems, backtesting strategies and
my whole approach to systematic trading. With the help of this blog I would like to
share my experience and learning with someone starting out on the same journey.
We will start out with identifying components of a trading system. They varies based
on characteristics of strategies employed, execution speed, asset class traded etc. I
have listed components of my trading system based on the following characteristic:
Components:
Backtesting Engine:
This component has 2 subcomponents. one is the backtesting framework. You need
a backtesting framework which can keep track of every order that is generated for
your backtest. Track transaction costs. It helps to keep track of available funds as of
the backtesting date during a backtest run. Especially important if your strategy
considers shorting, because the stock might not be available to borrow in reality as
of the backtest date etc.
Framework:
which you can pick from one of the open source ones available. I have listed few
open source frameworks available in the appendix below. I have decided to use bt
because it lets you inject various modules in your backtest and this fits well with
tapping into various microservices as and when you need an output from one. It also
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 2/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
let you defined hierarchy of strategies so you can backtest variable allocation across
multiple strategies.
Pipeline:
Trading strategies:
Ideally you would backtest each strategy individually and then different
combinations of 1 or more strategies . You would also want to allocate % of fund to
each strategy or combinations to strategies and this could also vary from one time
frame to another.
you might also want to setup risk management rulebook based on allocation. for eg:
I will not allocate more than 20% of account size to one strategy and within the
strategy not more then 5% will be allocated to on name. You can also expand this to
run market neutral allocation, sector allocation limits , limits based on market cap
of names, geographic area of business etc.
Optimizer:
Optimizers help you determine weightage for each name in your future portfolio
based on risk management framework and performance requirement to meet your
portfolio goals.
Optimizers also acts as filters in a way that at the end of the optimization chain few
names with allocation below your threshold will drop off. ( you will of course
rebalance after they drop off ).
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 3/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
DataSets:
Datasets are the life blood of your trading system. Having accurate data is the most
important ingredient in your trading system setup. you can get price action and
fundamental data set for US equities fairly cheaply by spending $30-$70/month. You
will have to do your due diligence and make sure the data you have is accurate by
cross checking with your brokers charts. For fundamental dataset you can go to
EDGAR and cross check. If you are scraping data by your self, you want to put alerts
and statistical check on downloads every run.
If you are pulling in public datasets like TSA, google trends, wiki trends, Flight
status. you want to be mindful of restatements when integrating in your trading
systems.
Its very difficult to get an accurate dataset even for price action at a retail traders
budget. You want to double , tripple check your datasets from time to time basis
during your backtests.
You can choose to fully automate your trading by have an order executior that will
submit your trade orders directly to your broker. I choose to get an email of the
orders and then I play them manually. Implementing this component requires that
you have thoroughly tested the executor code. you will also need to build out order
monitoring etc if you decide to implement order executor.
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 4/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
In this section, I will go over my trading system setup, various components and
microservices
Strategies:
I maintain confluence workspace where I document various strategies and mark the
matured ones so I can run backtests against them and integrate in trading system. I
have a structure while documenting my strategies which includes 3 sections,
Strategy Overview, Strategy, Entry and Exits definition , I also like to keep some
housekeeping items like notebook link used to develop it , backtest performance
etc. ( QS-1a doesnt work any more ).
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 5/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
Microservices
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 6/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 7/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 8/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
This microservice expect that you pass in the order executed (trade blotter) and it
will calculate PnL up to the current time of the backtest and return PnL for each
name, its performance etc. Trivial as it may sound but this is process is complicated
where you have to keep pnl of a position that was flipped from short to long or vice
versa?
type : lagging
input: epoch
type : lagging
This microservice implements weighting skew towards either long side or short side
based on SPY performance (not yet implemented :2s vs 10s curve, M2 supply etc.)
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 9/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
Returns long and short weights. This helps the optimizer determine how much to
skew long or short positions.
type: lagging
This microservice takes in portfolio from backtest and epoch, it maps the names in
portfolio to sectors and then lookups sector indices. using the sector indices price
action as of the epoch. it constructs covariance metric and using this covariance
metric it will generate weights of each sector compared to others. This weights will
then be mapped back to portfolio names. Names and weights will be returned back.
This helps the pipeline optimizer apply sector skew if it exists a the time.
type: lagging
This microservice take in portfolio and epoch from the backtest. It tries to look up
fundamental dataset for each name in the portfolio and generates average
performance based on few relevant KPIs for past 4 quarters (q/q). ( for now I use eps
, but I later plan to add name specific KPIs like ASM for airline names, GMV for
retail names etc ). This is then normalized across portfolio and the weight are
returned back.
output: portfolio weights based on metrics derived from alternative data sets.
type: leading
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 10/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
This microservice takes in portfolio and epoch. it tries to lookup alternative dataset
and see if there is an existing mapping between the portfolio name and the dataset,
then it tries to compute performance of the metric that was derived from the alt
dataset. This performance is then normalized across names and returned back in
terms of weights.
type: leading
This microservice has lot of potential to use various ML techniques and try to weight
to capture forward returns. You could also use kpis from any of the datasets that we
have already used in weighting above as features to the algorithm.
Backtesting Pipeline
Pipeline starts with choosing a strategy to run the backtest for. Each stage of the
backtesting pipeline then tries to tap into one or more microservices and adjusts the
weights which in turn reflects the $ allocations in terms of number of shares to
purchase.
Then we apply a filter stage where we drop of names that falls below certain
threshold of weight value eg: (0.01). We limit max weight for any one name not to
exceed threshold ( eg: .05) and rebalance to normalize across.
Framework then spits out final order which either you can choose to pass on to
order executor or email / notify yourself , so you can take action.
you would execute this pipeline every day after market close.
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 11/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
you could run multiple pipelines for each strategy and receive multiple orders for
which you could choose to take action or not This way you can diversify across
multiple strategies.
Appendix:
Backtesting Frameworks:
1. bt | https://pmorissette.github.io/bt/
2. backtrader | https://www.backtrader.com/
3. zipline | https://zipline.ml4trading.io/#
Follow
Written by Bhavin
36 followers · 50 following
No responses yet
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 12/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
Moses Ongwenyi
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 13/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
Bhavin
COVID-19 by Numbers
I use to track COVID-19 dashboard from John Hopkins on a daily basis. which gave a fair view
into the situation. But what if you wanted a…
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 14/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 15/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
Quantum Anomaly
Decoding Redis
Redis (REmote DIctionary Server) is an open-source, in-memory, key-value data store, often
used as a cache, message broker, real-time…
Jun 13 3 1
In Javarevisited by Veenarao
Dear Readers, I am summarizing the commonly asked concepts in system design interviews.
These questions are asked in almost all the system…
Rob Hutton
Feb 8 10
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 17/18
6/23/25, 10:22 AM Trading System Design using MicroServices | by Bhavin | Medium
Kevinnjagi
Feb 17
https://medium.com/@datajedi/trading-system-design-using-microservices-256cda0dc60a 18/18