Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ <h2 class="dialog-box__name" data-i18n="general.daisy-mae"></h2>
<tbody id="output"></tbody>
</table>
</div>

<div class="form__row">
<h6 data-i18n="output.better.title"></h6>
<label id="betterLabel"></label>
</div>
</div>

<div style="transform:rotate(180deg)">
Expand Down
56 changes: 54 additions & 2 deletions js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,13 @@ const displayPercentage = function(fraction) {

const hideChart = function() {
$("#output").html("");
$(".chart-wrapper").hide()
$(".chart-wrapper").hide();
$("#betterLabel").html("");
}

const calculateOutput = function (data, first_buy, previous_pattern) {
if (isEmpty(data)) {
hideChart()
hideChart();
return;
}
let pat_desc = {0:"fluctuating", 1:"large-spike", 2:"decreasing", 3:"small-spike", 4:"all"};
Expand Down Expand Up @@ -340,6 +341,57 @@ const calculateOutput = function (data, first_buy, previous_pattern) {
$("#output").html(output_possibilities);

update_chart(data, analyzed_possibilities);

update_sellnow(data, analyzed_possibilities);

};

const update_sellnow = function(prices, patterns) {

// get today info
let now = new Date();
let now_index = now.getDay() * 2 + (now.getHours() >= 12 ? 1 : 0); // this is today's index

let label = '';

if (patterns.length == 1) {
// invalid data
label = "---"
} else if (now_index <= 1) {
// sunday
label = i18next.t("output.better.cant")
} else if (isNaN(prices[now_index])) {
// no today's price
label = i18next.t("output.better.no-data")
} else {
// calculate

let now_price = prices[now_index]; // this is the base price
var prob = 1 - patterns // probability of better is 1 minus probability of worst
.slice(1) // discard the combined pattern (first in the list)
.map(pattern => { // calculate probability of each pattern
return pattern.probability * pattern.prices // as the probability of this pattern times probability of all worst values
.slice(now_index + 1) // starting from tomorrow
.map(day => { // calculate probability of each day
if (day.min >= now_price) return 0; // if the minimum possible is already greater than now, we will always have a greater value
else if (day.max < now_price) return 1; // if the maximum possible is already lower than now, we will always have a lower value
else return (now_price - day.min) / (day.max - day.min + 1); // otherwise, the probability is the percentage of the low interval
}).reduce((acc, e) => acc * e, 1); // the probability of a pattern is the multiplications of each day
}).reduce((acc, e) => acc + e, 0); // the total probability is the addition of each pattern (already normalized)

// generate label
let probNumber = prob == 0 ? "0%" : displayPercentage(prob);
let probLabel = i18next.t(
prob >= 0.9 ? "output.better.no" :
prob >= 0.5 ? "output.better.prob-no" :
prob >= 0.1 ? "output.better.prob-yes" :
"output.better.yes"
);
label = `${probLabel} - ${i18next.t("output.better.details")} ${probNumber}`
}

// update
$("#betterLabel").html(label);
};

const generatePermalink = function (buy_price, sell_prices, first_buy, previous_pattern) {
Expand Down
10 changes: 10 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@
"input": "Input Price",
"minimum": "Guaranteed Minimum",
"maximum": "Potential Maximum"
},
"better": {
"title": "Should I sell now?",
"cant": "Can't sell now",
"no-data": "Need today's price",
"yes": "Yes",
"prob-yes": "Probably yes",
"no": "No",
"prob-no": "Probably no",
"details": "Probability of better price is"
}
},
"textbox": {
Expand Down