فهرست منبع

不必要的变量整理

skyffire 10 ماه پیش
والد
کامیت
ba456d2eca
1فایلهای تغییر یافته به همراه15 افزوده شده و 21 حذف شده
  1. 15 21
      strategy/src/predictor.rs

+ 15 - 21
strategy/src/predictor.rs

@@ -21,7 +21,6 @@ pub struct Predictor {
     pub trade_long_vec: FixedTimeRangeDeque<Trade>,                             // 交易队列
     pub trade_short_vec: FixedTimeRangeDeque<Trade>,                            // 交易队列
     pub trade_fixed_vec: Vec<Trade>,                                            // 交易队列(观察持仓后的资金流)
-    pub profit_fixed_vec: Vec<Decimal>,                                         // 利润队列
     pub spread_vec: Vec<Decimal>,                                               // 价差队列
     pub record_vec: VecDeque<Record>,                                           // 蜡烛队列
 
@@ -37,36 +36,35 @@ pub struct Predictor {
     pub optimal_ask_price: Decimal,                                             // 卖出挂单价
     pub optimal_bid_price: Decimal,                                             // 买入挂单价
 
+    pub profit_point: Decimal,                                                  // 利润点数
+    pub profit_point_ema: Decimal,                                              // 利润点数的ema
+    pub profit_fixed_vec: Vec<Decimal>,                                         // 利润队列
+
     pub inventory: Decimal,                                                     // 库存,也就是q
     pub pos_amount: Decimal,                                                    // 原始持仓量
     pub pos_avg_price: Decimal,                                                 // 原始持仓价格
     pub level: Decimal,                                                         // martin
 
-    pub error_rate: Decimal,                                                    // 犯错概率(预估)
-    pub profit_point: Decimal,                                                  // 利润点数
-    pub profit_point_ema: Decimal,                                              // 利润点数的ema
+    pub money_flow: Decimal,                                                    // 资金流
 
     pub ask_delta: Decimal,                                                     // δa
     pub bid_delta: Decimal,                                                     // δb
 
-    pub mid_price_time_vec: FixedTimeRangeDeque<Decimal>,                       // 中间价格队列,100ms以内的所有中间价格
-    pub fair_price_time_vec: FixedTimeRangeDeque<Decimal>,                      // 公平价格队列,10ms以内的所有公平价格
-    pub fair_price_long_time_vec: FixedTimeRangeDeque<Decimal>,                 // 公平价格队列,10ms以内的所有公平价格
-    pub spread_sma_1000_time_vec: FixedTimeRangeDeque<Decimal>,                 // spread队列,10ms以内的所有spread_sma_1000
+    pub mid_price_time_vec: FixedTimeRangeDeque<Decimal>,                       // 中间价格队列,
+    pub fair_price_time_vec: FixedTimeRangeDeque<Decimal>,                      // 公平价格队列,
+    pub fair_price_long_time_vec: FixedTimeRangeDeque<Decimal>,                 //
     pub fair_price_vec: Vec<Decimal>,                                           // 公平价格列表,0表示做市所,1表示参考所
     pub fair_price: Decimal,                                                    // 公平价格
     pub fair_price_ema_short: Decimal,                                          // 公平价格_ema
     pub fair_price_ema_long: Decimal,                                           // 公平价格_ema
     pub fair_rate_focus_open: Decimal,                                          // 变化幅度焦点
-    pub mid_price_focus_open: Decimal,                                         // 观测焦点时的价格
+    pub mid_price_focus_open: Decimal,                                          // 观测焦点时的价格
     pub fair_rate_focus_close: Decimal,                                         // 变化幅度焦点
     pub fair_price_focus_close: Decimal,                                        // 观测焦点时的价格
     pub fair_price_when_ordering: Decimal,                                      // 下单时的公平价格
     pub price_times_avg: Decimal,                                               // 公平所与做市所的价格倍率的平均值
-    pub is_regressed: bool,                                                     // 做市所的价格是否已经回归
 
     pub is_ready: bool,                                                         // 是否已准备好
-    pub close_price: Decimal,                                                   // 计划平仓价格
 
     pub prev_trade_time: i64,                                                   // 上次交易时间,也就是t
     pub t_diff: Decimal,                                                        // (T-t)
@@ -167,7 +165,6 @@ impl Predictor {
             ask_delta: Default::default(),
             bid_delta: Default::default(),
 
-            spread_sma_1000_time_vec: FixedTimeRangeDeque::new(10_000),
             fair_price_time_vec: FixedTimeRangeDeque::new((params.second_observation_time.to_f64().unwrap() * 1_000_000f64).to_i64().unwrap()),
             fair_price_long_time_vec: FixedTimeRangeDeque::new(5 * 60_000_000),
             mid_price_time_vec: FixedTimeRangeDeque::new(100_000),
@@ -181,15 +178,13 @@ impl Predictor {
             fair_price_when_ordering: Default::default(),
 
             price_times_avg: Default::default(),
-            is_regressed: false,
 
             is_ready: false,
             prev_trade_time: Utc::now().timestamp_micros(),
-            close_price: Default::default(),
             t_diff: Default::default(),
             level: Default::default(),
             pos_amount: Default::default(),
-            error_rate: Default::default(),
+            money_flow: Default::default(),
             profit_point: Default::default(),
             profit_point_ema: Default::default(),
             last_update_time: Default::default(),
@@ -226,7 +221,7 @@ impl Predictor {
                     (self.pos_avg_price - self.mid_price) / self.pos_avg_price
                 };
 
-                // self.profit_fixed_vec.push();
+                self.profit_fixed_vec.push(profit_now - dec!(0.001));
 
                 // let total: Decimal = self.profit_fixed_vec.iter().sum();
                 self.profit_point = profit_now;
@@ -262,8 +257,8 @@ impl Predictor {
                             (buy_sum, sell_sum)
                         }
                     });
-                self.error_rate = (bought_sum - sold_sum) / (bought_sum + sold_sum);
-                self.error_rate.rescale(4);
+                self.money_flow = (bought_sum - sold_sum) / (bought_sum + sold_sum);
+                self.money_flow.rescale(4);
             }
         }
 
@@ -301,7 +296,6 @@ impl Predictor {
 
         if prev_inventory != self.inventory && prev_inventory.is_zero() {
             self.prev_trade_time = Utc::now().timestamp_micros();
-            self.close_price = self.fair_price_when_ordering;
         }
 
         // 重置fair数据,用于重新计算幅度
@@ -316,7 +310,7 @@ impl Predictor {
             self.profit_point = Decimal::ZERO;
             self.profit_point_ema = Decimal::ZERO;
 
-            self.error_rate = Decimal::ZERO;
+            self.money_flow = Decimal::ZERO;
         }
 
         self.update_level().await;
@@ -534,8 +528,8 @@ impl Predictor {
         } else {
             self.spread_ema_1000 * dec!(0.999) + self.spread * dec!(0.001)
         };
-        self.spread_sma_1000_time_vec.push_back(self.spread_ema_1000);
         // self.spread_sma_1000.rescale(8);
+        // self.spread_sma_1000_time_vec.push_back(self.spread_ema_1000);
 
         while self.spread_vec.len() > 1_000 {
             self.spread_vec.remove(0);