Skip to content

Commit e3f956d

Browse files
authored
Add files via upload
1 parent 351111a commit e3f956d

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

arbitrage.ipynb

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# Input values\n",
10+
"odds_win_site1 = 1.3\n",
11+
"odds_lost_site1 = 3.930\n",
12+
"odds_win_site2 = 1.42\n",
13+
"odds_lost_site2 = 2.9\n",
14+
"total_investment = 100"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 2,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"def has_arbitrage_opportunity(odds):\n",
24+
" total_inverse_odds = sum(1 / odd for odd in odds)\n",
25+
" return total_inverse_odds < 1"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 3,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"def calculate_arbitrage_percentage(odds):\n",
35+
" total_inverse_odds = sum(1 / odd for odd in odds)\n",
36+
" arbitrage_percentage = (1 - total_inverse_odds) * 100\n",
37+
" return arbitrage_percentage"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": 4,
43+
"metadata": {},
44+
"outputs": [],
45+
"source": [
46+
"def calculate_optimal_stakes(total_investment, odds):\n",
47+
" total_inverse_odds = sum(1 / odd for odd in odds)\n",
48+
" stakes = [(total_investment * (1 / odd)) / total_inverse_odds for odd in odds]\n",
49+
" return stakes"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 5,
55+
"metadata": {},
56+
"outputs": [],
57+
"source": [
58+
"def calculate_total_return(stakes, odds):\n",
59+
" total_returns = [stake * odd for stake, odd in zip(stakes, odds)]\n",
60+
" return total_returns"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 6,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"def calculate_guaranteed_profit(total_investment, total_returns):\n",
70+
" min_total_return = min(total_returns)\n",
71+
" guaranteed_profit = min_total_return - total_investment\n",
72+
" return guaranteed_profit"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": 7,
78+
"metadata": {},
79+
"outputs": [
80+
{
81+
"name": "stdout",
82+
"output_type": "stream",
83+
"text": [
84+
"Arbitrage Opportunity (lost-site1 and win-site2): Yes\n",
85+
"Arbitrage Percentage (lost-site1 and win-site2): 4.13%\n",
86+
"Optimal Stakes (lost-site1 and win-site2): [26.542056074766354, 73.45794392523365]\n",
87+
"Total Returns (lost-site1 and win-site2): [104.31028037383177, 104.31028037383177]\n",
88+
"Guaranteed Profit (lost-site1 and win-site2): 4.31\n"
89+
]
90+
}
91+
],
92+
"source": [
93+
"# Check for arbitrage opportunities\n",
94+
"arbitrage_opportunities = []\n",
95+
"\n",
96+
"# Combination 1: win-site1 and lost-site2\n",
97+
"if has_arbitrage_opportunity([odds_win_site1, odds_lost_site2]):\n",
98+
" arbitrage_percentage = calculate_arbitrage_percentage([odds_win_site1, odds_lost_site2])\n",
99+
" optimal_stakes = calculate_optimal_stakes(total_investment, [odds_win_site1, odds_lost_site2])\n",
100+
" total_returns = calculate_total_return(optimal_stakes, [odds_win_site1, odds_lost_site2])\n",
101+
" guaranteed_profit = calculate_guaranteed_profit(total_investment, total_returns)\n",
102+
" arbitrage_opportunities.append({\n",
103+
" \"description\": \"win-site1 and lost-site2\",\n",
104+
" \"arbitrage_percentage\": arbitrage_percentage,\n",
105+
" \"optimal_stakes\": optimal_stakes,\n",
106+
" \"total_returns\": total_returns,\n",
107+
" \"guaranteed_profit\": guaranteed_profit\n",
108+
" })\n",
109+
"\n",
110+
"# Combination 2: lost-site1 and win-site2\n",
111+
"if has_arbitrage_opportunity([odds_lost_site1, odds_win_site2]):\n",
112+
" arbitrage_percentage = calculate_arbitrage_percentage([odds_lost_site1, odds_win_site2])\n",
113+
" optimal_stakes = calculate_optimal_stakes(total_investment, [odds_lost_site1, odds_win_site2])\n",
114+
" total_returns = calculate_total_return(optimal_stakes, [odds_lost_site1, odds_win_site2])\n",
115+
" guaranteed_profit = calculate_guaranteed_profit(total_investment, total_returns)\n",
116+
" arbitrage_opportunities.append({\n",
117+
" \"description\": \"lost-site1 and win-site2\",\n",
118+
" \"arbitrage_percentage\": arbitrage_percentage,\n",
119+
" \"optimal_stakes\": optimal_stakes,\n",
120+
" \"total_returns\": total_returns,\n",
121+
" \"guaranteed_profit\": guaranteed_profit\n",
122+
" })\n",
123+
"\n",
124+
"# Output Results\n",
125+
"if arbitrage_opportunities:\n",
126+
" for opportunity in arbitrage_opportunities:\n",
127+
" print(f\"Arbitrage Opportunity ({opportunity['description']}): Yes\")\n",
128+
" print(f\"Arbitrage Percentage ({opportunity['description']}): {opportunity['arbitrage_percentage']:.2f}%\")\n",
129+
" print(f\"Optimal Stakes ({opportunity['description']}): {opportunity['optimal_stakes']}\")\n",
130+
" print(f\"Total Returns ({opportunity['description']}): {opportunity['total_returns']}\")\n",
131+
" print(f\"Guaranteed Profit ({opportunity['description']}): {opportunity['guaranteed_profit']:.2f}\")\n",
132+
"else:\n",
133+
" print(\"No Arbitrage Opportunities Found\")"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": null,
139+
"metadata": {},
140+
"outputs": [],
141+
"source": []
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": null,
146+
"metadata": {},
147+
"outputs": [],
148+
"source": []
149+
}
150+
],
151+
"metadata": {
152+
"kernelspec": {
153+
"display_name": "Python 3",
154+
"language": "python",
155+
"name": "python3"
156+
},
157+
"language_info": {
158+
"codemirror_mode": {
159+
"name": "ipython",
160+
"version": 3
161+
},
162+
"file_extension": ".py",
163+
"mimetype": "text/x-python",
164+
"name": "python",
165+
"nbconvert_exporter": "python",
166+
"pygments_lexer": "ipython3",
167+
"version": "3.12.4"
168+
}
169+
},
170+
"nbformat": 4,
171+
"nbformat_minor": 2
172+
}

0 commit comments

Comments
 (0)