Commit Graph

40 Commits

Author SHA1 Message Date
Bu5hm4nn
b2bc4db41a Improve backtest lazy loading and test automation 2026-04-07 12:18:50 +02:00
Bu5hm4nn
f00b1b7755 feat: add candlestick chart with portfolio value line (BT-004)
- Add spot_open field to BacktestDailyPoint for complete OHLC data
- Replace line chart with candlestick chart showing price OHLC
- Add portfolio value line on secondary Y-axis
- Add _chart_options_from_dict for rendering job results
- Update both render_result and render_job_result to use new chart
2026-04-06 11:22:10 +02:00
Bu5hm4nn
6b8336ab7e feat: add Portfolio Value, Option Value, and Contracts columns to daily results
- Add option_contracts field to BacktestDailyPoint (number of contracts held)
- Update engine to calculate total option contracts from positions
- Update job serialization to include underlying_value, option_market_value, net_portfolio_value, option_contracts
- Update both render_result and render_job_result tables to show:
  - Low, High, Close (from previous commit)
  - Portfolio value (net_portfolio_value)
  - Option value (option_market_value)
  - Contracts (option_contracts)
  - LTV hedged
  - Margin call status
2026-04-05 08:54:38 +02:00
Bu5hm4nn
7a7b191a6d fix: correct type annotations in databento_source.py
- Fix return type of _load_from_cache and _df_to_daily_points to return list[DailyClosePoint]
- Import DailyClosePoint from historical_provider
- Use TYPE_CHECKING pattern for optional databento/pandas imports
2026-04-05 08:43:07 +02:00
Bu5hm4nn
5ffe5dd04e fix: restore clear_cache and get_cache_stats methods in DatabentoHistoricalPriceSource
- Add back clear_cache method that was accidentally removed
- Add file_count and total_size_bytes to get_cache_stats return value
- Update tests for fixed March 2026 default dates
2026-04-04 23:24:53 +02:00
Bu5hm4nn
063ccb6781 feat: default to March 2026 dates and show Low/High/Close in results
- Change default backtest date range to 2026-03-02 through 2026-03-25
- Add spot_low and spot_high to BacktestDailyPoint for intraday range
- Update engine to populate low/high from DailyClosePoint
- Update daily results table to show Low, High, Close columns instead of just Spot
- Update job serialization to include spot_low and spot_high
2026-04-04 23:18:01 +02:00
Bu5hm4nn
a8e710f790 feat: use day's low price for margin call evaluation
- Extend DailyClosePoint to include low, high, open (optional)
- Update Databento source to extract OHLC data from ohlcv-1d schema
- Update YFinance source to extract Low, High, Open from history
- Modify backtest engine to use worst-case (low) price for margin call detection

This ensures margin calls are evaluated at the day's worst price,
not just the closing price, providing more realistic risk assessment.
2026-04-04 23:06:15 +02:00
Bu5hm4nn
d835544e58 fix: correct backtest job result serialization and add Playwright test fixtures
- Fix BacktestPageRunResult serialization in jobs.py to correctly access
  nested fields from scenario and run_result objects
- Add test_backtest_job.py with comprehensive tests for job execution
- Add conftest_playwright.py with ServerManager that starts FastAPI server
  for Playwright tests using uvicorn
- Add test_playwright_server.py with E2E tests using the server fixture

The job serialization bug was causing backtest results to fail silently
because it was trying to access non-existent fields on BacktestPageRunResult.
2026-04-04 18:27:34 +02:00
Bu5hm4nn
6c35efde0f fix: use selected data source for backtest historical prices
The backtest engine was always using fixture data (limited to 2024-01-02
through 2024-01-08) regardless of the data_source selection. The fix
fetches historical prices using the specified data source (Databento,
Yahoo Finance, or synthetic) and passes them directly to the engine.
2026-04-03 20:34:21 +02:00
Bu5hm4nn
79d19f14ef style: format backtesting files with black 2026-04-01 13:49:21 +02:00
Bu5hm4nn
c2e62972c6 chore: trigger CI 2026-04-01 12:28:42 +02:00
Bu5hm4nn
a0f245b212 chore: re-trigger CI 2026-04-01 12:09:56 +02:00
Bu5hm4nn
fae4d13c44 chore: trigger CI after Forgejo upgrade 2026-04-01 11:55:16 +02:00
Bu5hm4nn
07ea271971 chore: trigger CI rebuild 2026-04-01 09:50:49 +02:00
Bu5hm4nn
a2a816cc79 fix(backtest): use fixture provider ID for backtest scenario
The backtest engine uses a fixture provider (synthetic_v1) regardless of
the data_source used for price fetching. We must use the fixture provider's
ID for the scenario, not the data source's ID.

