|
|
@@ -19,9 +19,8 @@ pub struct Predictor {
|
|
|
pub depth_vec: Vec<Depth>, // 深度队列
|
|
|
pub record_vec: VecDeque<Record>, // 蜡烛队列
|
|
|
pub spread_vec: VecDeque<Decimal>, // 价差队列
|
|
|
- pub trade_price_long_vec: FixedTimeRangeDeque<Decimal>,
|
|
|
- pub trade_233_vec: FixedTimeRangeDeque<Trade>,
|
|
|
- pub trade_0_vec: FixedTimeRangeDeque<Trade>,
|
|
|
+ pub trade_price_short_vec: FixedTimeRangeDeque<Decimal>,
|
|
|
+ pub trend_rate: Decimal,
|
|
|
|
|
|
pub prices: Vec<Vec<VecDeque<Decimal>>>, // [[[做市所], [参考所0]], ...]
|
|
|
pub ks: Vec<Decimal>,
|
|
|
@@ -68,9 +67,9 @@ impl Predictor {
|
|
|
// 时间窗口大小(微秒)
|
|
|
// const MAX_TIME_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
|
// const TIME_DIFF_RANGE_MICROS: i64 = 15 * 60_000_000;
|
|
|
- const TRADE_LONG_RANGE_MICROS: i64 = 10 * 60_000_000;
|
|
|
+ // const TRADE_LONG_RANGE_MICROS: i64 = 10 * 60_000_000;
|
|
|
// const SPREAD_RANGE_MICROS: i64 = 15 * 60_000_000;
|
|
|
- const TRADE_SHORT_RANGE_MICROS: i64 = 2 * 60_000_000;
|
|
|
+ const TRADE_SHORT_RANGE_MICROS: i64 = 10_000_000;
|
|
|
// const ONE_MILLION: Decimal = dec!(1_000_000);
|
|
|
// const TWENTY_THOUSAND: Decimal = dec!(20_000);
|
|
|
const DONT_VIEW: Decimal = dec!(14142135623730951);
|
|
|
@@ -148,9 +147,7 @@ impl Predictor {
|
|
|
|
|
|
record_vec: VecDeque::new(),
|
|
|
|
|
|
- trade_price_long_vec: FixedTimeRangeDeque::new(Self::TRADE_LONG_RANGE_MICROS),
|
|
|
- trade_233_vec: FixedTimeRangeDeque::new(Self::TRADE_SHORT_RANGE_MICROS),
|
|
|
- trade_0_vec: FixedTimeRangeDeque::new(Self::TRADE_SHORT_RANGE_MICROS),
|
|
|
+ trade_price_short_vec: FixedTimeRangeDeque::new(Self::TRADE_SHORT_RANGE_MICROS),
|
|
|
spread_vec: VecDeque::new(),
|
|
|
mid_price: Default::default(),
|
|
|
fair_price: Default::default(),
|
|
|
@@ -180,6 +177,7 @@ impl Predictor {
|
|
|
params,
|
|
|
|
|
|
debug_sender: tx,
|
|
|
+ trend_rate: Default::default(),
|
|
|
};
|
|
|
|
|
|
predictor
|
|
|
@@ -247,19 +245,18 @@ impl Predictor {
|
|
|
|
|
|
self.last_price = trade.price;
|
|
|
|
|
|
- // self.trade_price_long_vec.push_back(trade.price);
|
|
|
-
|
|
|
if index == 233 {
|
|
|
- self.trade_233_vec.push_back(trade.clone());
|
|
|
- } else {
|
|
|
- // if trade.value > Decimal::ONE_HUNDRED {
|
|
|
- // self.update_fair_price(&trade.price, index).await;
|
|
|
- // self.processor(trade.time, false).await;
|
|
|
- // }
|
|
|
+ self.trade_price_short_vec.push_back(trade.price);
|
|
|
|
|
|
- // if index == 0 {
|
|
|
- // self.trade_0_vec.push_back(trade.clone());
|
|
|
- // }
|
|
|
+ self.trend_rate = if self.trade_price_short_vec.len() > 2 {
|
|
|
+ let last = self.trade_price_short_vec.deque.back().unwrap();
|
|
|
+ let first = self.trade_price_short_vec.deque.front().unwrap();
|
|
|
+
|
|
|
+ (last - first) / first - Decimal::ONE
|
|
|
+ } else {
|
|
|
+ Decimal::ZERO
|
|
|
+ };
|
|
|
+ self.trend_rate.rescale(6);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -377,17 +374,17 @@ impl Predictor {
|
|
|
self.optimal_bid_price = max(self.mid_price, self.fair_price);
|
|
|
self.optimal_ask_price = Self::DONT_VIEW;
|
|
|
} else if self.inventory.is_zero() {
|
|
|
- if self.fair_price > self.mid_price * (Decimal::ONE + self.params.open) {
|
|
|
+ if self.fair_price > self.mid_price * (Decimal::ONE + self.params.open) && self.trend_rate < self.params.open * dec!(-5) {
|
|
|
self.bid_delta = dec!(0);
|
|
|
self.ask_delta = dec!(-2);
|
|
|
|
|
|
- self.optimal_bid_price = self.mid_price;
|
|
|
+ self.optimal_bid_price = self.mid_price * dec!(1.001);
|
|
|
self.optimal_ask_price = Self::DONT_VIEW;
|
|
|
- } else if self.fair_price < self.mid_price * (Decimal::ONE - self.params.open) {
|
|
|
+ } else if self.fair_price < self.mid_price * (Decimal::ONE - self.params.open) && self.trend_rate > self.params.open * dec!(5) {
|
|
|
self.ask_delta = dec!(0);
|
|
|
self.bid_delta = dec!(-2);
|
|
|
|
|
|
- self.optimal_ask_price = self.mid_price;
|
|
|
+ self.optimal_ask_price = self.mid_price * dec!(0.999);
|
|
|
self.optimal_bid_price = Self::DONT_VIEW;
|
|
|
}
|
|
|
}
|
|
|
@@ -513,7 +510,7 @@ impl Predictor {
|
|
|
let sigma_square = Decimal::from(Utc::now().timestamp_millis()) - data_time;
|
|
|
|
|
|
let gamma = self.balance;
|
|
|
- let kappa = self.params.open;
|
|
|
+ let kappa = self.trend_rate;
|
|
|
|
|
|
let flow_ratio = Decimal::ZERO;
|
|
|
|