Commit Graph

239 Commits

Author SHA1 Message Date
Bu5hm4nn
e45c935eb6 test: bypass Turnstile network calls in test env
Some checks failed
CI / lint (push) Successful in 9s
CI / type-check (push) Successful in 16s
CI / test (push) Failing after 2m17s
2026-04-08 16:53:40 +02:00
Bu5hm4nn
eb262189cf test: force Turnstile test mode in CI
Some checks failed
CI / lint (push) Successful in 9s
CI / type-check (push) Successful in 16s
CI / test (push) Failing after 2m7s
2026-04-08 16:47:37 +02:00
Bu5hm4nn
52f883fa8f ci: retrigger after Gitea runner image sync
Some checks failed
CI / lint (push) Successful in 9s
CI / type-check (push) Successful in 15s
CI / test (push) Failing after 2m17s
2026-04-08 16:39:15 +02:00
Bu5hm4nn
fa03f375a4 ci: use noble playwright image on Gitea
Some checks failed
CI / lint (push) Successful in 10s
CI / type-check (push) Successful in 16s
CI / test (push) Failing after 2m10s
2026-04-08 16:25:10 +02:00
Bu5hm4nn
78ff775aa5 ci: migrate workflows from Forgejo to Gitea Actions
Some checks failed
CI / lint (push) Successful in 45s
CI / type-check (push) Successful in 50s
CI / test (push) Failing after 5s
2026-04-08 12:41:29 +02:00
Bu5hm4nn
2a49a10d9a ci: install dev dependencies and pin Playwright 1.58.0 2026-04-07 14:40:30 +02:00
Bu5hm4nn
3c2b507cf8 ci: Run playwright tests in proper image 2026-04-07 14:09:02 +02:00
Bu5hm4nn
4ca4752bfb ci: Don't re-run CI for deploy 2026-04-07 12:52:45 +02:00
Bu5hm4nn
b2bc4db41a Improve backtest lazy loading and test automation 2026-04-07 12:18:50 +02:00
Bu5hm4nn
ccc10923d9 chore: ignore local cache artifacts and uv lockfile 2026-04-07 10:13:58 +02:00
Bu5hm4nn
faa06a106e feat: add LTV unhedged column to daily results table
- Add LTV unhedged column before LTV hedged column
- Update both render_result and render_job_result tables
- Show both hedged and unhedged LTV for comparison
2026-04-06 22:28:03 +02:00
Bu5hm4nn
b546b59b33 feat: split portfolio chart into stacked bar chart above candle chart
- Create separate portfolio stacked bar chart (underlying + option value)
- Place portfolio chart above candle chart with same X axis alignment
- Make candle chart double height (h-[48rem] vs h-48 for portfolio)
- Portfolio chart shows underlying (gray) + option value (blue) as stacked bars
- Charts now render above the daily results table
2026-04-06 18:50:41 +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
aff4df325d feat: defer entry spot derivation to backtest run (BT-005)
- Remove async refresh_workspace_seeded_units from date change handlers
- Date changes now only call on_form_change() (updates cost estimates, marks results stale)
- Entry spot is derived only when user clicks Run button
- Form remains responsive during configuration
- No more API errors when changing dates while configuring other fields
2026-04-06 11:14:51 +02:00
Bu5hm4nn
4af7a09c6e feat: add option contracts to overview, fix default dates, add roadmap items
- Move option contracts from daily results table to overview cards (constant throughout backtest)
- Fix default dates to March 2026 (2026-03-02 to 2026-03-25)
- Add BT-004 backlog item: candlestick chart with portfolio value line on secondary axis
- Add BT-005 backlog item: defer entry spot derivation to backtest run (not on every date change)
2026-04-05 09:24:25 +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
1e567775f9 fix: also catch RuntimeError in derive_entry_spot exception handler
Databento can raise RuntimeError for API key issues, but derive_entry_spot
only caught ValueError and KeyError. This ensures Databento errors are
properly caught and displayed to the user.
2026-04-04 22:53:06 +02:00
Bu5hm4nn
4e9a610452 fix: update render_job_result to use correct result field names
The job serialization was fixed to use new field names, but the UI render
function was still using old field names (total_pnl, hedging_cost, etc.)
which don't exist anymore. Now uses:
- start_value, end_value_hedged_net, total_hedge_cost from summary_metrics
- template_results[0].daily_path for daily results table
- Added margin call metrics display
2026-04-04 22:40:39 +02:00
Bu5hm4nn
2de5966a4e refactor: move Playwright tests to tests/e2e/ with proper conftest
- Move conftest_playwright.py to tests/e2e/conftest.py for proper pytest discovery
- Move test_playwright_server.py to tests/e2e/
- Server fixture starts FastAPI with uvicorn for isolated E2E testing
2026-04-04 18:30:40 +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
99c7911b78 test: add e2e test for actual backtest scenario execution
- Add test_backtest_scenario_runs_and_displays_results that:
  - Creates workspace and navigates to backtests page
  - Selects Synthetic data source (uses deterministic fixture data)
  - Fills fixture-supported dates (2024-01-02 to 2024-01-08)
  - Fills scenario parameters (units, loan, LTV)
  - Runs backtest and verifies results display
  - Checks for Start value, End value, Daily Results table
  - Verifies no runtime errors

- Fix existing backtests page tests to create workspace first:
  - test_backtest_page_loads_with_valid_databento_dates
  - test_backtest_page_handles_invalid_dates_gracefully
  - Backtests page requires workspace_id in URL