This fixes 'Unsupported provider/pricing combination' error when running
backtests with data_source='databento'.
2026-04-01 09:42:23 +02:00
Bu5hm4nn
27ade507cd feat(backtest): async job queue for non-blocking backtest execution
BREAKING CHANGE: Complete redesign of backtest execution

- Add BacktestJob system with progress stages (validating, fetching_prices, calculating)
- Run backtests in background threads, UI polls for status
- Show progress label with current stage during execution
- Remove synchronous Databento API calls from page load
- Use static default entry spot for initial render (defers API call)
- Make refresh_workspace_seeded_units async with run.io_bound

This fixes:
- 'Connection lost' WebSocket timeout errors
- Slow page load (30s initial load)
- Backtest never completing

The job system provides:
- Non-blocking execution
- Progress tracking with stages
- Error handling with user-friendly messages
- Result caching for retrieval after completion
2026-04-01 09:31:53 +02:00
Bu5hm4nn
f31b83668e fix(backtest): remove default data_source from get_historical_prices 2026-03-30 14:28:07 +02:00
Bu5hm4nn
2d1ecc2fcf fix(backtest): ensure data_source is passed through all validation calls
- Pass data_source to derive_entry_spot in backtests.py
- Remove default 'synthetic' value for data_source in derive_entry_spot and validate_preview_inputs
- Update all tests to explicitly pass data_source parameter
- Improve error message with helpful suggestion for Databento/Yahoo Finance
2026-03-30 09:21:49 +02:00
Bu5hm4nn
eaaf78cd12 fix(backtest): improve error message for dates outside fixture window
- Add helpful message suggesting Databento/Yahoo Finance for dates outside fixture range
- Update test to expect BOUNDED policy for backtest UI
2026-03-30 09:11:56 +02:00
Bu5hm4nn
70b09cbf0b fix(backtest): remove BT-001A exact window restriction now that full data access is available
- Change WindowPolicy from EXACT to BOUNDED for backtest fixture
- Pass data_source to run_read_only_scenario so real data can be used
- Fix injected provider identity preservation in BacktestPageService
- Add type: ignore for BacktestHistoricalProvider protocol assignment
- Revert TypedDict change to avoid cascading type issues in pages/
- Update tests to reflect new BOUNDED policy behavior
2026-03-30 08:57:15 +02:00
Bu5hm4nn
8e1aa4ad26 fix(lint): remove unused imports and reformat with black 2026-03-30 08:42:07 +02:00
Bu5hm4nn
887565be74 fix(types): resolve all mypy type errors (CORE-003)
- Fix return type annotation for get_default_premium_for_product
- Add type narrowing for Weight|Money union using _as_money helper
- Add isinstance checks before float() calls for object types
- Add type guard for Decimal.exponent comparison
- Use _unit_typed and _currency_typed properties for type narrowing
- Cast option_type to OptionType Literal after validation
- Fix provider type hierarchy in backtesting services
- Add types-requests to dev dependencies
- Remove '|| true' from CI type-check job

All 36 mypy errors resolved across 15 files.
2026-03-30 00:05:09 +02:00
Bu5hm4nn
dc4ee1f261 feat(CONV-001): add GLD launch date validation, feat(DATA-DB-003): add cache CLI
CONV-001:
- Add GLD_LAUNCH_DATE constant (November 18, 2004)
- Validate reference_date in gld_ounces_per_share()
- Raise ValueError for dates before GLD launch
- Update docstring with valid date range
- Add comprehensive test coverage for edge cases

DATA-DB-003:
- Create scripts/cache_cli.py with three commands:
  - vault-dash cache stats: Show cache statistics
  - vault-dash cache list: List cached entries
  - vault-dash cache clear: Clear all cache files
