From 8e1aa4ad26811b4b246e5f25ccebea2e88185dfa Mon Sep 17 00:00:00 2001 From: Bu5hm4nn Date: Mon, 30 Mar 2026 08:42:07 +0200 Subject: [PATCH] fix(lint): remove unused imports and reformat with black --- app/core/calculations.py | 1 - app/domain/portfolio_math.py | 13 ++++++++----- app/domain/units.py | 16 ++++++++++++---- app/services/backtesting/ui_service.py | 1 - app/services/position_costs.py | 3 +-- tests/test_e2e_playwright.py | 8 ++++---- tests/test_page_validation.py | 5 +++-- 7 files changed, 28 insertions(+), 19 deletions(-) diff --git a/app/core/calculations.py b/app/core/calculations.py index 3e2fe4b..cbc5267 100644 --- a/app/core/calculations.py +++ b/app/core/calculations.py @@ -7,7 +7,6 @@ from app.core.pricing.black_scholes import ( DEFAULT_RISK_FREE_RATE, DEFAULT_VOLATILITY, BlackScholesInputs, - OptionType, black_scholes_price_and_greeks, ) from app.models.option import OptionContract diff --git a/app/domain/portfolio_math.py b/app/domain/portfolio_math.py index 6d3afe5..c8f97d5 100644 --- a/app/domain/portfolio_math.py +++ b/app/domain/portfolio_math.py @@ -412,11 +412,14 @@ def strategy_metrics_from_snapshot( ] scenario_price = spot * _pct_factor(scenario_pct) - scenario_gold_value = _as_money(gold_weight * PricePerWeight( - amount=scenario_price, - currency=BaseCurrency.USD, - per_unit=WeightUnit.OUNCE_TROY, - )) + scenario_gold_value = _as_money( + gold_weight + * PricePerWeight( + amount=scenario_price, + currency=BaseCurrency.USD, + per_unit=WeightUnit.OUNCE_TROY, + ) + ) current_gold_value = _as_money(gold_weight * current_spot) unhedged_equity = scenario_gold_value - loan_amount scenario_payoff_per_unit = _strategy_option_payoff_per_unit(strategy, spot, scenario_price) diff --git a/app/domain/units.py b/app/domain/units.py index a84ed91..0469d2e 100644 --- a/app/domain/units.py +++ b/app/domain/units.py @@ -260,16 +260,24 @@ class PricePerWeight: adjusted_weight = other.to_unit(self._per_unit_typed) return Money(amount=adjusted_weight.amount * self.amount, currency=self._currency_typed) if isinstance(other, Decimal): - return PricePerWeight(amount=self.amount * other, currency=self._currency_typed, per_unit=self._per_unit_typed) + return PricePerWeight( + amount=self.amount * other, currency=self._currency_typed, per_unit=self._per_unit_typed + ) if isinstance(other, int): - return PricePerWeight(amount=self.amount * Decimal(other), currency=self._currency_typed, per_unit=self._per_unit_typed) + return PricePerWeight( + amount=self.amount * Decimal(other), currency=self._currency_typed, per_unit=self._per_unit_typed + ) return NotImplemented def __rmul__(self, other: object) -> PricePerWeight: if isinstance(other, bool): return NotImplemented if isinstance(other, Decimal): - return PricePerWeight(amount=self.amount * other, currency=self._currency_typed, per_unit=self._per_unit_typed) + return PricePerWeight( + amount=self.amount * other, currency=self._currency_typed, per_unit=self._per_unit_typed + ) if isinstance(other, int): - return PricePerWeight(amount=self.amount * Decimal(other), currency=self._currency_typed, per_unit=self._per_unit_typed) + return PricePerWeight( + amount=self.amount * Decimal(other), currency=self._currency_typed, per_unit=self._per_unit_typed + ) return NotImplemented diff --git a/app/services/backtesting/ui_service.py b/app/services/backtesting/ui_service.py index 55f92ed..385b648 100644 --- a/app/services/backtesting/ui_service.py +++ b/app/services/backtesting/ui_service.py @@ -17,7 +17,6 @@ from app.models.backtest import ( from app.services.backtesting.databento_source import DatabentoHistoricalPriceSource, DatabentoSourceConfig from app.services.backtesting.fixture_source import ( FixtureBoundSyntheticHistoricalProvider, - SharedHistoricalFixtureSource, build_backtest_ui_fixture_source, ) from app.services.backtesting.historical_provider import ( diff --git a/app/services/position_costs.py b/app/services/position_costs.py index 0e0a39c..7240a94 100644 --- a/app/services/position_costs.py +++ b/app/services/position_costs.py @@ -86,8 +86,7 @@ def calculate_true_pnl( def get_default_premium_for_product( - underlying: str, - product_type: str = "default" + underlying: str, product_type: str = "default" ) -> tuple[Decimal | None, Decimal | None]: """Get default premium/spread for common gold products. diff --git a/tests/test_e2e_playwright.py b/tests/test_e2e_playwright.py index 6860815..ce694ac 100644 --- a/tests/test_e2e_playwright.py +++ b/tests/test_e2e_playwright.py @@ -159,7 +159,7 @@ def test_homepage_and_options_page_render() -> None: assert "RuntimeError" not in backtests_workspace_text assert "Server error" not in backtests_workspace_text assert "Traceback" not in backtests_workspace_text - + # Test backtest run by filling in fixture-supported dates page.get_by_label("Start date").fill("2024-01-02") page.get_by_label("End date").fill("2024-01-08") @@ -184,7 +184,7 @@ def test_homepage_and_options_page_render() -> None: # Page should render without runtime errors assert "RuntimeError" not in event_workspace_text assert "Traceback" not in event_workspace_text - + # Fill in value and run comparison page.get_by_label("Initial portfolio value").fill("100000") page.get_by_role("button", name="Run comparison").click() @@ -194,14 +194,14 @@ def test_homepage_and_options_page_render() -> None: # Should have results or error, but not runtime crash assert "RuntimeError" not in event_result_text assert "Traceback" not in event_result_text - + # Test preset selection page.get_by_label("Event preset").click() page.get_by_text("GLD January 2024 Drawdown", exact=True).click() page.wait_for_timeout(1000) event_preset_text = page.locator("body").inner_text(timeout=15000) assert "RuntimeError" not in event_preset_text - + page.goto(workspace_url, wait_until="domcontentloaded", timeout=30000) overview_text = page.locator("body").inner_text(timeout=15000) assert "Hedge Analysis" in overview_text diff --git a/tests/test_page_validation.py b/tests/test_page_validation.py index 6f165ba..c36bf3b 100644 --- a/tests/test_page_validation.py +++ b/tests/test_page_validation.py @@ -1,4 +1,5 @@ """Tests for page validation functions and constants.""" + from __future__ import annotations from datetime import date, timedelta @@ -218,7 +219,7 @@ class TestValidateDateRangeForSymbolBoundaryCases: """Test that start > end is caught before symbol-specific bounds.""" # Inverted range that's also before GLD launch start = date(2000, 1, 1) # Before GLD launch - end = date(1999, 1, 1) # Before start + end = date(1999, 1, 1) # Before start error = validate_date_range_for_symbol(start, end, "GLD") # Should get "start > end" error, not "before min date" error assert error is not None @@ -311,4 +312,4 @@ class TestValidateNumericInputs: error_low = validate_numeric_inputs(1000.0, 50000.0, 0.01) assert error_low is None error_high = validate_numeric_inputs(1000.0, 50000.0, 0.99) - assert error_high is None \ No newline at end of file + assert error_high is None