|
|
@@ -67,6 +67,7 @@ pub struct Predictor {
|
|
|
|
|
|
pub prev_insert_time: Decimal,
|
|
|
pub prev_save_time: Decimal,
|
|
|
+ pub init_time: Decimal,
|
|
|
|
|
|
pub params: Params,
|
|
|
|
|
|
@@ -79,8 +80,8 @@ pub struct Predictor {
|
|
|
impl Predictor {
|
|
|
// 时间窗口大小(微秒)
|
|
|
// const MAX_TIME_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
|
- const TIME_DIFF_RANGE_MICROS: i64 = 10 * 60_000_000;
|
|
|
- const TRADE_LONG_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
|
+ const TIME_DIFF_RANGE_MICROS: i64 = 15 * 60_000_000;
|
|
|
+ const TRADE_LONG_RANGE_MICROS: i64 = 60_000_000;
|
|
|
// const SPREAD_RANGE_MICROS: i64 = 15 * 60_000_000;
|
|
|
const TRADE_SHORT_RANGE_MICROS: i64 = 30_000_000;
|
|
|
// const ONE_MILLION: Decimal = dec!(1_000_000);
|
|
|
@@ -159,7 +160,7 @@ impl Predictor {
|
|
|
bid_delta: Default::default(),
|
|
|
|
|
|
spread_sma_1000_time_vec: FixedTimeRangeDeque::new(10_000),
|
|
|
- fair_price_time_vec: FixedTimeRangeDeque::new(10_000),
|
|
|
+ fair_price_time_vec: FixedTimeRangeDeque::new(10_000_000),
|
|
|
mid_price_time_vec: FixedTimeRangeDeque::new(100_000),
|
|
|
fair_price: Default::default(),
|
|
|
fair_rate_focus: Default::default(),
|
|
|
@@ -182,6 +183,7 @@ impl Predictor {
|
|
|
|
|
|
prev_insert_time: Default::default(),
|
|
|
prev_save_time: Decimal::from(Utc::now().timestamp_millis()),
|
|
|
+ init_time: Decimal::from(Utc::now().timestamp_millis()),
|
|
|
|
|
|
params,
|
|
|
|
|
|
@@ -342,7 +344,7 @@ impl Predictor {
|
|
|
}
|
|
|
|
|
|
// 更新程序关注的变化幅度焦点
|
|
|
- if self.fair_rate_focus.is_zero() {
|
|
|
+ if self.fair_rate_focus.is_zero() && self.inventory.is_zero() {
|
|
|
// 只有有强度的rate才有资格被称为针
|
|
|
if rate.abs() > self.params.open_activate {
|
|
|
// 向上涨,并且fair下穿mid,视为观测阶段开始
|
|
|
@@ -569,11 +571,11 @@ impl Predictor {
|
|
|
|
|
|
let inventory = self.inventory;
|
|
|
|
|
|
- let last_spread_sma = self.spread_sma_1000_time_vec.deque.iter().last().unwrap();
|
|
|
- let first_spread_sma = self.spread_sma_1000_time_vec.deque[0];
|
|
|
+ let last_fair_price = self.fair_price_time_vec.deque.iter().last().unwrap();
|
|
|
+ let first_fair_price = self.fair_price_time_vec.deque[0];
|
|
|
|
|
|
- let sigma_square = last_spread_sma - first_spread_sma;
|
|
|
- let gamma = now - self.last_update_time;
|
|
|
+ let sigma_square = (last_fair_price - first_fair_price) / first_fair_price;
|
|
|
+ let gamma = self.error_rate;
|
|
|
|
|
|
let kappa = self.fair_rate_focus;
|
|
|
|