Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vidul-nikolaev-petrov
Created March 4, 2015 23:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vidul-nikolaev-petrov/ba74633eb64b12f88332 to your computer and use it in GitHub Desktop.
Save vidul-nikolaev-petrov/ba74633eb64b12f88332 to your computer and use it in GitHub Desktop.
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