|
@@ -30,6 +30,7 @@ pub struct Predictor {
|
|
|
pub inventory: Decimal, // 库存,也就是q
|
|
pub inventory: Decimal, // 库存,也就是q
|
|
|
pub pos_amount: Decimal, // 原始持仓量
|
|
pub pos_amount: Decimal, // 原始持仓量
|
|
|
pub pos_avg_price: Decimal, // 原始持仓价格
|
|
pub pos_avg_price: Decimal, // 原始持仓价格
|
|
|
|
|
+ pub balance: Decimal, // 初始余额
|
|
|
|
|
|
|
|
pub signal: Decimal, // 大于0代表此时是正向信号,小于0则相反
|
|
pub signal: Decimal, // 大于0代表此时是正向信号,小于0则相反
|
|
|
|
|
|
|
@@ -134,6 +135,7 @@ impl Predictor {
|
|
|
inventory: Default::default(),
|
|
inventory: Default::default(),
|
|
|
pos_avg_price: Default::default(),
|
|
pos_avg_price: Default::default(),
|
|
|
pos_amount: Default::default(),
|
|
pos_amount: Default::default(),
|
|
|
|
|
+ balance: Default::default(),
|
|
|
|
|
|
|
|
signal: Default::default(),
|
|
signal: Default::default(),
|
|
|
|
|
|
|
@@ -202,6 +204,10 @@ impl Predictor {
|
|
|
self.processor().await;
|
|
self.processor().await;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ pub async fn on_balance(&mut self, balance: Decimal) {
|
|
|
|
|
+ self.balance = balance;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
pub fn get_real_rate(price_vec: &FixedTimeRangeDeque<Decimal>) -> Decimal {
|
|
pub fn get_real_rate(price_vec: &FixedTimeRangeDeque<Decimal>) -> Decimal {
|
|
|
let last_fair_price = price_vec.deque.iter().last().unwrap();
|
|
let last_fair_price = price_vec.deque.iter().last().unwrap();
|
|
|
let min_price = price_vec.deque.iter().min().unwrap();
|
|
let min_price = price_vec.deque.iter().min().unwrap();
|
|
@@ -313,7 +319,7 @@ impl Predictor {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if self.mid_price == Decimal::ZERO {
|
|
|
|
|
|
|
+ if self.mid_price.is_zero() {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -323,11 +329,15 @@ impl Predictor {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if self.ask_price == Decimal::ZERO {
|
|
|
|
|
|
|
+ if self.ask_price.is_zero() {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if self.bid_price.is_zero() {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if self.bid_price == Decimal::ZERO {
|
|
|
|
|
|
|
+ if self.balance.is_zero() {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -344,14 +354,6 @@ impl Predictor {
|
|
|
|
|
|
|
|
self.update_delta();
|
|
self.update_delta();
|
|
|
|
|
|
|
|
- // let mut smm = Decimal::ZERO;
|
|
|
|
|
- // if !self.depth_vec[1].time.is_zero() {
|
|
|
|
|
- // let sma = self.depth_vec[1].asks[0].price;
|
|
|
|
|
- // let smb = self.depth_vec[1].bids[0].price;
|
|
|
|
|
- // smm = (sma + smb) / Decimal::TWO;
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
// let cci_arc = self.cci_arc.clone();
|
|
// let cci_arc = self.cci_arc.clone();
|
|
|
let now = Decimal::from_i64(Utc::now().timestamp_millis()).unwrap();
|
|
let now = Decimal::from_i64(Utc::now().timestamp_millis()).unwrap();
|
|
|
let mid_price = self.mid_price;
|
|
let mid_price = self.mid_price;
|
|
@@ -373,7 +375,7 @@ impl Predictor {
|
|
|
|
|
|
|
|
let sigma_square = self.signal;
|
|
let sigma_square = self.signal;
|
|
|
|
|
|
|
|
- let gamma = Decimal::ZERO;
|
|
|
|
|
|
|
+ let gamma = self.balance;
|
|
|
let kappa = Decimal::ZERO;
|
|
let kappa = Decimal::ZERO;
|
|
|
|
|
|
|
|
let flow_ratio = Decimal::ZERO;
|
|
let flow_ratio = Decimal::ZERO;
|