|
|
@@ -69,36 +69,16 @@ fn calc_volatility_div_price_diff(records: Value) -> Decimal {
|
|
|
return Decimal::ZERO
|
|
|
}
|
|
|
|
|
|
- // let first_record = records_array[records_array.len() - 1].clone();
|
|
|
- // let last_record = records_array[0].clone();
|
|
|
- // let open = Decimal::from_str(first_record["open"].as_str().unwrap().to_string().as_str()).unwrap();
|
|
|
- // let close = Decimal::from_str(last_record["close"].as_str().unwrap().to_string().as_str()).unwrap();
|
|
|
-
|
|
|
- // let price_diff = (Decimal::ONE_HUNDRED * (close - open) / open).abs();
|
|
|
let mut volatility = Decimal::ZERO;
|
|
|
- let mut up = Decimal::ZERO;
|
|
|
- let mut down = Decimal::ZERO;
|
|
|
for record in records_array {
|
|
|
let record_high = Decimal::from_str(record["high"].as_str().unwrap().to_string().as_str()).unwrap();
|
|
|
let record_low = Decimal::from_str(record["low"].as_str().unwrap().to_string().as_str()).unwrap();
|
|
|
- let record_open = Decimal::from_str(record["open"].as_str().unwrap().to_string().as_str()).unwrap();
|
|
|
- let record_close = Decimal::from_str(record["close"].as_str().unwrap().to_string().as_str()).unwrap();
|
|
|
let mid = (record_high + record_low) / Decimal::TWO;
|
|
|
|
|
|
volatility += Decimal::ONE_HUNDRED * (record_high - record_low) / mid;
|
|
|
- if record_close > record_open {
|
|
|
- up += Decimal::ONE
|
|
|
- } else if record_close < record_open {
|
|
|
- down += Decimal::ONE
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- let up_down_diff = (up - down).abs();
|
|
|
- let mut vdpd = if up_down_diff.is_zero() {
|
|
|
- Decimal::TWO * volatility
|
|
|
- } else {
|
|
|
- (Decimal::ONE / up_down_diff) * volatility
|
|
|
- };
|
|
|
+ let mut vdpd = volatility;
|
|
|
vdpd.rescale(6);
|
|
|
|
|
|
return vdpd;
|