Răsfoiți Sursa

試試這一版的多周期共振。

skyfffire 1 an în urmă
părinte
comite
e85e062813
1 a modificat fișierele cu 26 adăugiri și 8 ștergeri
  1. 26 8
      strategy/src/avellaneda_stoikov.rs

+ 26 - 8
strategy/src/avellaneda_stoikov.rs

@@ -56,8 +56,8 @@ pub struct AvellanedaStoikov {
 impl AvellanedaStoikov {
     // 时间窗口大小(微秒)
     const MAX_TIME_RANGE_MICROS: i64 = 5 * 60_000_000;
-    const TRADE_LONG_RANGE_MICROS: i64 = 60_000_000;
-    const TRADE_SHORT_RANGE_MICROS: i64 = 10_000_000;
+    const TRADE_LONG_RANGE_MICROS: i64 = 30_000_000;
+    const TRADE_SHORT_RANGE_MICROS: i64 = 6_000_000;
     // const ONE_MILLION: Decimal = dec!(1_000_000);
     // const TWENTY_THOUSAND: Decimal = dec!(20_000);
     const IRA: Decimal = dec!(1);
@@ -294,12 +294,30 @@ impl AvellanedaStoikov {
 
         let mut flow_in_value = Decimal::ZERO;
         let mut flow_out_value = Decimal::ZERO;
-        for trade_iter in trades.deque.iter() {
-            if trade_iter.size > Decimal::ZERO {
-                flow_in_value += trade_iter.value;
+        for (index, trade_iter) in trades.deque.iter().enumerate() {
+            if index == 0 {
+                continue
+            }
+
+            let prev_trade_iter = trades.deque.get(index - 1).unwrap();
+            let trade = trade_iter;
+            if trade.price > prev_trade_iter.price {
+                flow_in_value += trade.value;
+            } else if trade.price < prev_trade_iter.price {
+                flow_out_value += trade.value;
             } else {
-                flow_out_value += trade_iter.value;
+                // if trade.size > Decimal::ZERO {
+                //     self.flow_in_value += trade.value;
+                // } else {
+                //     self.flow_out_value += trade.value;
+                // }
             }
+
+            // if trade_iter.size > Decimal::ZERO {
+            //     flow_in_value += trade_iter.value;
+            // } else {
+            //     flow_out_value += trade_iter.value;
+            // }
         }
 
         if flow_out_value + flow_in_value > *min_volume {
@@ -354,8 +372,8 @@ impl AvellanedaStoikov {
     }
 
     pub fn update_flow_ratio(&mut self) {
-        self.flow_ratio_long = Self::calc_flow_ratio(&self.flow_ratio_long, &dec!(300_000), &mut self.trade_long_vec);
-        self.flow_ratio_short = Self::calc_flow_ratio(&self.flow_ratio_short, &dec!(100_000), &mut self.trade_short_vec);
+        self.flow_ratio_long = Self::calc_flow_ratio(&self.flow_ratio_long, &dec!(30_000), &mut self.trade_long_vec);
+        self.flow_ratio_short = Self::calc_flow_ratio(&self.flow_ratio_short, &dec!(10_000), &mut self.trade_short_vec);
     }
 
     pub fn check_ready(&mut self) {