Skip to content

Commit

Permalink
Merge pull request #3 from AlgoETS/more-improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebou12 authored Jul 4, 2024
2 parents 5e1a7e3 + fc96427 commit 894c7bf
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 26 deletions.
20 changes: 11 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
<div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-md">
<h1 class="text-3xl font-bold mb-6 text-center text-blue-600">Arbitrage Calculator</h1>
<div class="mb-6 p-4 bg-blue-100 rounded-md shadow-md">
<h1 class="text-3xl font-bold mb-4 text-center text-blue-600">Arbitrage Calculator</h1>
<div class="text-center text-gray-600">
<p class="font-semibold">Instructions:</p>
<ol class="list-decimal list-inside text-left mx-auto text-sm">
<li>Select the number of odds (2 or 3).</li>
<li>Enter the odds values and the total investment amount.</li>
<li>Click "Calculate" to see the arbitrage opportunity, percentage, optimal stakes, total returns, and guaranteed profit.</li>
</ol>
</div>
</div>
<div class="space-y-4">
<div class="input-group">
<label for="numOdds" class="block text-sm font-medium text-gray-700">Number of Odds:</label>
Expand Down Expand Up @@ -52,14 +62,6 @@ <h1 class="text-3xl font-bold mb-6 text-center text-blue-600">Arbitrage Calculat
</div>
<div id="results" class="mt-6 p-4 bg-gray-100 rounded-md shadow-md text-gray-700"></div>
</div>
<div class="mt-6 text-center text-gray-600">
<p>Instructions:</p>
<ol class="list-decimal list-inside text-left max-w-md mx-auto">
<li>Select the number of odds (2 or 3).</li>
<li>Enter the odds values and the total investment amount.</li>
<li>Click "Calculate" to see the arbitrage opportunity, percentage, optimal stakes, total returns, and guaranteed profit.</li>
</ol>
</div>
<script src="script.js"></script>
</body>
</html>
106 changes: 89 additions & 17 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ function toggleOddsFields() {
}

function hasArbitrageOpportunity(odds) {
const totalInverseOdds = odds.reduce((sum, odd) => sum + (1 / odd), 0);
let totalInverseOdds = 0;
for (let i = 0; i < odds.length; i++) {
totalInverseOdds += 1 / odds[i];
}
return totalInverseOdds < 1;
}

function calculateArbitragePercentage(odds) {
const totalInverseOdds = odds.reduce((sum, odd) => sum + (1 / odd), 0);
let totalInverseOdds = 0;
for (let i = 0; i < odds.length; i++) {
totalInverseOdds += 1 / odds[i];
}
const arbitragePercentage = (1 - totalInverseOdds) * 100;
return arbitragePercentage;
}

function calculateOptimalStakes(totalInvestment, odds) {
const totalInverseOdds = odds.reduce((sum, odd) => sum + (1 / odd), 0);
let totalInverseOdds = 0;
for (let i = 0; i < odds.length; i++) {
totalInverseOdds += 1 / odds[i];
}
const stakes = odds.map(odd => (totalInvestment * (1 / odd)) / totalInverseOdds);
return stakes;
}
Expand All @@ -51,23 +60,86 @@ function calculateArbitrage() {
odds.push(parseFloat(document.getElementById('odds3Win').value));
odds.push(parseFloat(document.getElementById('odds3Lost').value));
}

const totalInvestment = parseFloat(document.getElementById('investment').value);
const arbitrageOpportunities = [];

