|
|
|
@ -67,6 +67,10 @@ function* multiply_generator_probability(generator, probability) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clamp(x, min, max) {
|
|
|
|
|
return Math.min(Math.max(x, min), max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function range_length(range) {
|
|
|
|
|
return range[1] - range[0];
|
|
|
|
|
}
|
|
|
|
@ -115,13 +119,12 @@ function generate_individual_random_price(
|
|
|
|
|
// Given price is out of predicted range, so this is the wrong pattern
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (given_prices[i] >= min_pred && given_prices[i] <= max_pred) {
|
|
|
|
|
// The value in the FUDGE_FACTOR range is ignored so that it don't give a probability 0.
|
|
|
|
|
// TODO: How to deal with probability when there's fudge factor?
|
|
|
|
|
// Clamp the value to be in range now so the probability won't be totally biased to fudged values.
|
|
|
|
|
const real_rate_range =
|
|
|
|
|
rate_range_from_given_and_base(given_prices[i], buy_price);
|
|
|
|
|
rate_range_from_given_and_base(clamp(given_prices[i], min_pred, max_pred), buy_price);
|
|
|
|
|
prob *= range_intersect_length(rate_range, real_rate_range) /
|
|
|
|
|
range_length(rate_range);
|
|
|
|
|
}
|
|
|
|
|
min_pred = given_prices[i];
|
|
|
|
|
max_pred = given_prices[i];
|
|
|
|
|
}
|
|
|
|
@ -304,15 +307,14 @@ function generate_decreasing_random_price(
|
|
|
|
|
// Given price is out of predicted range, so this is the wrong pattern
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (given_prices[i] >= min_pred && given_prices[i] <= max_pred) {
|
|
|
|
|
// The value in the FUDGE_FACTOR range is ignored so that it don't give a probability 0.
|
|
|
|
|
// TODO: How to deal with probability when there's fudge factor?
|
|
|
|
|
// Clamp the value to be in range now so the probability won't be totally biased to fudged values.
|
|
|
|
|
const real_rate_range =
|
|
|
|
|
rate_range_from_given_and_base(given_prices[i], buy_price);
|
|
|
|
|
rate_range_from_given_and_base(clamp(given_prices[i], min_pred, max_pred), buy_price);
|
|
|
|
|
prob *= rate_pdf.range_limit(real_rate_range);
|
|
|
|
|
if (prob == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
min_pred = given_prices[i];
|
|
|
|
|
max_pred = given_prices[i];
|
|
|
|
|
}
|
|
|
|
@ -358,20 +360,18 @@ function generate_peak_price(
|
|
|
|
|
// Given price is out of predicted range, so this is the wrong pattern
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (middle_price >= min_pred && middle_price <= max_pred) {
|
|
|
|
|
// The value in the FUDGE_FACTOR range is ignored so that it don't give a probability 0.
|
|
|
|
|
// TODO: How to deal with probability when there's fudge factor?
|
|
|
|
|
// Clamp the value to be in range now so the probability won't be totally biased to fudged values.
|
|
|
|
|
const real_rate_range =
|
|
|
|
|
rate_range_from_given_and_base(middle_price, buy_price);
|
|
|
|
|
rate_range_from_given_and_base(clamp(middle_price, min_pred, max_pred), buy_price);
|
|
|
|
|
prob *= range_intersect_length(rate_range, real_rate_range) /
|
|
|
|
|
range_length(rate_range);
|
|
|
|
|
if (prob == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
console.log(prob);
|
|
|
|
|
|
|
|
|
|
rate_range = range_intersect(rate_range, real_rate_range);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const left_price = given_prices[start];
|
|
|
|
|
const right_price = given_prices[start + 2];
|
|
|
|
@ -399,9 +399,9 @@ function generate_peak_price(
|
|
|
|
|
// Given price is out of predicted range, so this is the wrong pattern
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (price >= min_pred && price <= max_pred) {
|
|
|
|
|
// The value in the FUDGE_FACTOR range is ignored so that it don't give a probability 0.
|
|
|
|
|
const rate2_range = rate_range_from_given_and_base(price + 1, buy_price);
|
|
|
|
|
// TODO: How to deal with probability when there's fudge factor?
|
|
|
|
|
// Clamp the value to be in range now so the probability won't be totally biased to fudged values.
|
|
|
|
|
const rate2_range = rate_range_from_given_and_base(clamp(price, min_pred, max_pred)+ 1, buy_price);
|
|
|
|
|
const F = (t, ZZ) => {
|
|
|
|
|
if (t <= 0) {
|
|
|
|
|
return 0;
|
|
|
|
@ -418,7 +418,6 @@ function generate_peak_price(
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// * Then generate the real predicted range.
|
|
|
|
|
// We're doing things in different order then how we calculate probability,
|
|
|
|
|