- Add TODO comment about date_range_hint not updating for Databento
  on initial render (separate bug to fix)
2026-04-03 14:10:37 +02:00
Bu5hm4nn
dbd6e103c0 fix: pin black to 26.3.1 across all environments
- Pin black version in requirements-dev.txt (was >=24.0.0)
- Update pre-commit to use black 26.3.1 with Python 3.12
- Add language_version: python3.12 to pre-commit black hook
- Reformat files with new black version for consistency
2026-04-01 13:58:49 +02:00
Bu5hm4nn
6bcf78e5df style: format UI files and remove lint excludes
- Remove app/components/ and app/pages/ from ruff/black excludes
- Pre-commit reformatted multi-line strings for consistency
- All files now follow the same code style
2026-04-01 13:55:55 +02:00
Bu5hm4nn
9af654d9f2 feat: add pre-commit hooks for linting
- Add .pre-commit-config.yaml with ruff and black hooks
- Add pre-commit git hook script as fallback
- Add pre-commit to requirements-dev.txt

Running 'pre-commit install' will auto-lint on every commit.
2026-04-01 13:50:39 +02:00
Bu5hm4nn
79d19f14ef style: format backtesting files with black 2026-04-01 13:49:21 +02:00
Bu5hm4nn
f69e4b2d29 fix(ci): standardize runs-on labels and remove unused docker.io
- Changed all jobs from 'runs-on: docker' to 'runs-on: [linux, docker]'
  to match ci.yaml pattern and runner labels configuration
- Removed unnecessary docker.io package from deploy job since Docker
  commands run on remote SSH host, not inside CI container
- Aligned with Forgejo runner config having both 'linux' and 'docker' labels
2026-04-01 13:46:31 +02:00
Bu5hm4nn
ec16b76378 chore: trigger CI 2026-04-01 12:35:20 +02:00
Bu5hm4nn
c2e62972c6 chore: trigger CI 2026-04-01 12:28:42 +02:00
Bu5hm4nn
fa2b5c63da fix(ci): move env block inside container for Forgejo v12
Forgejo Actions requires env to be under container: block, not at job level.
This fixes:
- Unknown Property env
- Unknown Property steps
- Unknown Variable Access env
2026-04-01 12:24:52 +02:00
Bu5hm4nn
7ffa04709c fix(ci): use single label runs-on for Forgejo runner v12 compatibility
Runner v12.7.3 uses labels: [docker linux debian ubuntu-latest].
Changed from 'runs-on: [linux, docker]' to 'runs-on: docker' to fix:
- 'runs-on key not defined' error
- 'github.ref == refs/heads/main evaluated to false' error
2026-04-01 12:18:19 +02:00
Bu5hm4nn
a0f245b212 chore: re-trigger CI 2026-04-01 12:09:56 +02:00
Bu5hm4nn
02193c0131 chore: re-trigger CI 2026-04-01 12:09:30 +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
66d6eb3df2 style: format test file with black 2026-03-31 23:55:16 +02:00
Bu5hm4nn
6f9e31a69e chore: trigger CI rebuild 2026-03-31 23:49:45 +02:00
Bu5hm4nn
c203dd9a83 fix(test): remove unused variable in e2e test 2026-03-31 23:40:12 +02:00
Bu5hm4nn
2b500dfcb3 fix(backtest): run backtest asynchronously to prevent WebSocket timeout
- Use run.io_bound() from NiceGUI to run Databento API calls in background thread
- Add loading state to Run Backtest button
- Show notification when backtest starts and completes
- Remove loading state on completion/error

This prevents 'Connection lost' errors when the backtest takes longer than the WebSocket timeout.
2026-03-31 23:31:07 +02:00
Bu5hm4nn
c650cec159 perf(backtest): reduce Databento API calls on input changes
- on_form_change: Only update cost estimate, skip expensive derive_entry_spot
- Only call derive_entry_spot on date changes (start/end inputs)
- Other inputs (template, units, loan, LTV) just mark results stale
- This reduces lag from constant API polling
2026-03-30 20:58:36 +02:00
Bu5hm4nn
aa22766ae3 test(e2e): add backtest page regression tests for CORE-003
- test_backtest_page_loads_with_valid_databento_dates: Verifies page loads with valid default dates
- test_backtest_page_handles_invalid_dates_gracefully: Ensures validation errors instead of 500

These tests catch regressions where:
- Default dates are before dataset availability
- Databento API errors cause 500 instead of validation
- Date validation is missing or broken
2026-03-30 17:52:09 +02:00
Bu5hm4nn
69109c9e36 fix(backtest): pass data_source to validate_preview_inputs in validate_current_scenario 2026-03-30 17:50:47 +02:00
Bu5hm4nn
b161c51109 fix(backtest): handle Databento errors gracefully during page load
- Set default dates to 2024-07-01 to 2024-12-31 (valid for XNAS.BASIC)
- Catch all exceptions during entry spot derivation, not just ValueError
- Don't auto-run backtest on page load - let user configure first
- Use recent GLD price (~30) as fallback
2026-03-30 14:48:08 +02:00
Bu5hm4nn
79980c33ec feat(backtest): add dataset-specific date validation and better error handling
- Add DATABENTO_DATASET_MIN_DATES for XNAS.BASIC (2024-07-01) and GLBX.MDP3 (2010-01-01)
- Validate start date against dataset minimum before running backtest
- Parse Databento API errors and show user-friendly messages
- Update date range hint to show dataset-specific availability
- Catch BentoClientError and show appropriate warning tone
2026-03-30 14:37:04 +02:00