sbenthall / SHARKFin

Simulating Heterogeneous Agents with Finance
6 stars 5 forks source link

Run a Lucas Shark Simulation With AMMPS Only #218

Closed mesalas closed 1 year ago

mesalas commented 1 year ago

Aim

We will test that the ammps market can produce results that are in agreement with the Lucas asset pricing model. When the market makers have market maker Lucas factor = 1 they will only consider the dividend for pricing, while if it's 0 they will only consider their inventory. moving the factor away from 1 should create deviations from the Lucas pricing model. Even when the factor is 0 we will expect some degree of alignment between the prices and the Lucas pricing model as the institutional investors are using the Lucas pricing model too.

While the institutional investors are Lucas asset pricers, they have some dispersion of their fair price. This is set by the inst_val_std parameter. We want to see how that dispersion affect the prices and trading.

Setup

AMMPS:

As usual get the latest binaries from the master branch of ammps_sharkfin_container

AMMPS comes with a number of new runtime options for outputs. The most important is the -c option, if it is set to true the logger write a compressed csv file. This saves a large amount of space and avoids us having to compress later. This comes with a small overhead on the cpu but if we are aiming for 1.1 core per simulation we should be covered. A second new option that might be useful is the -p option that adds a prefix to the logs written by ammps.

For running a Lucas shark simulation with ammps only, we need to set an option to simulate a connection with SHARKfin this is done by setting the -s option to true. This option also comes with the -v and -d options that control the daily volume passed to the broker institutions simulating volume from the consumers in SHARKFin. In this case we just set both to 0.0. When using this option there should be no option to specify a RPC host etc.

For running a Lucas Shark 0 simulation with ammps only we need to run:

dotnet [path to binaries]amm.engine.dll RunConfFromFile config_file output_directory -n unique_id_number [-c true] -s true -v 0.0 -d 0.0 [-p prefix]

I suggest using the compression option. Prefix option can be left out if you don't think it is usefull.

AMMPS Configuration Generator

The ammps configuration generator generates a configuration file for the specific ammps simulation, this contains simulation specific parameters such as the period to be simulated, the random seed to be used, and the configurations for the agents in the simulations. It is now packed as a python package that can be installed in a python environment, or the scripts can be run using python. Scripts for generating the configs is found in the acg/simulations subdir.

For the Lucas shark tests we need to run

make_lucas_shark_config.py [-h] [--out-dir CONF_DIR] --name RUN_NAME --seed SEED [--days NUMBER_OF_DAYS] --mm_lucas_factor MM_LUCAS_FACTOR [--mm_size MM_SIZE] [--inst_val_std DIVIDEND_VAL_STD]

The new options are --mm_lucas_factor MM_LUCAS_FACTOR [--mm_size MM_SIZE] [--inst_val_std DIVIDEND_VAL_STD]

Simulation Grid

We want to test a simulation grid where we change the mm_lucas_factor and inst_val_std, and seed parameters.

I propose we use 10 seeds, and mm_lucas_factor =[0.0,0.25,0.5,0.75,1.0] and inst_val_std = [0.01, 0.05, 0.1, 0.15, 0.2] We set the -days parameter to 240 to simulate a "sharkfin year". This will require 5x5X10 = 250 simulations, of about 30 minutes each.

@wjt5121 let me know if you need any input

mesalas commented 1 year ago

Bill has finished the runs and we need to analyze the data. Ok here's what to do for the analysis.

I have a python package for analyzing ammps data called amme_data_processing (ammps was called am me at some point).

The adp/make_daily_close_and_fundamental_r2.py contains a method that calculates the R2 value between the dividend and the daily closing price telling us how much of the variance in price is explained by the variance in dividend.

For simid 250 of Bills last run the r2 is calculated like this

from adp.make_daily_close_and_fundamental_r2 import make_daily_close_and_fundamental_r2

r2 = make_daily_close_and_fundamental_r2("norpc-ABC_NYSE@250_Matching-MatchedOrders.csv.gz","norpc-ABC_NYSE@250_Matching-FundamentalInstsLog.csv.gz")

What we want is

  1. A table of the variables inst_val_std and mmlucasfactor, and the corresponding R2
  2. A plot that shows the R2 as a function of inst_val_std and mmlucasfactor

Bill has made a csv file that contains information for all the runs, in particular the simid and the parameters. With this we should be able to loop over all the simids and find the corresponding output to calculate the R2 and variables associated variables. I have attached the table.

lucas0parametergrid.csv

mesalas commented 1 year ago

Results:

image

lucas_data_with_r2_plots.xlsx