Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: config parametrization #24

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading