---
# System prepended metadata

title: Pointers for the kp sweep / bear market experiments
tags: [rai, rai-book]

---

# Pointers for the kp sweep / bear market experiments

###### tags: `rai` `rai-book`

:::info
>Up to date by [time=July 2021]
:::

*Authors: Danilo Lessa Bernardineli (BlockScience)*

Those are notes on what could be productive but non-exhaustive ways of implementing changes so that the Digital Twin informs the trajectory on those two different circumstances.

## Kp sweep

**Goal**: to simulate the effect of different changes on the Kp parameter immediately or after a given time from the present time

### Option 1: Sweeping Governance Events

This is done by manually specifying the governance events that should be used on the Extrapolation phase as in https://github.com/reflexer-labs/reflexer-digital-twin/blob/d4c8e4ba243ec0cde71377d805853309f9933aaa/rai_digital_twin/execution_logic.py#L173

Specifically, that line should be updated to `params.update(governance_events=ParamSweep(SCENARIOS, dict))`, where `SCENARIOS` has an `List[List[GovernanceEvent]]` signature. Each element of the list is going to be a different parameter sweep, so in order to sweep for kp=0.5 and kp=2.0 for instance, we would need to have to define `SCENARIOS` as something like:

```python 
EVENTS: List[GovernanceEvent] = ...

EVENT_BASE: GovernanceEvent = EVENTS[-1]
EVENT_1 = GovernanceEvent(1, {**EVENT_BASE.descriptor, 'kp': 0.5})
EVENT_2 = GovernanceEvent(1, {**EVENT_BASE.descriptor, 'kp': 2.0})

SCENARIO_BASE = EVENTS.copy()
SCENARIO_1 = EVENTS[:-1] + EVENT_1
SCENARIO_2 = EVENTS[:-1] + EVENT_2

SCENARIOS = [SCENARIO_BASE, SCENARIO_1, SCENARIO_2]
```

### Option 2: Manually overriding the initial state

This would involve overriding the extrapolation initial state on `pid_params` while not having any governance event.

Reference: https://github.com/reflexer-labs/reflexer-digital-twin/blob/d4c8e4ba243ec0cde71377d805853309f9933aaa/rai_digital_twin/execution_logic.py#L181

## Bear market

**Goal**: to simulate the effect of a systemic ETH/USD price drop immediately or after a given time from the present time

### Option 1: Using an alternative ETH/USD price generator

The ETH/USD future series is generated at the `extrapolate_signals` function, and a simple way of simulating a bear market is to subtract an certain amount of it after some time. Reference: https://github.com/reflexer-labs/reflexer-digital-twin/blob/d4c8e4ba243ec0cde71377d805853309f9933aaa/rai_digital_twin/execution_logic.py#L119

### Option 2: Overriding the extrapolated ETH/USD price feed

Instead of extrapolating the price data, it is possible to simply read the future price from a .csv file. That would involve substituting the `extrapolated_signals` variable on the `extrapolation_cycle`: https://github.com/reflexer-labs/reflexer-digital-twin/blob/d4c8e4ba243ec0cde71377d805853309f9933aaa/rai_digital_twin/execution_logic.py#L277

### Option 3: Behavioral model for price data

Right now, the cadCAD model simply sets the `eth_price` as being whatever is provided by the  `p_exogenous` policy. One alternative is to create a custom function for that variable that makes uses of the simulation timesteps, state and parameters so that the bear market is modelled on a richer setting

Reference: https://github.com/reflexer-labs/reflexer-digital-twin/blob/d4c8e4ba243ec0cde71377d805853309f9933aaa/rai_digital_twin/models/digital_twin_v1/model/partial_state_update_blocks.py#L44

