Selaa lähdekoodia

最后一点点,一次平完

skyfffire 1 vuosi sitten
vanhempi
commit
33ba8b1e86
2 muutettua tiedostoa jossa 7 lisäystä ja 2 poistoa
  1. 5 2
      strategy/src/avellaneda_stoikov.rs
  2. 2 0
      strategy/src/strategy.rs

+ 5 - 2
strategy/src/avellaneda_stoikov.rs

@@ -33,6 +33,7 @@ pub struct AvellanedaStoikov {
     pub optimal_bid_price: Decimal,                                             // 买入挂单价
 
     pub inventory: Decimal,                                                     // 库存,也就是q
+    pub pos_amount: Decimal,                                                    // 原始持仓量
     pub level: Decimal,                                                         // martin
     pub sigma_square: Decimal,                                                  // σ^2,波动性的平方
     pub gamma: Decimal,                                                         // γ,库存风险厌恶参数
@@ -107,6 +108,7 @@ impl AvellanedaStoikov {
             level: Default::default(),
             flow_ratio: Default::default(),
             money_flow_index: Default::default(),
+            pos_amount: Default::default(),
         };
 
         avellaneda_stoikov
@@ -273,9 +275,10 @@ impl AvellanedaStoikov {
         self.update_flow_ratio();
     }
 
-    pub async fn update_inventory(&mut self, inventory: &Decimal, min_amount_value: &Decimal) {
+    pub async fn update_inventory(&mut self, pos_amount: &Decimal, min_amount_value: &Decimal) {
         let prev_inventory = self.inventory;
-        self.inventory = (inventory / (min_amount_value / self.mid_price)).round();
+        self.pos_amount = pos_amount.clone();
+        self.inventory = (pos_amount / (min_amount_value / self.mid_price)).round();
         if prev_inventory != self.inventory {
             self.prev_trade_time = Utc::now().timestamp_micros();
         }

+ 2 - 0
strategy/src/strategy.rs

@@ -994,6 +994,8 @@ impl Strategy {
             target_sell_price = utils::fix_price(target_sell_price, self.tick_size);
             let amount = if predictor.inventory.abs() > dec!(10) && predictor.flow_ratio > Decimal::ZERO {
                 utils::get_amount_by_min_amount_value(self.min_amount_value * Decimal::TWO, target_sell_price, self.step_size)
+            } else if predictor.inventory.abs() == Decimal::ONE {
+                predictor.pos_amount
             } else {
                 utils::get_amount_by_min_amount_value(self.min_amount_value, target_sell_price, self.step_size)
             };