BTC event trading pipeline upadte#80
Open
EvW1329 wants to merge 1 commit into
Open
Conversation
- Add polymarket/real_data_builder.py: build feather files from a Polymarket trade-history parquet instead of synthetic prices. Parses BTC binary markets, checks 60% hourly coverage in the 7-day window, forward-fills gaps ≤ 6h, and writes real_contracts.jsonl. - Extend polymarket/contracts.py: support reach/hit/exceed/surpass question patterns; parse K-suffix strikes ($88K → 88,000); add skip_unparseable flag to load_contracts() so mixed JSONL files do not crash the strategy. - Extend scripts/prepare_event_model.py: --use-real-data and --parquet-path flags route Step 0 to real_data_builder instead of the synthetic generator. - Extend DualModelPolymarketPortfolio: contracts_jsonl and predictions_dir are now configurable via the freqtrade config JSON, enabling real-data backtests without strategy file edits. - Pin freqtrade submodule to mlsys-io/freqtrade@5fb001168 (includes precision.amount fix, merged as PR #12). - Update .gitignore: exclude user_data/data/polymarket_ml_real/ and report/. - Update docs/polymarket/README.md and training-guide.md to document all new flags, config keys, question patterns, and real-data artefacts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b2fc200 to
cb52cac
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a complete end-to-end pipeline for trading Polymarket BTC binary
contracts using a direct event-probability model. It includes data ingestion
(both synthetic and real), model training, per-contract predictions, a
portfolio strategy, unit tests, and documentation.
What's included
Core pipeline (
polymarket/)contracts.pyContractMetadataobjects; extract strike/directionabove,below,reach/hit/exceed/surpass, K-suffix like$88K)event_features.pyevent_dataset.pyevent_model.pydata_builder.pyevent_probs.csvforreal_data_builder.pyreal_contracts.jsonlsynthetic_prices.pysettlement.pyStrategy (
user_data/strategies/)DualModelPolymarketPortfolio— freqtradeIStrategythat:event_probs.csvfair values per contractcontracts_jsonlandpredictions_dirconfigurable via config JSON (no strategy edits needed to switch datasets)Alpha factor (
alpha/)EventProbAlpha— pluggableIAlphathat reads fair-value CSVs and emitsml_edgeandml_fair_valuesignals.Preparation script (
scripts/prepare_event_model.py)Four-step pipeline runner:
--skip-feathers*.featherper contract (synthetic or real via--use-real-data)--skip-training-dataevent_model_training.parquetevent_model.pkl*-event_probs.csvper contractTests (
tests/test_polymarket/)61 unit tests covering contracts parsing, event model training/calibration, settlement resolution, and synthetic price
generation.
Documentation (
docs/polymarket/)README.md— quick start, strategy reference, backtesting guide, real-data workflow, configurable paths, modelmetrics, limitations
training-guide.md— architecture, feature engineering, label construction, temporal split, calibration, inference,retraining guidance
freqtrade submodule
Updated to
mlsys-io/freqtrade@5fb001168which includes:fix: set precision.amount=1 for Polymarket synthetic markets— resolves a CCXT TICK_SIZE assertion error on tradeentry (merged via PR Add GitHub Actions CI workflow and unit tests for auto-testing #12)
Validation
End-to-end backtest on real Sep-5 2025 BTC contracts (108K/110K/112K/114K):
BTCABOVE108K-SEP5-YES(BTC was ~$111,500 at expiry → settled YES)