Skip to main content
Version: 2.0.2

Montecarlo

A montecarlo simulation in short is a multitude of single simulations using a specification of what is different between the different single simulations. This means you can create anywhere from 2 to hundreds of simulations that run at the same time using a set of parameters of configuration changes.

Usually running the exact same simulation twice doesn't give a lot of difference in the results, and that's not what the montecarlo simulation is meant for. But it can do that too. It's super flexible and allows you to specify exactly what is different between each simulation.

Running a Montecarlo

To run a montecarlo we require Run Specifications for each simulator run you would like the montecarlo to execute. This run specification is a JSON object that specifies what values of the configuration have to be updated. So you can for example change the block value for every run.

Maybe most importantly you can change the prices value between each simulation. This gives a lot of flexibility for running multiple simulations at the same time.

The Run Specifications can be provided in 2 ways, via a JSON string as a parameter for the CLi and SDK. Or as a file run_specification.json.

The run_specification.json file has to be present in the same folder as the configuration.yaml when creating a montecarlo simulation. They will be uploaded at the same time.

An example of Run Specifications looks like 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',
'holdings': 'token',
'models': 'alias'

This way you can write environments.ethereum1.block which uses the value of the alias identifier. In this example that value is ethereum1 which the system uses to find the correct item and update the block value of that item.

As you can see in the example there are multiple ways of passing in certain values. As a general rule of thumb you can always pass in the value directly or through a gs:// link. This will pull the information from a Google Cloud Storage bucket as long as the simulator has access to it (If not it will throw an error). The library system will also still work here, just use library:// to update any supported item to a different library item.

For prices there is also the option to pass in the Price Simulation ID via price-id:// which will pull the Price Simulation result from the correct location and parse it to the correct storage format for the configuration.

Result

To get the result of the montecarlo you can use the CLI or SDK.

Metrics

To get the metrics of the montecarlo you can use the CLI or SDK.