This project builds an experimental pipeline for Mega-Sena draws:
- Parse draw history
- Compute astrology features (local, no API)
- Run a backtest predictor with adjustable weights
- Tune weights via walk-forward optimization
Note: Mega-Sena is designed to be random. The predictor is for exploration only.
- Node.js 16+ (Node 18+ recommended)
- npm 8+
- Windows PowerShell 5.1+ or PowerShell 7+
- The historical input file
Mega-Sena.xlsxin the project root
Check versions:
node -v
npm -v
powershell -Version- Extract draw history (from the Excel file):
powershell -ExecutionPolicy Bypass -File .\scripts\extract_megasena.ps1
- Compute astrology features:
node .\scripts\compute_astro.js
- Run backtest:
node .\scripts\backtest_predict.js
Outputs:
data/mega_sena.csvdata/mega_sena.jsondata/mega_sena_astro.jsondata/backtest_results.json
The predictor reads defaults from config/predictor.json. Environment variables
override any field, so you can test changes without editing the file.
Path: config/predictor.json
{
"windowSize": 200,
"halfLife": 20,
"explore": 0.1,
"hotBoost": 0.05,
"coldBoost": 0.1,
"coldWindow": 25,
"ticketsPerDraw": 10,
"minHistory": 50,
"seed": 42
}
windowSize: How many previous draws are used to compute weights. Larger values smooth noise but can lag shifts.halfLife: Recency decay in draws. Smaller values prioritize recent draws.explore: Mixes in a uniform distribution (0.0 = no exploration).hotBoost: Multiplier for numbers recently drawn (seecoldWindow).coldBoost: Multiplier for numbers NOT drawn recently (seecoldWindow).coldWindow: Number of latest draws used to define hot/cold numbers.ticketsPerDraw: Number of predicted tickets per draw (backtest only).minHistory: Minimum history before prediction starts.seed: RNG seed for reproducible backtest results.
Any of these can be set as environment variables:
WINDOWHALF_LIFEEXPLOREHOT_BOOSTCOLD_BOOSTCOLD_WINDOWTICKETSMIN_HISTORYSEED
Example (PowerShell):
$env:WINDOW='120'
$env:HALF_LIFE='12'
$env:EXPLORE='0.18'
node .\scripts\backtest_predict.js
The tuner runs walk-forward evaluation without peeking at future draws.
node .\scripts\tune_predictor.js
For full coverage, the tuning can be split into chunks and merged:
$env:STRIDE='1'; $env:RANDOM_TRIALS='20'; $env:START_IDX='50'; $env:END_IDX='800'
node .\scripts\tune_predictor.js .\data\mega_sena_astro.json .\data\tuning_chunk_1.json .\data\tuning_chunk_1.csv
$env:STRIDE='1'; $env:RANDOM_TRIALS='20'; $env:START_IDX='800'; $env:END_IDX='1550'
node .\scripts\tune_predictor.js .\data\mega_sena_astro.json .\data\tuning_chunk_2.json .\data\tuning_chunk_2.csv
$env:STRIDE='1'; $env:RANDOM_TRIALS='20'; $env:START_IDX='1550'; $env:END_IDX='2300'
node .\scripts\tune_predictor.js .\data\mega_sena_astro.json .\data\tuning_chunk_3.json .\data\tuning_chunk_3.csv
$env:STRIDE='1'; $env:RANDOM_TRIALS='20'; $env:START_IDX='2300'; $env:END_IDX='2954'
node .\scripts\tune_predictor.js .\data\mega_sena_astro.json .\data\tuning_chunk_4.json .\data\tuning_chunk_4.csv
Merge and report:
node .\scripts\merge_tuning_chunks.js .\data .\data\tuning_results_full.json .\data\tuning_results_full.csv
node .\scripts\report_tuning.js .\data\tuning_results_full.json .\data\tuning_report_full.html
Generate tickets for any target draw date/time using the current tuned config:
node .\scripts\predict_next.js --date YYYY-MM-DD --hour 21 --minute 0 --tickets 20Example:
node .\scripts\predict_next.js --date 2025-12-31 --hour 22 --minute 0 --tickets 20Or via npm script:
npm run predict:next -- --date 2025-12-31 --hour 22 --minute 0 --tickets 20Optional flags:
--inputpath to historical dataset (default:data/mega_sena_astro.json)--outoutput JSON path--csvoutput CSV path--latlatitude (default:-23.564)--lonlongitude (default:-46.651)
- The astrology calculations use
circular-natal-horoscope-js. - Lunar phases include phase name, angle, and illumination.
- The predictor is experimental and not intended for real-world betting.