CITE THIS NOTEBOOK: Modeling Trading and Liquidity Holes by Zeqiong Huang. Wolfram Community JAN 13 2023.
Abstract: This project explores the trading behavior in a decentralized market and the formation of liquidity holes (the chain of trading among a group of agents that form a hole in a topological graph) . In the model, trading starts from disagreement among heterogenous agents who are endowed with assets and observe existing orders and create new ones. We plot the chain of transactions and trace the branching and merging of states. We show how liquidity holes form in such a setting and how it is linked to endowed wealth and the pool of trading agents.
Section 1 Introduction
Section 1 Introduction
Market provides liquidity and facilitates trading between agents. Modern financial markets often feature a market maker and trading is centralized. However, without such a market maker, what market trading pattern would naturally emerge? Would there be enough liquidity that all efficients trades do take place? This project explores the trading behavior in a decentralized market. We are interested in the formation of liquidity holes, i.e., the chain of trading among a group of agents that form a hole in a topological graph. To do so, we simulate a group of agents, each endowed with some assets and numeraire (money). In each round, an agents can observe one pair of buy or sell orders, and then submit his own buy/sell order. A trade can happen if there is a pair of matching orders. We plot the chain of transactions and trace the branching and merging of states. We show how liquidity holes form in such a setting and how it is linked to endowed wealth and the pool of trading agents.
Section 2 Model Setup
Section 2 Model Setup
Description
Description
There are agents (indexed with ), each endowed with units of the risky asset and units of numeraire (i.e., money). The distribution of is uniformly on and is uniformly on . There are also initial orders with prices uniformly distributed on .
Agents can observe one existing buy order and one sell order, and based on that, submit order if their wealth constraint allows. Each order buys or sells one unit of the asset. Specifically, to submit a buy order, the agent should have enough money to cover the order if it is executed; to submit a sell order, the agent should have at least one unit of the assets. Submitting an order also entails a transaction fee. A pair of orders is executed if the buy price is higher than the sell price.
nAgents
i
q
i
w
i
q
i
[0,maxInitAssets]
w
i
[0,maxInitMoney]
[0,1]
Agents can observe one existing buy order and one sell order, and based on that, submit order if their wealth constraint allows. Each order buys or sells one unit of the asset. Specifically, to submit a buy order, the agent should have enough money to cover the order if it is executed; to submit a sell order, the agent should have at least one unit of the assets. Submitting an order also entails a transaction fee. A pair of orders is executed if the buy price is higher than the sell price.
Code
Code
Our code started with simulating the initial conditions of agents' endowment and orders . Next the order submission, cancellation and execution rules are applied for \!\(TraditionalForm\`nSteps\) .
(*ModelParameters*)fee=0.1;nAgents=15;nInitOrders=50;maxInitAssets=25;maxInitMoney=3.0;nSteps=10;(*RulesforOrderSubmissionandExecution*)rules=(*OldOrderCancellation*){"Event",__}:>{},(*Orderexecution*){{"Buy",buyAgent_,buyPrice_},{"Sell",sellAgent_,sellPrice_},{buyAgent_Integer,buyQuantity_,buyMoney_},{sellAgent_Integer,sellQuantity_,sellMoney_}}/;buyPrice>=sellPrice:>Splice@buyAgent,buyQuantity+1,buyMoney-fee-,sellAgent,sellQuantity-1,sellMoney+-fee,{"Event",buyAgent,sellAgent},(*SellOrdercreation*){{agent_Integer,quantity_,money_},{"Buy",buyAgent_,buyPrice_},{"Sell",sellAgent_,sellPrice_}}/;quantity>0&&money>=fee&&buyPrice<sellPrice:>Splice@"Sell",agent,,{agent,quantity,money},{"Buy",buyAgent,buyPrice},{"Sell",sellAgent,sellPrice},(*BuyOrdercreation*){{agent_Integer,quantity_,money_},{"Buy",buyAgent_,buyPrice_},{"Sell",sellAgent_,sellPrice_}}/;money>=+fee&&buyPrice<sellPrice:>Splice@"Buy",agent,,{agent,quantity,money},{"Buy",buyAgent,buyPrice},{"Sell",sellAgent,sellPrice};initState=Join[{#,RandomInteger[maxInitAssets],RandomReal[maxInitMoney]}&/@Range[nAgents],Table[{RandomChoice[{"Buy","Sell"}],RandomInteger[nAgents],RandomReal[]},nInitOrders]];evolution=NestList[SubsetReplace[rules],initState,nSteps];events=Catenate[MapIndexed[{e,idx}|->Append[idx[[1]]]/@Cases[e,{"Event",__}],evolution]];causalGraph=TransitiveReductionGraph[If[#1[[3]]<#2[[3]]&&IntersectingQ[#1[[2;;3]],#2[[2;;3]]],#1#2,Nothing]&@@@Tuples[events,2],VertexStyleDirective[,EdgeForm[{,Opacity[1]}]],EdgeStyleDirective[Thickness[0.0001],Arrowheads[0.001],],VertexSize->0.5,GraphLayout->Automatic];
buyPrice+sellPrice
2
buyPrice+sellPrice
2
buyPrice+sellPrice
2
buyPrice+sellPrice
2
buyPrice+sellPrice
2
Section 3 Results
Section 3 Results
Subsection 3.1 State Transitive Graph
Subsection 3.1 State Transitive Graph
We first run the above simulation several times and obtain the following example state transitive reduction graphs:
Overall, we can see the formation of chains and liquidity holes - that some states are not directly linked together but connected by a chain of transactions, forming a hole in the transitive reduction graph. It also features a “hub and spoke” style, i.e., there are also peripheral nodes, which are connected only to some nodes in the main chain.
Subsection 3.2 Impacts of initial orders and agents’ wealth
Subsection 3.2 Impacts of initial orders and agents’ wealth
In this subsection we further study the impact of initial orders on liquidity hole formation. With more initial orders come more liquidity - that transactions are more likely to happen. This conjecture is consistent with the plots below in which we raise the initial order amount to 100.
Next, we conjecture that as agents’ initial wealth declines, the liquidity holes become larger - that is, for agent to trade with agent , the chain of transactions it has to go through lengthens.
Next, we conjecture that as agents’ initial wealth declines, the liquidity holes become larger - that is, for agent
i
j
◼
The plot below sets the maximum wealth to be 1:
In[]:=
fee=0.1;nAgents=15;nInitOrders=100;maxInitAssets=25;maxInitMoney=1.0;initState=Join[{#,RandomInteger[maxInitAssets],RandomReal[maxInitMoney]}&/@Range[nAgents],Table[{RandomChoice[{"Buy","Sell"}],RandomInteger[nAgents],RandomReal[]},nInitOrders]];nSteps=10;evolution=NestList[SubsetReplace[rules],initState,nSteps];events=Catenate[MapIndexed[{e,idx}|->Append[idx[[1]]]/@Cases[e,{"Event",__}],evolution]];causalGraph=TransitiveReductionGraph[If[#1[[3]]<#2[[3]]&&IntersectingQ[#1[[2;;3]],#2[[2;;3]]],#1#2,Nothing]&@@@Tuples[events,2],VertexStyleDirective[,EdgeForm[{,Opacity[1]}]],EdgeStyleDirective[Thickness[0.0001],Arrowheads[0.001],],VertexSize->0.5,GraphLayout->Automatic(*,GraphLayout->{"LayeredDigraphEmbedding","VertexLayerPosition"->events[[All,-1]]}*)]
Out[]=
◼
The plot below sets the maximum wealth to be 10:
Concluding Remarks
Concluding Remarks
To sum up, in this project we study the trading behavior in a decentralized market and the formation of liquidity holes. We plot the chain of transactions and trace evolution of states int he system. Our results show the formation of chains of transactions and accompanying liquidity holes, where transactions are carried out along the chain but scarce otherwise. We also explore how it is linked to endowed wealth and the pool of initial orders. Our model can be used for further extension to study trading behaviors in more complex systems.
Keywords
Keywords
◼
Liquidity Hole
◼
Trading Network
◼
Topological Graph
Acknowledgment
Acknowledgment
I am deeply grateful to the advice and support from James Boyed and Nik Murzin. I also thank Stephen Wolfram for his valuable advice. I am grateful to them for their guidance. All errors are my own.
References
References
◼
Wolfram, Stephen, 2022. Games and Puzzles as Multicomputational Systems https://writings.stephenwolfram.com/2022/06/games-and-puzzles-as-multicomputational-systems/