Risk Calculator for Perpetual Trading on dYdX


dYdX Grants Team

Bayswater Capital received funding from the dYdX Grants Program for the following projects:

  • Market Making Trading Bot
  • Monte Carlo Risk Calculator
  • Rewards Estimator Tool

Background on Bayswater Capital

The Bayswater Capital team consists of three traders and experts in designing cryptocurrency trading tools:

- Mélody Frédérique: Bachelor of Science (B.Sc) Software Engineering, Master of Science (MS) Financial Markets EDHEC Business School

- Marie-Claude Sibylle: Bachelor of Science (B.Sc) Software Engineering, Master of Science (MS) Financial Markets EDHEC Business School and

- Will Tan: Bachelor of Finance, Bachelor of Laws – University of Sydney 

Risk Application Tool for Perpetual Trading on dYdX

The goal of this project is to create a comprehensive set of risk estimation and alerting tools to:

(1) prevent excessive risk-taking and

(2) alert traders to potential liquidations

Ultimately, the goal is to provide cryptocurrency traders with the tools to minimize risk exposure and probability of liquidation, thereby reducing the overall risk to the dYdX exchange and protocol.

dYdX Exchange Risk Calculator
dYdX Exchange Risk Calculator

What is Monte Carlo Simulation? 

Monte Carlo simulation is a relatively straightforward mathematical technique used to predict potential outcomes of uncertain events and, thus, to manage uncertainty. Monte Carlo simulations are a common tool used by economists in their cost-utility models and traders for portfolio management.

How does the Monte Carlo Risk Calculator for the dYdX exchange work?

The team built a calculator to estimate a trader’s chances of liquidation for some look-forward period using stochastic methods, which are methods that make use of random values to simulate market movements. The tool can be found on GitHub where users can create historical and Monte Carlo simulations to estimate their chances of being liquidated on dYdX.

Users can customize their request according to a look-forward period (24 hours), portfolio of dYdX perpetuals, number of simulations, and correlation structures. The tool also provides more traditional risk metrics such as Value-At-Risk and Expected Shortfall.

To improve usability, the team built a web app for users to input their portfolio details and other relevant risk parameters to estimate their chances of liquidation.

Detailed instructions for using the tool can be found in this instructional video:

Advantages of using the Monte Carlo Risk Calculator for Perpetual Trading

  • Probabilistic Results: Results show not only what could happen, but how likely each outcome is.
  • Graphical Results: It's easy to create graphs of different outcomes and their chances of occurrence.
  • Sensitivity Analysis: Analyze the impact of each individual input on the result.

Using Monte Carlo models can help establish probabilities on a number of important performance metrics, such as:

  • Risk of liquidation
  • Maximum and median drawdowns 
  • Annual rates of return 
  • Return / drawdown ratios

Traders are provided results from historical and Monte Carlo simulations and provided with tradFi risk metrics such as Value-At-Risk and Expected Shortfall.

Benefits of using value-at-risk and expected shortfall values

Value at risk (VaR) 

Value at risk (VaR) is a market risk measure that quantifies potential losses associated with market fluctuations. VaR tries to provide a single number that would answer the following question:

“How much I can lose at most on this investment in a given period of time?”

Depending on the portfolio composition, market data used and quantile level (confidence/significance level, α), VaR measures the overall risks associated with market movements.

The VaR approach is attractive because it is easy to understand. It provides an estimate of the amount of capital needed to support a certain level of risk.

Another advantage of this measure is the ability, to some extent, to incorporate the effects of portfolio diversification.

Expected Shortfall

In response to the lack of coherence for the VaR risk measure, several alternatives have been proposed. Of these, the most common is expected shortfall.

Expected shortfall is defined based on the results from the VaR calculation. 

Can a beginner trader on dYdX take advantage of the risk calculator?

The risk calculator is available to anyone, with any sort of trading experience. As mentioned above, the GitHub code is available for people who want to try to build on top of it, and there's also a Streamlit page where people can just simply put in their portfolio and the tool will generate all the information needed of having an automated trading system on dYdX.

In the upcoming dYdX transition to Cosmos and the V4, will the tool be functional?

The Monte Carlo simulation risk tool shouldn't have any issues migrating over dYdX V4.

dydx v4 cosmos