A professional sports betting framework based on academic research, implementing the Kelly Criterion with safety constraints for optimal bankroll management.
⚠️ Educational Purpose: This framework is for educational and research purposes. Sports betting involves risk. Never bet more than you can afford to lose.
- 📚 Research-Based EV Filtering: Only recommends bets with 10%+ expected value (based on academic studies)
- 📊 Kelly Criterion: Uses Half-Kelly sizing for optimal risk-adjusted returns
- 🛡️ Safety Constraints: Maximum 15% of bankroll per bet
- 📈 Batch Processing: Analyze multiple games via Excel with automatic ranking
- 💰 Bankroll Allocation: Prevents over-betting by prioritizing highest EV opportunities
- 🧪 Comprehensive Testing: 102 tests including property-based validation with 95% code coverage
- 🔧 Robinhood Integration: Whole contract calculations with commission handling
Pick the track that matches your experience:
- Already set up with Python 3.13+ and
uv? Jump straight to the commands in Fast path. - Need a refresher or starting from scratch? Follow the Full setup checklist.
uv sync
uv run python run.pyThe menu offers Excel batch processing (option 1), single-bet analysis (option 2), and exit (option 3). Excel runs write results to data/output/ with “_RESULTS” in the filename.
-
Install Python 3.13+
- Using
uv: If you already haveuvavailable, runuv python install 3.13to download and manage a Python interpreter specifically for this project. - Windows: Download the latest 3.13 release from the Python download page, run the installer, and select Add python.exe to PATH before clicking Install Now.
- macOS: Download the macOS installer from the same page, open the
.pkg, and follow the prompts. If you're unsure which version you have, reinstalling 3.13 is the simplest path.
- Using
-
Install
uvuvmanages virtual environments and dependencies for this project. Follow the instructions for your operating system in the official installation guide, then restart your terminal so the new command is available.
-
Get the project files
- Developers comfortable with Git can clone the repository:
git clone https://github.com/dpearson2699/sports-betting-calculator.git - Otherwise, download the ZIP from GitHub (green Code button → Download ZIP) and extract it. The extracted folder should be named
sports-betting-calculator.
- Developers comfortable with Git can clone the repository:
-
Open a terminal in the project directory
- Windows: In File Explorer, open the project folder, click the address bar, type
powershell, and press Enter. - macOS: In Finder, right-click the folder and choose New Terminal at Folder (or open Terminal and
cdto the folder).
- Windows: In File Explorer, open the project folder, click the address bar, type
-
Install the dependencies
uv sync
uvcreates an isolated environment and downloads the required packages. The first run may take a couple of minutes; later runs are fast. -
Launch the calculator
uv run python run.py
Choose the workflow you need from the on-screen menu and follow the prompts. Excel batch runs save their output to
data/output/.
Your Excel file should have these columns:
| Column | Description | Example |
|---|---|---|
Game |
Game identifier | "Lakers vs Warriors" |
Model Win Percentage |
Your model's win probability | 68 (or 0.68) |
Model Margin |
Predicted margin (optional) | 3.5 |
Contract Price |
Sportsbook price per unit | 0.45 |
💡 Tip: When you first run the application and choose Excel batch mode, if no Excel files are found, you'll see the prompt:
"No Excel files found in data/input/ directory. Create sample Excel file? (y/n)". Choose 'y' to create asample_games.xlsxfile that shows the exact format required and includes example data you can use for testing.
sports-betting-calculator/
├── .github/ # GitHub configuration
├── .vscode/ # VS Code settings
├── config/ # Configuration files
│ └── settings.py # Framework settings & constants
├── data/ # Data directories (auto-created)
│ ├── input/ # Excel files for batch processing
│ └── output/ # Generated results files
├── examples/ # Usage examples
│ ├── basic_usage.py # Single bet example
│ ├── excel_batch_example.py # Batch processing example
│ └── README.md # Examples documentation
├── src/ # Core source code
│ ├── __init__.py # Package initialization
│ ├── betting_framework.py # Kelly Criterion & EV calculations
│ ├── excel_processor.py # Excel I/O & bankroll allocation
│ └── main.py # CLI interface
├── test-results/ # Test output (auto-generated)
│ └── coverage/ # HTML coverage reports
├── tests/ # Streamlined test suite
│ ├── __init__.py # Test package initialization
│ ├── conftest.py # Minimal shared fixtures
│ ├── integration/ # End-to-end workflow tests
│ │ ├── test_excel_workflow.py
│ │ └── test_end_to_end.py
│ └── unit/ # Unit tests for core modules
│ ├── test_betting_framework.py
│ ├── test_commission_manager.py
│ ├── test_excel_processor.py
│ └── test_main.py
├── CONTRIBUTING.md # Contribution guidelines
├── LICENSE # MIT license
├── MATHEMATICAL-FOUNDATION.md # Academic research documentation
├── pyproject.toml # Dependencies & project configuration
├── README.md # This file
├── run.py # Main application entry point
├── SECURITY.md # Security policy
└── uv.lock # Dependency lock file
The project features a comprehensive yet maintainable test suite focused on essential functionality:
# Run all tests locally (< 30 seconds)
uv run pytest
# Run with coverage report
uv run pytest --cov=src --cov-report=term-missing --cov-report=html
# Run specific test categories
uv run pytest tests/unit/ # Unit tests only
uv run pytest tests/integration/ # Integration tests only
# Run tests in parallel (CI/CD)
uv run pytest -n auto- Simple Structure: Clean unit and integration test organization
- Fast Execution: Complete test suite runs in under 30 seconds locally
- Essential Coverage: 87% coverage focusing on core business logic
- Standard Tools: Uses pytest without complex custom frameworks
- UV Integration: Consistent dependency management with
uv runcommands - Offline Testing: Works completely offline after initial setup
- 176 comprehensive tests covering all major functionality
- 146 unit tests across 4 core modules
- 30 integration tests for end-to-end workflows
- 87% overall coverage exceeding the 80% target
- Local-First Development: Immediate feedback with
uv run pytest - CI/CD Integration: Automated testing on GitHub Actions (< 2 minutes)
- Multi-Platform: Validated on Ubuntu, Windows, and macOS
| Command | Purpose | Execution Time |
|---|---|---|
uv run pytest |
Run all tests locally | < 30 seconds |
uv run pytest tests/unit/ |
Unit tests only | < 10 seconds |
uv run pytest tests/integration/ |
Integration tests only | < 20 seconds |
uv run pytest --cov=src |
Tests with coverage | < 35 seconds |
tests/
├── unit/ # Fast unit tests for core modules
│ ├── test_betting_framework.py # Kelly criterion calculations (22 tests)
│ ├── test_commission_manager.py # Commission logic (51 tests)
│ ├── test_excel_processor.py # Excel processing (30 tests)
│ └── test_main.py # User interface (43 tests)
├── integration/ # End-to-end workflow tests
│ ├── test_excel_workflow.py # Excel processing pipeline (15 tests)
│ └── test_end_to_end.py # Complete application flows (15 tests)
├── conftest.py # Minimal shared fixtures
└── __init__.py # Test package initialization
Tests focus on: mathematical accuracy, input validation, Excel processing workflows, user interface functionality, and error handling.
-
Expected Value Calculation:
$EV = (p \times \frac{1}{\text{Contract Price}}) - 1$ - Wharton Filter: Only bet if EV ≥ 10% (academic research requirement)
- Kelly Sizing: Calculate optimal bet size using Kelly Criterion
- Half-Kelly Safety: Use 50% of Kelly for reduced volatility
- Bankroll Cap: Never bet more than 15% of bankroll
- Whole Contracts: Round down to whole contracts (Robinhood constraint)
- Commission Handling: Include $0.02 per contract commission
- Allocation: Rank by EV%, allocate bankroll to best opportunities first
📚 For detailed mathematical formulas and theoretical foundation, see the comprehensive Mathematical Foundation Documentation.
The Excel processor creates a *_RESULTS.xlsx file with two sheets:
- Simplified overview with key metrics
- Game, Win %, Edge %, Stake $, Expected Value
- Final recommendations after bankroll allocation
- Complete analysis with all calculations
- Original game data and betting recommendations
- Expected value percentages and bet amounts
- Target vs actual bet amounts (whole contract adjustments)
- Commission details and unused amounts
- Games automatically ranked by EV% (highest first)
BETTING ANALYSIS SUMMARY
============================================================
Total Games Analyzed: 6
Initial BET Opportunities: 5
Final Recommended Bets: 4
Weekly Bankroll: $100.00
Total Allocated: $83.28
Remaining Bankroll: $16.72
Total Expected Profit: $25.15
TOP RECOMMENDED BETS (by EV%):
Chiefs vs Bills: $15.00 (EV: 114.3%)
Cowboys vs Giants: $15.00 (EV: 80.0%)
Lakers vs Warriors: $15.00 (EV: 51.1%)
Yankees vs Red Sox: $15.00 (EV: 12.4%)
src/betting_framework.py- Core betting logic and Kelly calculationssrc/excel_processor.py- Excel file processing and batch analysissrc/main.py- Interactive CLI interfaceconfig/settings.py- Configuration constants and directory setuprun.py- Main application entry pointtests/- Comprehensive test suite with 102 tests including property-based validation
Edit config/settings.py to modify:
MIN_EV_THRESHOLD = 10.0- Minimum expected value percentageHALF_KELLY_MULTIPLIER = 0.5- Kelly fraction multiplierMAX_BET_PERCENTAGE = 0.15- Maximum bet as fraction of bankrollCOMMISSION_PER_CONTRACT = 0.02- Commission per contract
- Python 3.13+
- pandas ≥ 2.3.2
- openpyxl ≥ 3.1.5
- pytest ≥ 8.0.0 (for testing)
- ✅ 10% minimum expected value threshold (Wharton research)
- ✅ Half-Kelly sizing (reduced volatility vs full Kelly)
- ✅ 15% maximum bet size cap (prevents excessive risk)
- ✅ Whole contract enforcement (Robinhood constraint)
- ✅ Commission integration (realistic cost calculations)
- ✅ Bankroll allocation (prevents over-betting across multiple games)
- ✅ Input validation (dual format support, error handling)
- ✅ Mathematical verification (comprehensive test coverage)
This framework is built on rigorous academic research and proven mathematical principles. For complete details on the theoretical foundation, empirical validation, and mathematical derivations, see Mathematical Foundation Documentation.
The methodology is primarily based on:
- Wharton School empirical study analyzing 10,000+ betting opportunities
- Kelly Criterion with Half-Kelly safety implementation
- Expected value thresholds validated through academic research
- Risk management principles from modern portfolio theory
- Solution: Use option to create sample file, or add your Excel files to
data/input/directory
- Solution: Ensure Excel file has columns:
Game,Model Win Percentage,Contract Price - Optional column:
Model Margin
- Cause: Expected values below 10% threshold (Wharton requirement)
- Solution: Check your win percentages and contract prices for accuracy
- Solution: The
.vscode/settings.jsonfile should resolve Python path issues - Alternative: Use
python run.pyinstead of running files directly
- Run:
uv run pytest -vto see detailed test output - Check: Python version (requires 3.13+) and dependencies (
uv sync)
- Check the examples:
python -m src.examples.basic_usage - Run tests:
uv run pytestto verify installation - Review documentation: See
docs/directory for comprehensive documentation - Read the guides: Check
docs/CONTRIBUTING.mdfor development info - Create an issue: Use GitHub issues for bug reports or questions### Performance Tips
- Large datasets: Framework handles 100+ games efficiently
- Memory usage: Results are optimized for reasonable memory footprint
- Processing speed: Typical processing time < 1 second for most datasets