Skip to content

Commit

Permalink
feat: config parametrization (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu authored Feb 25, 2024
1 parent 0169e16 commit 2289db1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
2 changes: 0 additions & 2 deletions configs/example.toml

This file was deleted.

11 changes: 11 additions & 0 deletions configs/stable_pool.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[admin]]
Deployer = {}

[[admin]]
PoolAdmin = {}

[[admin]]
TokenAdmin = { token_data.TKN0 = { name = "TKN0", symbol = "Token 0", decimals = 18 } }

[[changer]]
PriceChanger = { mu = 1, theta = 1, sigma = 1, cursor = 0, value = 1 }
26 changes: 12 additions & 14 deletions src/behaviors/price_changer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use crate::bindings::liquid_exchange::LiquidExchange;

#[derive(Serialize, Deserialize)]
pub struct PriceChanger {
#[serde(skip)]
pub params: OrnsteinUhlenbeckParams,
mu: f64,
sigma: f64,
theta: f64,

#[serde(skip)]
#[serde(default = "trajectory_default")]
Expand All @@ -35,13 +36,6 @@ fn trajectory_default() -> Trajectories {
}
}

#[derive(Debug, Serialize, Deserialize, Default)]
pub struct OrnsteinUhlenbeckParams {
mu: f64,
sigma: f64,
theta: f64,
}

impl fmt::Debug for PriceChanger {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", serde_json::to_string(self).unwrap())
Expand All @@ -55,14 +49,16 @@ pub struct PriceUpdate {

impl PriceChanger {
/// Public constructor function to create a [`PriceChanger`] behaviour.
pub fn new(initial_value: f64, params: OrnsteinUhlenbeckParams) -> Self {
let ou = OrnsteinUhlenbeck::new(params.mu, params.sigma, params.theta);
pub fn new(initial_value: f64, mu: f64, sigma: f64, theta: f64) -> Self {
let ou = OrnsteinUhlenbeck::new(mu, sigma, theta);

// Chunk our price trajectory over 100 price points.
let current_chunk = ou.euler_maruyama(initial_value, 0.0, 100.0, 100_usize, 1_usize, false);

Self {
params,
mu,
sigma,
theta,
current_chunk,
cursor: 0,
client: None,
Expand All @@ -75,14 +71,16 @@ impl PriceChanger {
impl Behavior<Message> for PriceChanger {
async fn startup(
&mut self,
_client: Arc<ArbiterMiddleware>,
client: Arc<ArbiterMiddleware>,
_messager: Messager,
) -> Result<Option<EventStream<Message>>> {
self.client = Some(client);

Ok(None)
}

async fn process(&mut self, event: Message) -> Result<ControlFlow> {
let ou = OrnsteinUhlenbeck::new(self.params.mu, self.params.sigma, self.params.theta);
let ou = OrnsteinUhlenbeck::new(self.mu, self.sigma, self.theta);

let query: PriceUpdate = match serde_json::from_str(&event.data) {
Ok(query) => query,
Expand Down

0 comments on commit 2289db1

Please sign in to comment.