|
|
@@ -37,7 +37,7 @@ pub struct Predictor {
|
|
|
pub fair_price: Decimal,
|
|
|
pub last_price: Decimal, // 最后成交价
|
|
|
pub ma_30: Decimal,
|
|
|
- pub ma_200: Decimal,
|
|
|
+ pub ma_500: Decimal,
|
|
|
pub trend_rate: Decimal,
|
|
|
|
|
|
pub optimal_ask_price: Decimal, // 卖出挂单价
|
|
|
@@ -173,7 +173,7 @@ impl Predictor {
|
|
|
last_price: Default::default(),
|
|
|
|
|
|
ma_30: Default::default(),
|
|
|
- ma_200: Default::default(),
|
|
|
+ ma_500: Default::default(),
|
|
|
trend_rate: Default::default(),
|
|
|
|
|
|
optimal_ask_price: Self::DONT_VIEW,
|
|
|
@@ -327,12 +327,12 @@ impl Predictor {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if self.record_vec.len() > 200 {
|
|
|
+ if self.record_vec.len() > 500 {
|
|
|
self.record_vec.pop_front();
|
|
|
}
|
|
|
|
|
|
- // 计算ma30与ma200
|
|
|
- if self.record_vec.len() == 200 {
|
|
|
+ // 计算ma30与ma500
|
|
|
+ if self.record_vec.len() == 500 && !self.mid_price.is_zero() {
|
|
|
let len = self.record_vec.len();
|
|
|
// ma200
|
|
|
let mut i = len - 1;
|
|
|
@@ -346,7 +346,7 @@ impl Predictor {
|
|
|
|
|
|
i = i - 1;
|
|
|
}
|
|
|
- self.ma_200 = sum / Decimal::from(200);
|
|
|
+ self.ma_500 = sum / Decimal::from(500);
|
|
|
// ma30
|
|
|
let mut i = len - 1;
|
|
|
let mut sum: Decimal = Decimal::ZERO;
|
|
|
@@ -362,9 +362,9 @@ impl Predictor {
|
|
|
self.ma_30 = sum / Decimal::from(30);
|
|
|
|
|
|
self.ma_30.rescale(self.mid_price.scale());
|
|
|
- self.ma_200.rescale(self.mid_price.scale());
|
|
|
+ self.ma_500.rescale(self.mid_price.scale());
|
|
|
|
|
|
- self.trend_rate = self.ma_30 / self.ma_200;
|
|
|
+ self.trend_rate = self.ma_30 / self.ma_500;
|
|
|
self.trend_rate.rescale(8);
|
|
|
}
|
|
|
}
|
|
|
@@ -604,6 +604,14 @@ impl Predictor {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ if self.ma_500.is_zero() {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.ma_30.is_zero() {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if self.record_vec.len() < 200 {
|
|
|
return;
|
|
|
}
|
|
|
@@ -696,7 +704,7 @@ impl Predictor {
|
|
|
|
|
|
let spread = self.mid_price;
|
|
|
let spread_max = self.ma_30;
|
|
|
- let spread_min = self.ma_200;
|
|
|
+ let spread_min = self.ma_500;
|
|
|
// 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;
|