Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Arbitrage Check
/**
* Check for arbitrage bet.
*
* @class Arbitrage
*/
var Arbitrage = Arbitrage || {};
var args = [];
process.argv.forEach(
function (value, index) {
if (index > 1) {
args.push(parseFloat(value));
}
}
);
/**
*
* @method arbitrageCheck
*
* @param [name] {Array} Coefficients numbers
* for given bet. Should be two or more.
*
* @return {Number} Under or over 100. Under
* would mean arbitrage, over would mean no
* arbitrage.
*
* @example
* Arbitrage.arbitrageCheck(1.69, 4.50, 6.50); // 96.78 which means ~3.22% profit (100 - 96.78)
*
*/
Arbitrage.arbitrageCheck = function () {
var total = 0;
[].forEach.call(arguments,
function (value, index) {
total += 1 / value;
}
);
return total * 100;
}
console.log(Arbitrage.arbitrageCheck.apply(null, args).toFixed(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.