|
|
@@ -42,6 +42,7 @@ pub struct AvellanedaStoikov {
|
|
|
pub base_delta: Decimal, // 基础挂单距离
|
|
|
pub ratio_edge: Decimal, // 资金流修正的挂单距离
|
|
|
pub ref_price: Decimal, // 预定价格
|
|
|
+ pub init_delta_plus: Decimal, // 最初的delta之和
|
|
|
|
|
|
pub cci_arc: Arc<Mutex<CentralControlInfo>>, // 中控信息
|
|
|
|
|
|
@@ -80,6 +81,8 @@ impl AvellanedaStoikov {
|
|
|
ask_delta: Default::default(),
|
|
|
bid_delta: Default::default(),
|
|
|
base_delta: Default::default(),
|
|
|
+ init_delta_plus: Default::default(),
|
|
|
+
|
|
|
ratio_edge: Default::default(),
|
|
|
kappa: Default::default(),
|
|
|
flow_in_value: Default::default(),
|
|
|
@@ -194,38 +197,33 @@ impl AvellanedaStoikov {
|
|
|
}
|
|
|
|
|
|
pub fn update_gamma(&mut self) {
|
|
|
- self.gamma = if self.sigma_square == Decimal::ZERO || self.inventory == Decimal::ZERO {
|
|
|
- Decimal::ONE
|
|
|
- } else {
|
|
|
- Self::IRA * (self.spread_max - self.spread_min) / (Decimal::TWO * self.inventory.abs() * self.sigma_square)
|
|
|
- };
|
|
|
- self.gamma.rescale(8);
|
|
|
+ // self.gamma = if self.sigma_square == Decimal::ZERO || self.inventory == Decimal::ZERO {
|
|
|
+ // Decimal::ONE
|
|
|
+ // } else {
|
|
|
+ // Self::IRA * (self.spread_max - self.spread_min) / (Decimal::TWO * self.inventory.abs() * self.sigma_square)
|
|
|
+ // };
|
|
|
+ // self.gamma.rescale(8);
|
|
|
+
|
|
|
+ self.gamma = dec!(0.1) * Self::IRA;
|
|
|
}
|
|
|
|
|
|
pub fn update_kappa(&mut self) {
|
|
|
- if self.spread_max == Decimal::ZERO {
|
|
|
- self.kappa = Decimal::ONE;
|
|
|
- } else {
|
|
|
- let delta_plus_max = (Decimal::TWO - Self::IRA) * self.spread_max + Self::IRA * self.spread_min;
|
|
|
- let mut temp = (delta_plus_max) * self.gamma - self.sigma_square * self.gamma.powd(Decimal::TWO);
|
|
|
-
|
|
|
- temp.rescale(6);
|
|
|
+ // self.kappa = if self.spread_max.is_zero() || self.init_delta_plus.is_zero() {
|
|
|
+ // Decimal::ONE
|
|
|
+ // } else {
|
|
|
+ // let mut temp = self.init_delta_plus * self.gamma - self.sigma_square * self.gamma.powd(Decimal::TWO);
|
|
|
+ // temp.rescale(6);
|
|
|
+ //
|
|
|
+ // self.gamma / (temp.exp() - Decimal::ONE)
|
|
|
+ // };
|
|
|
+ //
|
|
|
+ // self.kappa.rescale(8);
|
|
|
|
|
|
- self.kappa = if temp <= Decimal::ZERO {
|
|
|
- Decimal::TEN
|
|
|
- } else if temp >= Decimal::TEN {
|
|
|
- Decimal::TEN
|
|
|
- } else {
|
|
|
- self.gamma / (temp.exp() - Decimal::ONE)
|
|
|
- };
|
|
|
- self.kappa.rescale(8);
|
|
|
+ if self.mid_price > Decimal::ZERO {
|
|
|
+ self.kappa = dec!(888) / self.mid_price;
|
|
|
+ } else {
|
|
|
+ self.kappa = dec!(1);
|
|
|
}
|
|
|
-
|
|
|
- // if self.mid_price > Decimal::ZERO {
|
|
|
- // self.kappa = dec!(888) / self.mid_price;
|
|
|
- // } else {
|
|
|
- // self.kappa = dec!(1);
|
|
|
- // }
|
|
|
}
|
|
|
|
|
|
pub fn update_ref_price(&mut self) {
|
|
|
@@ -234,18 +232,18 @@ impl AvellanedaStoikov {
|
|
|
|
|
|
pub fn update_delta(&mut self) {
|
|
|
if self.gamma != Decimal::ZERO {
|
|
|
- self.base_delta = (Decimal::ONE / self.gamma) * (Decimal::ONE + self.gamma / self.kappa).ln();
|
|
|
+ self.base_delta = self.gamma * self.sigma_square * self.t_diff / Decimal::TWO + (Decimal::ONE / self.gamma) * (Decimal::ONE + self.gamma / self.kappa).ln();
|
|
|
self.ratio_edge = (self.flow_ratio * self.base_delta) * Decimal::TWO;
|
|
|
|
|
|
self.bid_delta = self.base_delta;
|
|
|
self.ask_delta = self.base_delta;
|
|
|
|
|
|
if self.inventory > Decimal::ZERO {
|
|
|
- let pos_edge = ((Decimal::ONE + Decimal::TWO * self.inventory) / Decimal::TWO) * (self.gamma * self.sigma_square) * self.t_diff;
|
|
|
+ let pos_edge = self.gamma * self.sigma_square * self.inventory * self.t_diff / Decimal::TWO;
|
|
|
|
|
|
self.bid_delta += pos_edge;
|
|
|
} else if self.inventory < Decimal::ZERO {
|
|
|
- let pos_edge = ((Decimal::ONE - Decimal::TWO * self.inventory) / Decimal::TWO) * (self.gamma * self.sigma_square) * self.t_diff;
|
|
|
+ let pos_edge = self.gamma * self.sigma_square * self.inventory.abs() * self.t_diff / Decimal::TWO;
|
|
|
|
|
|
self.ask_delta += pos_edge;
|
|
|
}
|
|
|
@@ -254,6 +252,10 @@ impl AvellanedaStoikov {
|
|
|
} else if self.ratio_edge > Decimal::ZERO {
|
|
|
self.ask_delta += self.ratio_edge.abs()
|
|
|
}
|
|
|
+
|
|
|
+ if self.init_delta_plus.is_zero() {
|
|
|
+ self.init_delta_plus = (self.bid_delta + self.ask_delta) / Decimal::TWO
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -300,19 +302,19 @@ impl AvellanedaStoikov {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // if self.optimal_ask_price < self.ask_price {
|
|
|
- // return;
|
|
|
- // }
|
|
|
- //
|
|
|
- // if self.optimal_bid_price > self.bid_price {
|
|
|
- // return;
|
|
|
- // }
|
|
|
+ if self.optimal_ask_price < self.ask_price {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.optimal_bid_price > self.bid_price {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if self.depth_vec.len() < 200 {
|
|
|
+ if self.depth_vec.len() < 100 {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if self.trade_vec.len() < 200 {
|
|
|
+ if self.trade_vec.len() < 100 {
|
|
|
return;
|
|
|
}
|
|
|
|