-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
147 lines (133 loc) · 6.42 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
function toggleOddsFields() {
const numOdds = parseInt(document.getElementById('numOdds').value, 10);
const odds3WinContainer = document.getElementById('odds3Win-container');
const odds3LostContainer = document.getElementById('odds3Lost-container');
if (numOdds === 3) {
odds3WinContainer.classList.remove('hidden');
odds3LostContainer.classList.remove('hidden');
} else {
odds3WinContainer.classList.add('hidden');
odds3LostContainer.classList.add('hidden');
}
}
function hasArbitrageOpportunity(odds) {
let totalInverseOdds = 0;
for (let i = 0; i < odds.length; i++) {
totalInverseOdds += 1 / odds[i];
}
return totalInverseOdds < 1;
}
function calculateArbitragePercentage(odds) {
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) {
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;
}
function calculateTotalReturn(stakes, odds) {
return stakes.map((stake, index) => stake * odds[index]);
}
function calculateGuaranteedProfit(totalInvestment, totalReturns) {
const minTotalReturn = Math.min(...totalReturns);
return minTotalReturn - totalInvestment;
}
function calculateArbitrage() {
const numOdds = parseInt(document.getElementById('numOdds').value, 10);
const odds = [
parseFloat(document.getElementById('odds1Win').value),
parseFloat(document.getElementById('odds1Lost').value),
parseFloat(document.getElementById('odds2Win').value),
parseFloat(document.getElementById('odds2Lost').value)
];
if (numOdds === 3) {
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[3]])) {
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[1], odds[2]])) {
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[3], 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[2], 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
});
}
}
// Display results
if (arbitrageOpportunities.length > 0) {
let resultHTML = '';
arbitrageOpportunities.forEach(opportunity => {
resultHTML += `
<div class="p-4 bg-white rounded-md shadow-md mb-4">
<p class="font-bold text-lg">Arbitrage Opportunity (${opportunity.description}): Yes</p>
<p>Arbitrage Percentage: ${opportunity.arbitrage_percentage.toFixed(2)}%</p>
<p>Optimal Stakes: ${opportunity.optimal_stakes.map(stake => stake.toFixed(2)).join(', ')}</p>
<p>Total Returns: ${opportunity.total_returns.map(ret => ret.toFixed(2)).join(', ')}</p>
<p>Guaranteed Profit: ${opportunity.guaranteed_profit.toFixed(2)}</p>
</div>
`;
});
document.getElementById('results').innerHTML = resultHTML;
} else {
document.getElementById('results').innerHTML = '<p class="font-bold text-lg">No Arbitrage Opportunities Found</p>';
}
}