浏览代码

kappa,和gamma

skyfffire 1 年之前
父节点
当前提交
106863f840
共有 2 个文件被更改,包括 31 次插入32 次删除
  1. 30 31
      strategy/src/avellaneda_stoikov.rs
  2. 1 1
      strategy/src/strategy.rs

+ 30 - 31
strategy/src/avellaneda_stoikov.rs

@@ -194,39 +194,38 @@ impl AvellanedaStoikov {
     }
 
     pub fn update_gamma(&mut self) {
-        self.gamma = if self.spread_min == Decimal::ZERO {
+        self.gamma = if self.sigma_square == Decimal::ZERO || self.inventory == Decimal::ZERO {
             Decimal::ONE
         } else {
-            Decimal::ONE + Self::IRA * (self.spread_max / self.spread_min).sqrt().unwrap() / Decimal::TEN
+            Self::IRA * (self.spread_max - self.spread_min) / (Decimal::TWO * self.inventory.abs() * self.sigma_square)
         };
-
         self.gamma.rescale(8);
     }
 
     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 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;
+        if self.spread_max == Decimal::ZERO {
+            self.kappa = Decimal::ONE;
         } else {
-            self.kappa = dec!(1);
+            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 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);
+        // }
     }
 
     pub fn update_ref_price(&mut self) {
@@ -301,13 +300,13 @@ 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 {
             return;

+ 1 - 1
strategy/src/strategy.rs

@@ -1079,7 +1079,7 @@ impl Strategy {
         }
 
         self._cancel_open(&mut command, local_orders);              // 撤单命令处理
-        self._post_open(&mut command, local_orders, predictor);     // 限价单命令处理
+        // self._post_open(&mut command, local_orders, predictor);     // 限价单命令处理
         self._check_local_orders(&mut command, local_orders);       // 固定时间检查超时订单
         self._update_in_cancel(&mut command, local_orders);         // 更新撤单队列,是一个filter
         self._check_request_limit(&mut command);                    // 限制频率,移除不合规则之订单,是一个filter