forked from kyleskom/NBA-Machine-Learning-Sports-Betting
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactored XGBoost color conditions, added kelly criterion file * reverted some color logic, correct KC formula * tweaked ReadMe, tested KC, updated NN_runner to have KC * removed debug print statement, updated readme * Added feature flag for kelly criterion - optionally available with -kc cli argument
- Loading branch information
1 parent
a297aa7
commit 05f71ed
Showing
7 changed files
with
81 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import unittest | ||
from src.Utils import Kelly_Criterion as kc | ||
|
||
|
||
class TestKellyCriterion(unittest.TestCase): | ||
|
||
def test_calculate_kelly_criterion_1(self): | ||
result = kc.calculate_kelly_criterion(-110, .6) | ||
self.assertEqual(result, 16.04) | ||
|
||
def test_calculate_kelly_criterion_2(self): | ||
result = kc.calculate_kelly_criterion(-110, .4) | ||
self.assertEqual(result, 0) | ||
|
||
def test_calculate_kelly_criterion_3(self): | ||
result = kc.calculate_kelly_criterion(400, .35) | ||
self.assertEqual(result, 18.75) | ||
|
||
def test_calculate_kelly_criterion_4(self): | ||
result = kc.calculate_kelly_criterion(-500, .85) | ||
self.assertEqual(result, 10) | ||
|
||
def test_calculate_kelly_criterion_5(self): | ||
result = kc.calculate_kelly_criterion(100, .99) | ||
self.assertEqual(result, 98) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def american_to_decimal(american_odds): | ||
""" | ||
Converts American odds to decimal odds (European odds). | ||
""" | ||
if american_odds >= 100: | ||
decimal_odds = (american_odds / 100) | ||
else: | ||
decimal_odds = (100 / abs(american_odds)) | ||
return round(decimal_odds, 2) | ||
|
||
def calculate_kelly_criterion(american_odds, model_prob): | ||
""" | ||
Calculates the fraction of the bankroll to be wagered on each bet | ||
""" | ||
decimal_odds = american_to_decimal(american_odds) | ||
bankroll_fraction = round((100 * (decimal_odds * model_prob - (1 - model_prob))) / decimal_odds, 2) | ||
return bankroll_fraction if bankroll_fraction > 0 else 0 |