|
@@ -64,7 +64,7 @@ impl AvellanedaStoikov {
|
|
|
const MAX_TIME_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
const MAX_TIME_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
|
const TRADE_LONG_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
const TRADE_LONG_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
|
// const SPREAD_RANGE_MICROS: i64 = 15 * 60_000_000;
|
|
// const SPREAD_RANGE_MICROS: i64 = 15 * 60_000_000;
|
|
|
- const TRADE_SHORT_RANGE_MICROS: i64 = 60_000_000;
|
|
|
|
|
|
|
+ const TRADE_SHORT_RANGE_MICROS: i64 = 30_000_000;
|
|
|
// const ONE_MILLION: Decimal = dec!(1_000_000);
|
|
// const ONE_MILLION: Decimal = dec!(1_000_000);
|
|
|
// const TWENTY_THOUSAND: Decimal = dec!(20_000);
|
|
// const TWENTY_THOUSAND: Decimal = dec!(20_000);
|
|
|
const IRA: Decimal = dec!(1);
|
|
const IRA: Decimal = dec!(1);
|
|
@@ -329,19 +329,19 @@ impl AvellanedaStoikov {
|
|
|
|
|
|
|
|
pub fn update_ref_price(&mut self) {
|
|
pub fn update_ref_price(&mut self) {
|
|
|
if !self.fair_price_vec[0].is_zero() && !self.fair_price_vec[1].is_zero() {
|
|
if !self.fair_price_vec[0].is_zero() && !self.fair_price_vec[1].is_zero() {
|
|
|
- // let v0_rate = self.volume_vec[0] / (self.volume_vec[0] + self.volume_vec[1]);
|
|
|
|
|
- // let v1_rate = self.volume_vec[1] / (self.volume_vec[0] + self.volume_vec[1]);
|
|
|
|
|
|
|
+ let v0_rate = self.volume_vec[0] / (self.volume_vec[0] + self.volume_vec[1]);
|
|
|
|
|
+ let v1_rate = self.volume_vec[1] / (self.volume_vec[0] + self.volume_vec[1]);
|
|
|
|
|
|
|
|
- // let sma = self.depth_vec[1].asks[0].price;
|
|
|
|
|
- // let smb = self.depth_vec[1].bids[0].price;
|
|
|
|
|
|
|
+ let sma = self.depth_vec[1].asks[0].price;
|
|
|
|
|
+ let smb = self.depth_vec[1].bids[0].price;
|
|
|
|
|
|
|
|
- // let mp0 = self.mid_price;
|
|
|
|
|
- // let mp1 = (sma + smb) / Decimal::TWO;
|
|
|
|
|
|
|
+ let mp0 = self.mid_price;
|
|
|
|
|
+ let mp1 = (sma + smb) / Decimal::TWO;
|
|
|
|
|
|
|
|
- // let price_diff = mp0 - mp1;
|
|
|
|
|
|
|
+ let price_diff = mp0 - mp1;
|
|
|
|
|
|
|
|
- // self.ref_price = (self.fair_price_vec[0] + self.fair_price_vec[1] + price_diff) / Decimal::TWO;
|
|
|
|
|
- self.ref_price = (self.fair_price_vec[0] + self.fair_price_vec[1]) / Decimal::TWO;
|
|
|
|
|
|
|
+ self.ref_price = (self.fair_price_vec[0] + self.fair_price_vec[1] + price_diff) / Decimal::TWO;
|
|
|
|
|
+ // self.ref_price = (self.fair_price_vec[0] + self.fair_price_vec[1]) / Decimal::TWO;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -481,6 +481,11 @@ impl AvellanedaStoikov {
|
|
|
let smb = self.depth_vec[1].bids[0].price;
|
|
let smb = self.depth_vec[1].bids[0].price;
|
|
|
smm = (sma + smb) / Decimal::TWO;
|
|
smm = (sma + smb) / Decimal::TWO;
|
|
|
}
|
|
}
|
|
|
|
|
+ let short_len = Decimal::from_usize(self.trade_short_vec.len()).unwrap();
|
|
|
|
|
+ let long_len = Decimal::from_usize(self.trade_long_vec.len()).unwrap();
|
|
|
|
|
+ let mut rate = short_len / long_len;
|
|
|
|
|
+ rate.rescale(4);
|
|
|
|
|
+
|
|
|
cci.predictor_state_vec.push_back(PredictorState {
|
|
cci.predictor_state_vec.push_back(PredictorState {
|
|
|
update_time: Decimal::from_i64(Utc::now().timestamp_millis()).unwrap(),
|
|
update_time: Decimal::from_i64(Utc::now().timestamp_millis()).unwrap(),
|
|
|
|
|
|
|
@@ -495,9 +500,9 @@ impl AvellanedaStoikov {
|
|
|
optimal_bid_price: self.optimal_bid_price,
|
|
optimal_bid_price: self.optimal_bid_price,
|
|
|
|
|
|
|
|
inventory: self.inventory,
|
|
inventory: self.inventory,
|
|
|
- sigma_square: self.sigma_square,
|
|
|
|
|
- gamma: self.money_flow_index,
|
|
|
|
|
- kappa: self.flow_ratio,
|
|
|
|
|
|
|
+ sigma_square: rate,
|
|
|
|
|
+ gamma: short_len,
|
|
|
|
|
+ kappa: long_len,
|
|
|
|
|
|
|
|
flow_ratio: Decimal::ZERO,
|
|
flow_ratio: Decimal::ZERO,
|
|
|
ref_price: self.ref_price,
|
|
ref_price: self.ref_price,
|