-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVirtualLiquidityPoolSimulation.m
95 lines (67 loc) · 1.85 KB
/
VirtualLiquidityPoolSimulation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
n = 1000;
T_stable = Token("TokenA");
T_volatile = Token("TokenB");
BasePool = 10000;
P_volatile = 10;
PoolRecoveryPeriod = 36;
sigma = 0.0001;
virtualPool = VirtualLiquidityPool(T_stable, T_volatile, P_volatile, ...
BasePool, PoolRecoveryPeriod);
% initialize delta and price variation vecotors
d = zeros(1, n + 1);
% initialize wallet distribution
walletExpRate = 0.00003;
initialFreeTokenSupply = 3*BasePool;
walletProbDistribution = WalletBalanceGenerator(initialFreeTokenSupply, walletExpRate);
% initialize the random purchaise generator
pool = LiquidityPool(T_stable, T_volatile, 1, 1, 0);
initialProbability = 0.5;
purchaseGenerator = PurchaseGenerator(pool, n, initialProbability, sigma, walletProbDistribution);
%% evenly spaced impulses
virtualPool.resetReplenishingSystem();
for i = 2:(n+1)
if (mod(i, 100) == 0)
virtualPool.swap(T_stable, 1000);
end
d(i) = virtualPool.Delta;
if (mod(i, 6) == 0)
virtualPool.restoreDelta();
end
end
plot(d);
xlim([0, n]);
%% exponential signal
a = 1.01;
m = 0:(n+1)/2;
x = a.^m;
y = zeros(1, n+1);
virtualPool.resetReplenishingSystem();
for i = 2:(n+1)
if (i < (n+1)/2)
virtualPool.swap(T_stable, x(i));
y(i) = y(i-1) + x(i);
end
d(i) = virtualPool.Delta;
if (mod(i, 6) == 0)
virtualPool.restoreDelta();
end
end
plot(d);
hold on;
plot(y);
xlim([0, n]);
hold off;
%% random signal
virtualPool.resetReplenishingSystem();
for i = 2:n+1
r = rand(1, 1);
% choose if there will be a transaction in this iteration
if (r > 0.5)
[token, quantity] = purchaseGenerator.rndPurchase(initialFreeTokenSupply, initialFreeTokenSupply*3);
[~, q] = virtualPool.swap(token, quantity);
end
d(i) = virtualPool.Delta;
virtualPool.restoreDelta();
end
plot(d);
xlim([0, n]);