Skip to content

Instantly share code, notes, and snippets.

@ognjengt
Created December 23, 2017 22:21
Show Gist options
  • Save ognjengt/f7e6856fc694da3e21e131c0784bacc6 to your computer and use it in GitHub Desktop.
Save ognjengt/f7e6856fc694da3e21e131c0784bacc6 to your computer and use it in GitHub Desktop.
/**
* Calculates the prediction
* Returns object containing valuable data for prediction
* @param {*Array} data Array of objects, containing start and end bitcoin values
* @param {*Float} currentBitcoinValue Current btc value
*/
async function calculatePrediction(data,currentBitcoinValue) {
var finalPredictionData = {
raw: 0,
percentage: 0,
positive: '',
finalValue: 0
}
var sum = 0;
await forEach(data, async (value) => {
sum += value.end - value.start;
})
sum = sum / K;
finalPredictionData.raw = sum;
finalPredictionData.finalValue = currentBitcoinValue + sum;
finalPredictionData.positive = sum > 0 ? 'true' : 'false';
finalPredictionData.percentage = ((finalPredictionData.finalValue - currentBitcoinValue) / currentBitcoinValue) * 100;
return finalPredictionData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment