function StochasticPricingModelPoiss() P0=20; % P0: Asset price at t=0 lambdaB=19; % lambdaB: Buy order poisson distribution rate parameter lambdaS=19; % lambdaS: Sell order poisson distribution rate parameter T=390; % T: Total number of time intervals dp=0.01; % dp: Price increment (e.g. 0.01 is one cent) muBuyOrigin=0.50; nuBuy=1; muSellOrigin=0.50; nuSell=1; numBuyOrders(1)=0; numSellOrders(1)=0; pCurrent(1)=P0; buyQueue=zeros((2*(P0/dp)+1),1); sellQueue=zeros((2*(P0/dp)+1),1); for t=2:T numBuyOrders(t)=numBuyOrders(t-1)+round(randp(lambdaB)); numSellOrders(t)=numSellOrders(t-1)+round(randp(lambdaS)); for N=1:numBuyOrders(t) pBuyOrigin=pCurrent(t-1)+round(100*randexp(muBuyOrigin))/100; % Matlab: exprnd(muBuyOrigin) pBuy=pBuyOrigin-round(100*randchi(nuBuy))/100; % Matlab: chi2rnd(nu) buyQueue(pBuy)=buyQueue(pBuy)+1; end for M=1:numSellOrders(t) pSellOrigin=pCurrent(t-1)+round(100*randexp(muSellOrigin))/100; % Matlab: exprnd(muBuyOrigin) pSell=pSellOrigin-round(100*randchi(nuSell))/100; % Matlab: chi2rnd(nu) sellQueue(pSell)=sellQueue(pSell)-1; end end % while tOrder(n)<=1000 % % if rand>0.50 % orderType=1; % Buy % pOrigin=pCurrent(n)+randexp(muBuyOrigin); % Matlab: exprnd(muBuyOrigin) % p(n)=round(pOrigin)-round(randchi(nu)); % Matlab: chi2rnd(nu) % if numSell(max(p(n),1))~= 0 % numSell(max(p(n),1))=numSell(max(p(n),1))-1; % pCurrent(n+1)=p(n); % else % numBuy(max(p(n),1))=numBuy(max(p(n),1))+1; % pCurrent(n+1)=pCurrent(n); % end % % else % orderType=-1; % Sell % pOrigin=pCurrent(n)-randexp(muSellOrigin); % p(n)=round(pOrigin)+round(randchi(nu)); % if numBuy(min(p(n),1001))~= 0 % numBuy(min(p(n),1001))=numBuy(min(p(n),1001))-1; % pCurrent(n+1)=p(n); % else % numSell(min(p(n),1001))=numSell(min(p(n),1001))+1; % pCurrent(n+1)=pCurrent(n); % end % end % % % tOrder(n+1)=tOrder(n)+randexp(muOrderTime); % n=n+1; % % end