Fix calculation of amplitude
This commit is contained in:
parent
bd24ffe455
commit
b95a194e84
|
|
@ -176,30 +176,26 @@ pub async fn list_up_for_sell(
|
|||
.rt_price_1d_vec
|
||||
.get(&element.symbol)
|
||||
{
|
||||
if let Some(partial_price_vec) = price_1d_vec.get(price_1d_vec.len()-opclo_sample_length+1..price_1d_vec.len()-1) {
|
||||
let vec_len = price_1d_vec.len();
|
||||
if let Some(candles) = price_1d_vec.get(vec_len-opclo_sample_length-2..vec_len-1) {
|
||||
let windows = candles.windows(2);
|
||||
let mut sum_amplitude_candles = 0.0;
|
||||
let mut sum_ratio_amp_body = 0.0;
|
||||
for element in price_1d_vec {
|
||||
sum_amplitude_candles +=
|
||||
((element.high_price / element.low_price) - 1.0) * 100.0;
|
||||
sum_ratio_amp_body += (element.close_price - element.open_price).abs()
|
||||
/ (element.high_price - element.low_price);
|
||||
let mut average_amplitude = 0.0;
|
||||
|
||||
for window in windows {
|
||||
sum_amplitude_candles += ((window.last().unwrap().high_price - window.last().unwrap().low_price) * 100.0) / window.first().unwrap().close_price;
|
||||
}
|
||||
let average_amplitude = sum_amplitude_candles / opclo_sample_length as f64; // percent unit
|
||||
let average_ratio_amp_body = sum_ratio_amp_body / opclo_sample_length as f64;
|
||||
|
||||
let mut amplitude_variance = 0.0;
|
||||
for element in price_1d_vec {
|
||||
amplitude_variance += ((((element.high_price / element.low_price) - 1.0)
|
||||
* 100.0)
|
||||
- average_amplitude)
|
||||
.powi(2);
|
||||
|
||||
let windows = candles.windows(2);
|
||||
for window in windows {
|
||||
amplitude_variance += ((((window.last().unwrap().high_price - window.last().unwrap().low_price) * 100.0) / window.first().unwrap().close_price) - average_amplitude).powi(2);;
|
||||
}
|
||||
amplitude_variance = amplitude_variance / (opclo_sample_length - 1) as f64;
|
||||
let standard_deviation_amplitude = amplitude_variance.sqrt();
|
||||
|
||||
// let target_profit_percent = average_amplitude + (standard_deviation_amplitude * (average_ratio_amp_body));
|
||||
target_profit_percent = (average_amplitude - standard_deviation_amplitude);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user