Ver Fonte

研究交易笔数与犯错概率的关系。

skyfffire há 11 meses atrás
pai
commit
7ae7204c50
2 ficheiros alterados com 19 adições e 14 exclusões
  1. 18 13
      strategy/src/avellaneda_stoikov.rs
  2. 1 1
      strategy/src/strategy.rs

+ 18 - 13
strategy/src/avellaneda_stoikov.rs

@@ -64,7 +64,7 @@ impl AvellanedaStoikov {
     const MAX_TIME_RANGE_MICROS: i64 = 3 * 60_000_000;
     const TRADE_LONG_RANGE_MICROS: i64 = 3 * 60_000_000;
     // const SPREAD_RANGE_MICROS: i64 = 15 * 60_000_000;
-    const TRADE_SHORT_RANGE_MICROS: i64 = 60_000_000;
+    const TRADE_SHORT_RANGE_MICROS: i64 = 30_000_000;
     // const ONE_MILLION: Decimal = dec!(1_000_000);
     // const TWENTY_THOUSAND: Decimal = dec!(20_000);
     const IRA: Decimal = dec!(1);
@@ -329,19 +329,19 @@ impl AvellanedaStoikov {
 
     pub fn update_ref_price(&mut self) {
         if !self.fair_price_vec[0].is_zero() && !self.fair_price_vec[1].is_zero() {
-            // let v0_rate = self.volume_vec[0] / (self.volume_vec[0] + self.volume_vec[1]);
-            // let v1_rate = self.volume_vec[1] / (self.volume_vec[0] + self.volume_vec[1]);
+            let v0_rate = self.volume_vec[0] / (self.volume_vec[0] + self.volume_vec[1]);
+            let v1_rate = self.volume_vec[1] / (self.volume_vec[0] + self.volume_vec[1]);
 
-            // let sma = self.depth_vec[1].asks[0].price;
-            // let smb = self.depth_vec[1].bids[0].price;
+            let sma = self.depth_vec[1].asks[0].price;
+            let smb = self.depth_vec[1].bids[0].price;
 
-            // let mp0 = self.mid_price;
-            // let mp1 = (sma + smb) / Decimal::TWO;
+            let mp0 = self.mid_price;
+            let mp1 = (sma + smb) / Decimal::TWO;
 
-            // let price_diff = mp0 - mp1;
+            let price_diff = mp0 - mp1;
 
-            // self.ref_price = (self.fair_price_vec[0] + self.fair_price_vec[1] + price_diff) / Decimal::TWO;
-            self.ref_price = (self.fair_price_vec[0] + self.fair_price_vec[1]) / Decimal::TWO;
+            self.ref_price = (self.fair_price_vec[0] + self.fair_price_vec[1] + price_diff) / Decimal::TWO;
+            // self.ref_price = (self.fair_price_vec[0] + self.fair_price_vec[1]) / Decimal::TWO;
         }
     }
 
@@ -481,6 +481,11 @@ impl AvellanedaStoikov {
             let smb = self.depth_vec[1].bids[0].price;
             smm = (sma + smb) / Decimal::TWO;
         }
+        let short_len = Decimal::from_usize(self.trade_short_vec.len()).unwrap();
+        let long_len = Decimal::from_usize(self.trade_long_vec.len()).unwrap();
+        let mut rate = short_len / long_len;
+        rate.rescale(4);
+
         cci.predictor_state_vec.push_back(PredictorState {
             update_time: Decimal::from_i64(Utc::now().timestamp_millis()).unwrap(),
 
@@ -495,9 +500,9 @@ impl AvellanedaStoikov {
             optimal_bid_price: self.optimal_bid_price,
 
             inventory: self.inventory,
-            sigma_square: self.sigma_square,
-            gamma: self.money_flow_index,
-            kappa: self.flow_ratio,
+            sigma_square: rate,
+            gamma: short_len,
+            kappa: long_len,
 
             flow_ratio: Decimal::ZERO,
             ref_price: self.ref_price,

+ 1 - 1
strategy/src/strategy.rs

@@ -1109,7 +1109,7 @@ impl Strategy {
         self.fix_price(predictor);
 
         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