- Add Makefile targets: cache-stats, cache-list, cache-clear
- Integrate with DatabentoHistoricalPriceSource methods
2026-03-29 12:00:30 +02:00
Bu5hm4nn
9a3b835c95 feat(DATA-DB-004): add Databento settings UI and independent scenario config
- Updated backtests page with Data Source card
  - Data source selector (databento/yfinance/synthetic)
  - Dataset dropdown (XNAS.BASIC, GLBX.MDP3)
  - Resolution dropdown (ohlcv-1d, ohlcv-1h)
  - Cost estimate display (placeholder for now)

- Added Scenario Configuration card
  - Underlying symbol selector (GLD/GC/XAU)
  - Start/end date inputs
  - Start price input (0 = auto-derive)
  - Underlying units, loan amount, margin call LTV

- BacktestPageService updates:
  - get_historical_prices() with data_source parameter
  - get_cost_estimate() for Databento cost estimation
  - get_cache_stats() for cache status display
  - Support for injected custom provider identity
  - DataSourceInfo for provider metadata

- BacktestSettingsRepository integration:
  - Load/save settings per workspace
  - Default values from BacktestSettings.create_default()

- Test update: TLT validation message changed to reflect
  new multi-symbol support (GLD, GC, XAU)
2026-03-29 11:12:11 +02:00
Bu5hm4nn
bf13ab5b46 feat(DATA-DB-001): add Databento historical price source for backtesting
- Add DatabentoHistoricalPriceSource implementing HistoricalPriceSource protocol
- Smart caching with Parquet storage and metadata tracking
- Auto symbol-to-dataset resolution (GLD→XNAS.BASIC, GC=F→GLBX.MDP3)
- Cache management with age threshold invalidation
- Cost estimation via metadata.get_cost()
- Add databento>=0.30.0 to requirements.txt
- Add DATABENTO_API_KEY to .env.example
- Full test coverage with 16 tests
2026-03-29 09:58:02 +02:00
Bu5hm4nn
554a41a060 refactor(BT-001C): share historical fixture provider 2026-03-27 21:41:50 +01:00
Bu5hm4nn
477514f838 feat(BT-002): add historical snapshot provider 2026-03-27 18:31:28 +01:00
Bu5hm4nn
94f3c1ef83 feat(CORE-001D): close remaining boundary cleanup slices 2026-03-26 17:27:44 +01:00
Bu5hm4nn
91f67cd414 fix(pre-alpha): preserve injected provider identity 2026-03-26 12:32:52 +01:00
Bu5hm4nn
52d943e614 fix(pre-alpha): preserve injected template services 2026-03-26 12:26:38 +01:00
Bu5hm4nn
d7117bb6a3 fix(pre-alpha): preserve injected backtest services 2026-03-26 12:18:39 +01:00
Bu5hm4nn
18fd0681ca refactor(pre-alpha): align preview and runtime fixture validation 2026-03-26 12:11:45 +01:00
Bu5hm4nn
68275c4d18 refactor(pre-alpha): fail closed on historical fixture bounds 2026-03-26 12:04:42 +01:00
Bu5hm4nn
f38d0a53a9 refactor(pre-alpha): fail closed on historical preview fallbacks 2026-03-26 11:55:45 +01:00
Bu5hm4nn
695f3d07ed fix(CORE-002C): explain undercollateralized historical seeds 2026-03-25 21:44:30 +01:00
Bu5hm4nn
c7c8654be7 feat(CORE-001C): type historical unit materialization 2026-03-24 22:30:36 +01:00
Bu5hm4nn
ff4e565ee6 feat(BT-003A): add event comparison page 2026-03-24 19:20:35 +01:00
Bu5hm4nn
d2d85bccdb feat(BT-001A): add backtest scenario runner page 2026-03-24 19:00:22 +01:00
Bu5hm4nn
8566cc203f feat(BT-003): add event preset backtest comparison 2026-03-24 17:49:58 +01:00
Bu5hm4nn
d4dc34d5ab feat(BT-001): add synthetic historical backtesting engine 2026-03-24 16:14:51 +01:00