-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti-asset.html
385 lines (343 loc) · 16.5 KB
/
multi-asset.html
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Multi-Asset Risk</title>
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<link rel="stylesheet" href="css/bulmaswatch.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@creativebulma/bulma-tooltip@1.2.0/dist/bulma-tooltip.min.css" />
<style>
.main {
/*display: flex;*/
min-height: 100vh;
flex-direction: column;
}
.positoin-sizes-container {
/*max-height: 50vh;
max-width: 100vh;*/
/*width: 200px;*/
/*height: 100px;*/
/*overflow-y: auto;*/
}
.noBorder {
border: none;
border-radius: 30px;
box-background-color: none;
}
.progress {
border-radius: 5;
background-color: blue;
color: white;
}
.chartSize {
max-height: 50vh;
max-width: 50vh;
}
.monteCarloChartSize {
max-height: 85vh;
/*max-width: 85vh;*/
}
</style>
</head>
<body>
<div class="main">
<!-- Header -->
<section class="section pb-0">
<div class="columns">
<div class="column is-3" style="text-align:left;">
<button class="button is-rounded"><a href="single-asset.html">Single   Asset</a></button>
</div>
<div class="column is-6 has-text-centered">
<p class="title is-3">⚠ DyDx Risk Station ⚠</p>
</div>
<div class="column is-3" style="text-align:right;">
<button class="button is-rounded"><a href="sausage.html">Documentation</a></button>
</div>
</div>
<div class="columns">
<div class="column has-text-centered">
<p><i>The comprehensive DyDx risk calculator.</i></p>
</div>
</div>
</section>
<section class="section">
<div class="tile is-ancestor is-vertical">
<!-- User Inputs -->
<div class="tile is-parent is-vertical box">
<div class="tile is-parent">
<div class="tile is-child">
<div class="columns is-centered">
<button class="button is-rounded" aria-haspopup="true" aria-controls="dropdown-menu2" id="selectPosSize" onclick="document.getElementById('posModal').classList.add('is-active')">
Select Perpetuals   <i class="fas fa-plus" id="advancedOptionsArrow"></i>
</button>
</div>
</div>
</div>
<div class="tile is-parent py-0">
<div class="tile is-child is-4"></div>
<div class="tile is-child is-4">
<div id="posSizeBoxes">
</div>
</div>
<div class="tile is-child is-4"></div>
</div>
<div class="tile is-parent">
<div class="tile is-child">
<!-- <div class="columns is-centered">
<span>Account Equity  </span>
<div class="has-tooltip-multiline" data-tooltip="The amount of USDC in the DyDx account." style="display: inline;">
<i class="fas fa-info-circle is-info"></i>
</div>
</div>
<div class="columns is-centered">
<div class="column is-one-third is-offest-one-third">
<input class="input is-rounded" type="text" id="accountEquity" placeholder="e.g. 10000 for $10,000 USDC" value="100">
</div>
</div> -->
<div class="columns is-centered">
<div class="column is-one-quarter is-offest-4 has-text-centered">
<label for="accountEquity">Account Equity</label>
<div class="has-tooltip-multiline" data-tooltip="The amount of USDC in the DyDx account." style="display: inline;">
<i class="fas fa-info-circle is-info"></i>
</div>
<input class="input is-rounded" type="text" id="accountEquity" placeholder="e.g. 10000 for $10,000 USDC" value="100">
</div>
</div>
</div>
</div>
<div class="tile is-parent">
<div class="tile is-child">
<div class="columns is-centered">
<button class="button is-rounded" id="advancedOptionsButton">
Advanced Options   <i class="fas fa-arrow-down" id="advancedOptionsArrow"></i>
</button><br><br>
</div>
</div>
</div>
<div class="py-0" id="advancedOptions" style="display: none;">
<div class="tile is-parent">
<div class="tile is-child">
<div class="columns is-centered">
<div class="column">
<label for="annualDriftBox">Expected Annual Log-Returns</label>
<div class="has-tooltip-multiline" data-tooltip="The expected log-returns of the perpetual one year from today. Log-returns is defined as ln(1+return_pct/100)." style="display: inline;">
<i class="fas fa-info-circle is-info"></i>
</div>
<input class="input is-rounded" type="text" id="annualDriftBox" placeholder="">
</div>
<div class="column">
<label for="annualVolBox">Expected Annual Volatility</label>
<div class="has-tooltip-multiline" data-tooltip="The expected standard deviation of log-returns one year from today. This default value comes from annualizing the standard deviation of hourly log-returns over the previous 30 days. Log-returns is defined as ln(1+return_pct/100)." style="display: inline;">
<i class="fas fa-info-circle is-info"></i>
</div>
<input class="input is-rounded" type="text" id="annualVolBox" placeholder="">
</div>
</div>
</div>
</div>
</div>
<div class="tile is-parent">
<div class="tile is-child">
<div class="columns is-centered">
<button class="button is-primary is-rounded" type="button" id="getRiskStatsButton">
⚠ Get Risk Statistics ⚠
</button>
</div>
</div>
</div>
<div class="tile is-parent" style="display: none;">
<div class="tile is-child">
<div class="columns" id="statusBarContainer">
<div class="column is-one-third is-offset-one-third" id="progressBarDiv"></div>
</div>
</div>
</div>
</div>
<!-- Generated Content -->
<div id="generatedStats" style="display: none;">
<!-- <div id="generatedStats"> -->
<!-- Health Score -->
<div class="tile is-parent is-vertical box px-0">
<div class="tile is-parent">
<div class="tile is-child">
<div class="columns is-centered">
<div class="column is-4"></div>
<div class="column is-4 has-text-centered">
<p class="title" id="healthScoreTitle">
Health Score
<span class="has-tooltip-multiline" data-tooltip="An estimate of probability of that your portfolio will not be liquidated within the next 7 days. Higher scores are better." style="text-decoration: none;">
<i class="fas fa-info-circle is-info"></i>
</span>
</p>
<p class="title" id="healthScoreValue"></p>
</div>
<div class="column is-4"></div>
</div>
<div class="columns is-centered">
<p><i id="prescription"></i></p>
</div>
</div>
</div>
</div>
<!-- Risk Synopsis -->
<div class="tile is-parent px-0">
<div class="tile is-child">
<article class="message is-large is-primary">
<div class="message-header">
<p>Risk Synopsis</p>
</div>
<div class="message-body">
<p>
This portfolio currently has <span id="openInterestSpan"></span> of open interest, and <span id="equitySpan"></span> of equity. The current portfolio requires <span id="collatReq"></span> of equity to stay above the liquidation point. We estimate the portfolio has a <span id="probLiq1Day"></span> chance of being liquidated within a day, and a <span id="probLiq7Day"></span> chance of being liquidated within 7 days.
<!-- <br><br>
To get a better understanding of value trajectories that this portfolio could follow, see <a href="#monteCarloSection">Monte Carlo Simulation</a>. For more metrics to help you understand your risk, see <a href="#riskStatsSection">Risk Statistics</a>. For more detail on how the calculations are performed, take a look at <a href="sausage.html">how the sausage gets made</a>. -->
</p>
</div>
</article>
</div>
</div>
<!-- Liquidation Probabilities -->
<div class="tile is-vertical">
<div>
<div class="title">Liquidation Probabilities</div>
<p><i>The probability that the given portfolio will be liquidated within a given period of time. This is useful for understanding the risk of holding a leveraged portfolio for long.</i></p>
</div>
<div class="tile py-0 px-0">
<div class="tile is-parent">
<div class="tile is-child box" id="shortTermLiqProbBox">
<canvas id="shortTermLiqProbChart" width="200" height="150"></canvas>
</div>
</div>
<div class="tile is-parent">
<div class="tile is-child box" id="longTermLiqProbBox">
<canvas id="longTermLiqProbChart" width="200" height="150"></canvas>
</div>
</div>
</div>
<!-- Monte Carlo Section -->
<div class="tile is-parent is-vertical px-0">
<div class="title" id="monteCarloSection">Monte Carlo Price Simulation</div>
<p><i>These are possible paths that the portfolio's equity value can take, showing you what to expect from holding onto the portfolio. Modify drift and volatility "Advanced Options" to see how this graph changes!</i></p>
<div class="tile is-parent px-0">
<div class="tile is-child box">
<div class="columns is-centered">
<canvas class="monteCarloChartSize" id="monteCarloChart" width="200" height="150"></canvas>
</div>
<div class="columns is-centered">
<div class="column has-text-centered">
<p><i>Blue Dashed Line = Initial Equity; Red Dashed Line = Estimated Liquidation Equity</i></p>
</div>
</div>
<div class="tile is-parent">
<div class="tile is-child">
<div class="columns is-centered">
<div class="column">
<label for="nHoursMC">Look-Forward Hours</label>
<div class="has-tooltip-multiline" data-tooltip="The number of hours to look forward when running Monte Carlo simulations." style="display: inline;">
<i class="fas fa-info-circle is-info"></i>
</div>
<input class="input" type="text" id="nHoursMC" placeholder="e.g. 24 for 24 hours">
</div>
<div class="column">
<label for="nCarloPaths">Number of Paths</label>
<div class="has-tooltip-multiline" data-tooltip="The number of Monte Carlo price paths to simulate." style="display: inline;">
<i class="fas fa-info-circle is-info"></i>
</div>
<input class="input" type="text" id="nCarloPaths" placeholder="e.g. 10 for 10 Monte Carlo Paths">
</div>
</div>
</div>
</div>
<div class="tile is-parent">
<div class="tile is-child">
<div class="columns is-centered">
<button class="button is-primary is-rounded" type="button" id="runMCButton" onclick="runMonteCarlo()">
🎲   Run Monte Carlo Simulation   🎲
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Risk Statistics -->
<div class="tile is-parent px-0">
<div class="tile is-parent">
<div class="tile is-child box">
<div class="columns is-centered">
<h4 class="title is-4">General Stats</h4>
</div>
<div class="columns is-centered">
<table class="table is-full-width">
<tbody id="scalarResultsTable"></tbody>
</table>
</div>
</div>
</div>
<div class="tile is-parent">
<div class="tile is-child box" id="monteCarloResults">
<div class="columns is-centered">
<h4 class="title is-4">Monte Carlo Stats</h4>
</div>
<div class="columns is-centered">
<table class="table is-full-width">
<tbody id="mcResultsTable"></tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Correlations -->
<div class="tile is-parent is-vertical box">
<div class="tile is-parent">
<div class="tile is-child">
<h4 class="title is-4">Correlations</h4>
</div>
</div>
<div class="tile is-parent is-vertical">
<div class="tile is-child">
<div class="columns is-centered">
<canvas class="chartSize" id="correlationHeatMap" width="200" height="200"></canvas>
</div>
<div class="columns is-centered">
<p><i>Pearson Correlation Coefficient of the Log Returns, ranging from -1 to 1. A value of -1 means the two assets are purely anti-correlated (when one goes up, the other typically goes down). A value of 1 means they are purely correlated. A value near 0 means there is no linear correlation relationship present. In general, your portfolio will be better diversified, and thus have lower variation in returns, if the assets in your portfolio are anti-correlated.</i></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<div id="modals">
<div class="modal" id="posModal">
<div class="modal-background" onclick="positionModalClose()"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Select DyDx Perpetuals</p>
<button class="delete" aria-label="close" onclick="positionModalClose()"></button>
</header>
<section class="modal-card-body" id="posModalCardBody"></section>
<footer class="modal-card-foot">
<div class="columns">
<div class="column has-text-centered">
<button class="button is-primary" onclick="positionModalClose()">Save Selections</button>
</div>
</div>
</footer>
</div>
</div>
</div>
<script src="js/footer.js"></script>
<script src="js/multiAsset.js"></script>
<script src="js/carlo.js"></script>
<script src="js/math.min.js"></script>
<script src="js/distributions.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.7"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-chart-matrix@1"></script>
<script async src="https://cdn.jsdelivr.net/npm/danfojs@0.3.3/lib/bundle.min.js"></script>
<script async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</body>
</html>