// Check combinations for 2 odds
if (numOdds == 2) {
if (hasArbitrageOpportunity([odds[0], odds[2]])) {
const arbitragePercentage = calculateArbitragePercentage([odds[0], odds[3]]);
const optimalStakes = calculateOptimalStakes(totalInvestment, [odds[0], odds[3]]);
const totalReturns = calculateTotalReturn(optimalStakes, [odds[0], odds[3]]);
const guaranteedProfit = calculateGuaranteedProfit(totalInvestment, totalReturns);
arbitrageOpportunities.push({
"description": "win-site1 and lost-site2",
"arbitrage_percentage": arbitragePercentage,
"optimal_stakes": optimalStakes,
"total_returns": totalReturns,
"guaranteed_profit": guaranteedProfit
});
}

if (hasArbitrageOpportunity(odds)) {
const arbitragePercentage = calculateArbitragePercentage(odds);
const optimalStakes = calculateOptimalStakes(totalInvestment, odds);
const totalReturns = calculateTotalReturn(optimalStakes, odds);
const guaranteedProfit = calculateGuaranteedProfit(totalInvestment, totalReturns);
if (hasArbitrageOpportunity([odds[1], odds[3]])) {
const arbitragePercentage = calculateArbitragePercentage([odds[1], odds[2]]);
const optimalStakes = calculateOptimalStakes(totalInvestment, [odds[1], odds[2]]);
const totalReturns = calculateTotalReturn(optimalStakes, [odds[1], odds[2]]);
const guaranteedProfit = calculateGuaranteedProfit(totalInvestment, totalReturns);
arbitrageOpportunities.push({
"description": "lost-site1 and win-site2",
"arbitrage_percentage": arbitragePercentage,
"optimal_stakes": optimalStakes,
"total_returns": totalReturns,
"guaranteed_profit": guaranteedProfit
});
}
}

// Check combinations for 3 odds
if (numOdds == 3) {
if (hasArbitrageOpportunity([odds[0], odds[2], odds[4]])) {
const arbitragePercentage = calculateArbitragePercentage([odds[0], odds[3], odds[4]]);
const optimalStakes = calculateOptimalStakes(totalInvestment, [odds[0], odds[3], odds[4]]);
const totalReturns = calculateTotalReturn(optimalStakes, [odds[0], odds[3], odds[4]]);
const guaranteedProfit = calculateGuaranteedProfit(totalInvestment, totalReturns);
arbitrageOpportunities.push({
"description": "win-site1, lost-site2, draw-site1",
"arbitrage_percentage": arbitragePercentage,
"optimal_stakes": optimalStakes,
"total_returns": totalReturns,
"guaranteed_profit": guaranteedProfit
});
}

if (hasArbitrageOpportunity([odds[1], odds[3], odds[5]])) {
const arbitragePercentage = calculateArbitragePercentage([odds[1], odds[2], odds[5]]);
const optimalStakes = calculateOptimalStakes(totalInvestment, [odds[1], odds[2], odds[5]]);
const totalReturns = calculateTotalReturn(optimalStakes, [odds[1], odds[2], odds[5]]);
const guaranteedProfit = calculateGuaranteedProfit(totalInvestment, totalReturns);
arbitrageOpportunities.push({
"description": "lost-site1, win-site2, draw-site2",
"arbitrage_percentage": arbitragePercentage,
"optimal_stakes": optimalStakes,
"total_returns": totalReturns,
"guaranteed_profit": guaranteedProfit
});
}
}

document.getElementById('results').innerHTML = `
<p class="font-bold">Arbitrage Opportunity: Yes</p>
<p>Arbitrage Percentage: ${arbitragePercentage.toFixed(2)}%</p>
<p>Optimal Stakes: ${optimalStakes.map(stake => stake.toFixed(2)).join(', ')}</p>
<p>Total Returns: ${totalReturns.map(ret => ret.toFixed(2)).join(', ')}</p>
<p>Guaranteed Profit: ${guaranteedProfit.toFixed(2)}</p>
`;
// Display results
if (arbitrageOpportunities.length > 0) {
let resultHTML = '';
arbitrageOpportunities.forEach(opportunity => {
resultHTML += `
<p class="font-bold">Arbitrage Opportunity (${opportunity.description}): Yes</p>
<p>Arbitrage Percentage (${opportunity.description}): ${opportunity.arbitrage_percentage.toFixed(2)}%</p>
<p>Optimal Stakes (${opportunity.description}): ${opportunity.optimal_stakes.map(stake => stake.toFixed(2)).join(', ')}</p>
<p>Total Returns (${opportunity.description}): ${opportunity.total_returns.map(ret => ret.toFixed(2)).join(', ')}</p>
<p>Guaranteed Profit (${opportunity.description}): ${opportunity.guaranteed_profit.toFixed(2)}</p>
`;
});
document.getElementById('results').innerHTML = resultHTML;
} else {
document.getElementById('results').innerHTML = `<p class="font-bold">Arbitrage Opportunity: No</p>`;
document.getElementById('results').innerHTML = '<p class="font-bold">No Arbitrage Opportunities Found</p>';
}
}

0 comments on commit 894c7bf

Please sign in to comment.