|
|
@@ -36,8 +36,8 @@ pub struct Predictor {
|
|
|
pub bid_price: Decimal, // 中间价
|
|
|
pub fair_price: Decimal,
|
|
|
pub last_price: Decimal, // 最后成交价
|
|
|
- pub ma_30: Decimal,
|
|
|
- pub ma_500: Decimal,
|
|
|
+ pub ma_short: Decimal,
|
|
|
+ pub ma_long: Decimal,
|
|
|
pub trend_rate: Decimal,
|
|
|
|
|
|
pub optimal_ask_price: Decimal, // 卖出挂单价
|
|
|
@@ -172,8 +172,8 @@ impl Predictor {
|
|
|
fair_price: Default::default(),
|
|
|
last_price: Default::default(),
|
|
|
|
|
|
- ma_30: Default::default(),
|
|
|
- ma_500: Default::default(),
|
|
|
+ ma_short: Default::default(),
|
|
|
+ ma_long: Default::default(),
|
|
|
trend_rate: Default::default(),
|
|
|
|
|
|
optimal_ask_price: Self::DONT_VIEW,
|
|
|
@@ -327,12 +327,12 @@ impl Predictor {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if self.record_vec.len() > 500 {
|
|
|
+ if self.record_vec.len() > 50 {
|
|
|
self.record_vec.pop_front();
|
|
|
}
|
|
|
|
|
|
- // 计算ma30与ma500
|
|
|
- if self.record_vec.len() == 500 && !self.mid_price.is_zero() {
|
|
|
+ // 计算ma
|
|
|
+ if self.record_vec.len() == 50 && !self.mid_price.is_zero() {
|
|
|
let len = self.record_vec.len();
|
|
|
// ma200
|
|
|
let mut i = len - 1;
|
|
|
@@ -346,12 +346,12 @@ impl Predictor {
|
|
|
|
|
|
i = i - 1;
|
|
|
}
|
|
|
- self.ma_500 = sum / Decimal::from(500);
|
|
|
- // ma30
|
|
|
+ self.ma_long = sum / Decimal::from(self.record_vec.len());
|
|
|
+ // ma20
|
|
|
let mut i = len - 1;
|
|
|
let mut sum: Decimal = Decimal::ZERO;
|
|
|
loop {
|
|
|
- if i == len - 31 {
|
|
|
+ if i == len - 21 {
|
|
|
break
|
|
|
}
|
|
|
|
|
|
@@ -359,12 +359,12 @@ impl Predictor {
|
|
|
|
|
|
i = i - 1;
|
|
|
}
|
|
|
- self.ma_30 = sum / Decimal::from(30);
|
|
|
+ self.ma_short = sum / Decimal::from(20);
|
|
|
|
|
|
- self.ma_30.rescale(self.mid_price.scale());
|
|
|
- self.ma_500.rescale(self.mid_price.scale());
|
|
|
+ self.ma_short.rescale(self.mid_price.scale());
|
|
|
+ self.ma_long.rescale(self.mid_price.scale());
|
|
|
|
|
|
- self.trend_rate = self.ma_30 / self.ma_500;
|
|
|
+ self.trend_rate = self.ma_short / self.ma_long;
|
|
|
self.trend_rate.rescale(8);
|
|
|
}
|
|
|
}
|
|
|
@@ -510,10 +510,12 @@ impl Predictor {
|
|
|
|| (self.profit > dec!(0.01) && self.profit < self.profit_high * dec!(0.75))
|
|
|
);
|
|
|
|
|
|
- let last_record = &self.record_vec[self.record_vec.len() - 2];
|
|
|
let is_open_long = self.inventory.is_zero()
|
|
|
- && last_record.close / last_record.open < (Decimal::ONE - dec!(0.005))
|
|
|
- && self.trend_rate < self.params.open
|
|
|
+ && self.fair_price > self.mid_price * (Decimal::ONE + self.params.open)
|
|
|
+ && self.trend_long_rate < dec!(-0.005)
|
|
|
+ && self.fair_rate > Decimal::ZERO
|
|
|
+ && self.fair_rate > self.trend_short_rate + dec!(0.0001)
|
|
|
+ && self.trend_rate < dec!(0.985)
|
|
|
;
|
|
|
let is_open_short = self.inventory.is_zero()
|
|
|
&& false
|
|
|
@@ -535,9 +537,9 @@ impl Predictor {
|
|
|
self.trade_condition_time = now;
|
|
|
}
|
|
|
|
|
|
- // 开仓信号要过期,只保留60秒
|
|
|
+ // 开仓信号要过期,只保留2秒
|
|
|
if (self.trade_condition == dec!(3) || self.trade_condition == dec!(4))
|
|
|
- && now - self.trade_condition_time > dec!(60_000) {
|
|
|
+ && now - self.trade_condition_time > dec!(2_000) {
|
|
|
self.trade_condition = Decimal::ZERO;
|
|
|
}
|
|
|
|
|
|
@@ -604,11 +606,11 @@ impl Predictor {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if self.ma_500.is_zero() {
|
|
|
+ if self.ma_long.is_zero() {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if self.ma_30.is_zero() {
|
|
|
+ if self.ma_short.is_zero() {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -703,8 +705,8 @@ impl Predictor {
|
|
|
let fair_price = self.fair_price;
|
|
|
|
|
|
let spread = self.mid_price;
|
|
|
- let spread_max = self.ma_30;
|
|
|
- let spread_min = self.ma_500;
|
|
|
+ let spread_max = self.ma_short;
|
|
|
+ let spread_min = self.ma_long;
|
|
|
// let spread = self.price_times_avg;
|
|
|
// let spread_max = self.fair_price_vec[1] / self.fair_price_vec[0];
|
|
|
// let spread_min = self.fair_price / self.mid_price;
|