Skip to main content

Monte Carlo

A Monte Carlo simulation is essentially a series of individual simulations that vary based on specified differences between each run. This approach allows you to create anywhere from a couple to hundreds of simulations that run simultaneously, each with a unique set of configuration parameters.

Typically, running the exact same simulation twice does not yield significantly different results, which is not the primary purpose of a Monte Carlo simulation. However, it can handle such cases as well. The Monte Carlo method is highly flexible, enabling you to specify precisely what changes between each simulation.

Running a Monte Carlo Simulation

To run a Monte Carlo simulation, you need to provide Run Specifications for each simulator run you want the Monte Carlo to execute. This Run Specification is a JSON object that defines which configuration values should be updated. For example, you might change the starting balance for each run.

One of the most important aspects is the ability to change the prices value between simulations, offering considerable flexibility when running multiple simulations concurrently.

The run_specification.json file must be located in the same directory as the configuration.yaml when creating a Monte Carlo simulation. These files will be uploaded together.

An example of a Run Specification looks likRe this:

[
{
"agents.0x6429FEe053768Ffa90a59cAfb98Ca9E8F6471211.settings.initial_borrow_amount": 100000001
},
{
"environments.ethereum1.block": 16801000,
"steps": 100,
"prices": "gs://almanak-simulations/prices_example.json"
},
{
"environments.ethereum1.block": 16801000,
"steps": 100,
"prices": [
{
"tokenPair": [
"ETH",
"USDT"
],
"historical": [
1297.85,
1297.84,
...
]
},
{
"tokenPair": [
"USDT",
"DAI"
],
"historical": [
1.0002,
1.0002,
...
]
},
{
"tokenPair": [
"BNT",
"USDT"
],
"historical": [
0.388,
0.388,
...
]
}
]
}
]

Note here that you can specify items in an array by writing down the value of the "identifier key" which works as follows:

    'agents': 'address',
'parameters': 'name',
'environments': 'name',
'tokens': 'name',
'dependencies': 'name',
'contracts': 'alias',
'models': 'alias'

This allows you to write environments.ethereum1.block, which references the value of the alias identifier. In this example, the value is ethereum1, which the system uses to locate the correct item and update its block value.

As shown in the example, there are multiple ways to pass in values. Generally, you can either provide the value directly or use a gs:// link. The gs:// link pulls information from a Google Cloud Storage bucket, provided the simulator has access (otherwise, an error will occur). The library system is also supported; you can use library:// to update any supported item to a different library item.

For prices, you have the option to pass in the Price Simulation ID via price-id://, which retrieves the Price Simulation result from the correct location and converts it to the appropriate storage format for the configuration.


Tutorial

See the Results & Metrics Tutorial to learn how to obtain and analyze the results and metrics.