fix: Properly implement small spike

Closes #8
master
Mike Bryant 4 years ago
parent 840f684dee
commit 4ab53128f0

@ -452,29 +452,53 @@ function* generate_pattern_3_with_peak(given_prices, peak_start) {
}); });
} }
// TODO this could be made more accurate, I've not bothered with forward/backward calculating of the rate each side of the peak value // Main spike 1
for (var i = peak_start+2; i < peak_start+5; i++) { min_pred = Math.floor(1.4 * buy_price) - 1;
if (i == peak_start+3) { max_pred = Math.ceil(2.0 * buy_price) - 1;
min_pred = predicted_prices[peak_start+2].min; if (!isNaN(given_prices[peak_start+2])) {
max_pred = Math.ceil(2.0 * buy_price); if (given_prices[peak_start+2] < min_pred || given_prices[peak_start+2] > max_pred ) {
} else { // Given price is out of predicted range, so this is the wrong pattern
min_pred = Math.floor(1.4 * buy_price) - 1; return;
max_pred = Math.ceil(2.0 * buy_price) - 1;
} }
if (!isNaN(given_prices[i])) { min_pred = given_prices[peak_start+2];
if (given_prices[i] < min_pred || given_prices[i] > max_pred ) { max_pred = given_prices[peak_start+2];
// Given price is out of predicted range, so this is the wrong pattern }
return; predicted_prices.push({
} min: min_pred,
min_pred = given_prices[i]; max: max_pred,
max_pred = given_prices[i]; });
// Main spike 2
min_pred = predicted_prices[peak_start+2].min;
max_pred = Math.ceil(2.0 * buy_price);
if (!isNaN(given_prices[peak_start+3])) {
if (given_prices[peak_start+3] < min_pred || given_prices[peak_start+3] > max_pred ) {
// Given price is out of predicted range, so this is the wrong pattern
return;
} }
min_pred = given_prices[peak_start+3];
max_pred = given_prices[peak_start+3];
}
predicted_prices.push({
min: min_pred,
max: max_pred,
});
predicted_prices.push({ // Main spike 3
min: min_pred, min_pred = Math.floor(1.4 * buy_price) - 1;
max: max_pred, max_pred = predicted_prices[peak_start+3].max - 1;
}); if (!isNaN(given_prices[peak_start+4])) {
if (given_prices[peak_start+4] < min_pred || given_prices[peak_start+4] > max_pred ) {
// Given price is out of predicted range, so this is the wrong pattern
return;
}
min_pred = given_prices[peak_start+4];
max_pred = given_prices[peak_start+4];
} }
predicted_prices.push({
min: min_pred,
max: max_pred,
});
if (peak_start+5 < 14) { if (peak_start+5 < 14) {
var min_rate = 4000; var min_rate = 4000;

Loading…
Cancel
Save