<jupyter_start><jupyter_text>System Model V3 - Query: does market price decline with controller, when $K_i < 0$?The purpose of this notebook is to simulate a single run of the full CDP and APT system model, using a stochastic Ethereum price and liquidity demand process as a driver.For this simulation run, we will be asking the following question: does market price decline with controller, when $K_i < 0$?3. Query: does market price decline with controller, when $K_i < 0$?---  - Run simulation with:     - ETH price shock OFF     - Liquidity shocks OFF     - Controller ON with $K_p$ and $K_i$ equalling recommended values     - Arbitrageur considers liquidation ratio:       - ON       - OFF     - Target price rescaled:       - ON       - OFF              We will override the recommended parameters in [init.py](https://github.com/BlockScience/reflexer/blob/experiment-analysis/models/system_model_v3/model/params/init.py)In order to test this, configure the following experiment [Query_3.py](experiments/system_model_v3/Query_3.py). Run run this simulation, we create a directory in the ```experiments/system_model_v3``` called ```Query_3/```,and add a ```logs/``` directory inside of it.Assuming our we have all of the requirements required (run requirements.txt from the ```reflexer/``` root directory to be sure. Assuming our terminal is in the root directory, we run the follow to run the simulation:```bashcd experiments/system_model_v3python3 -m experiments.system_model_v3.Query_3```And our simulation will run. The resulting [run log](experiments/system_model_v3/Query_3/experiment_run_log.md) can be found in the ```experiments/system_model_v3/Query_3/``` directory, along with the simulation results stored as ```experiment_results.hdf5```Below we will import and examine the simulation results.<jupyter_code># import libraries
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os

%matplotlib inline<jupyter_output><empty_output><jupyter_text>Import simulation run data<jupyter_code>os.getcwd()
os.chdir('../../')
os.getcwd()
experiment_results = 'experiments/system_model_v3/Query_3/experiment_results.hdf5'
experiment_results_keys = []
with pd.HDFStore(experiment_results) as store:
    experiment_results_keys = list(filter(lambda x: "results" in x, store.keys()))
    exceptions_keys = list(filter(lambda x: "exceptions" in x, store.keys()))
# A list of all experiment result keys
experiment_results_keys
# Copy a results_ key from the above keys to select the experiment
experiment_results_key = experiment_results_keys[-1]#'results_2021-02-09T18:46:33.073363' # Or select last result: experiment_results_keys[-1]
experiment_timestamp = experiment_results_key.strip('results_')
exceptions_key = 'exceptions_' + experiment_timestamp
experiment_timestamp
df_raw = pd.read_hdf(experiment_results, experiment_results_key)
df_raw.tail()<jupyter_output><empty_output><jupyter_text>Post process<jupyter_code>from experiments.system_model_v3.post_process import post_process_results
from experiments.system_model_v3.Query_3 import params, SIMULATION_TIMESTEPS
params
# add swept parameters as a column
df = post_process_results(df_raw, params, set_params=['rescale_target_price','arbitrageur_considers_liquidation_ratio','liquidation_ratio'])
df<jupyter_output>Adding new columns
0.04308629035949707
Getting parameter sweep
0.043213844299316406
Assigning parameters to subsets
0.807908296585083
Creating target_price_scaled
0.8128876686096191<jupyter_text>Simulation Analysis- Outcomes from these simulations are interpretable only after Query 1 and Query 2 outcomes have been determined, but:    -  **if market price declines when arbitrageur considers liquidation ratio is ON and target price rescaled is ON**:       - Implication from Reflexer: negative $K_i$ term is concluded to be introducing negative drift in the market price<jupyter_code>df.substep.unique()
df.subset.unique()
df.columns<jupyter_output><empty_output><jupyter_text>Generate key plots for analysis<jupyter_code>df_true_true = df.query('rescale_target_price==True and arbitrageur_considers_liquidation_ratio == True')
sns.lineplot(data=df_true_true,x="timestamp", y="eth_price",label='Generated Eth price')
plt.ylim(250, 600)
ax2 = plt.twinx()
sns.lineplot(data=df_true_true,x="timestamp", y="market_price",ax=ax2,color='r',label='Market Price in Rai')
sns.lineplot(data=df_true_true,x="timestamp", y="target_price_scaled",ax=ax2,color='g',label='Redemption Price in Rai')
plt.title('Liquidation ratio is ON and target price rescaled is ON')
plt.legend(loc="upper left")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09092872570194384, 'fraction_numerical': 0.027861771058315336, 'mean_word_length': 6.281446540880503, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 20, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '325867', 'license': 'MIT', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1390, 'n_words': 418, 'path': 'notebooks/analysis/experiment_notebooks/Query_3_does_market_price_decline_with_controller_when_K_i_less_than_0.ipynb', 'repo_name': 'trangnv/geb-simulations-h20', 'size': '4630'}