Backtest price history fix and simulated portfolio fixes - #18
Merged
Merged
Conversation
The CLOB now answers 400 ("'startTs' and 'endTs' interval is too long") to
/prices-history windows longer than about 15 days, and the backtest asked
for up to 32 days (30-day horizon + 2), so every case failed. The history
is now fetched in windows of at most 14 days; resolved markets without
hourly points are asked again every 12 hours; a 4xx for one market means
no history (case skipped) instead of an error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JLWZrfy12imc6dQRsEtFjj
…s, bid value - Excluding a bet only changes its status; readmitting restores it as it was: a sold bet comes back sold, a closed one keeps its result and closing time (settle_bets no longer overwrites settled_at). Sold bets excluded by the old code get their result rebuilt from the sale. - latest_prediction falls back to the market's own forecast when its multi-outcome event has none, so positions opened before multi-outcome support get an exit plan and are reviewed by automatic selling. - Open positions are valued at the best bid minus the sale fee (what selling now would fetch); the value at the market price stays available. - "Sell now" asks for confirmation and offers to exclude the market from automatic buys, so the next forecast does not buy it back. - Opportunities flag stored exposure/cash reasons that no longer hold. - The simplified Kelly stake is labelled as indicative and points to the real stake of the economic assessment. - .table-wrap is position: relative, so the hidden "Actions" header no longer widens the Portfolio page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JLWZrfy12imc6dQRsEtFjj
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.
1. Backtest: Polymarket price history in 14-day windows
Every backtest case failed with
400 Bad Requestonhttps://clob.polymarket.com/prices-history.startTs–endTswindows longer than about 15 days ('startTs' and 'endTs' interval is too long, report).fetch_price_historynow:fidelity=720when there are no hourly points;2. Simulated portfolio
routes/portfolio.py,settle_bets).ledgerandsummaryalready count bets by status, so the kept fields are not counted.settled_at = settled_at or now.sold, notopen.pnlrebuilt from the sale price.latest_prediction): the function falls back to the market's ownMarketPrediction. Positions opened before multi-outcome support now get an exit plan and are reviewed by automatic selling..table-wrapis nowposition: relative. At 951px the pagescrollWidthgoes from 1301 to 951.unrealized_pnl_mid,mid_value) and shows on hover.exposure_cap/no_cashreasons that no longer hold, for example after a sale, are flagged (economics.stale). The card says to open the market for up-to-date numbers.Tests
tests/test_portfolio.py:settled_at,pnland the time of its point on the equity curve;#/portafoglioat 390, 951 and 1280px;🤖 Generated with Claude Code
https://claude.ai/code/session_01JLWZrfy12imc6dQRsEtFjj