% Simple market making strategy pseudocode - Roberto Maria Caloi - 2022 % For educational purposes only. OnStart (): S.Gamma = 0.01; %Initialize risk aversion parameter S.margin = 1; %Initialize margin S.Q = 1; %Initialize size/amount of a single Quote S.q = S.getPortfolioPosition(); %Initialize portfolio position S.CF = 0; %Initialize portfolio Cash Flow OnPriceUpdate (newFairPrice): % Pricing model (!) if checkfilters() == false % Security checks failed (!) callStopStrategy(); % Stop trading end S.p = newFairPrice; %Update Current Fair Price: S.PL = S.CF + S.q *S.p; %Update Profit And Loss (P&L, mark to model) S.r_bid = S.p -S.Gamma *S.q - 0.5*Gamma * S.Q - S.margin; %Compute Quote bid price S.r_ask = S.p -S.Gamma *S.q + 0.5*Gamma * S.Q + S.margin; %Compute Quote ask price S.quote(S.Q,S.r_bid); %Send new Bid Quote, replace the previous one if already sent S.quote(S.Q,S.r_ask); %Send new Ask Quote, replace the previous one if already sent OnTradeBuy (): %Assume All or Nothing at original price S.CF = S.CF - S.r_bid * S.Q; S.q = S.q + S.Q; callOnPriceUpdate(S.p); OnTradeSell (): %Assume All or Nothing at original price S.CF = S.CF + S.r_ask * S.Q; S.q = S.q - S.Q; callOnPriceUpdate(S.p); OnStop (): ... Close position at market prices or simply stop and withdraw existing quotes...