Fix linting issues: line length, import sorting, unused variables
- Set ruff/black line length to 120 - Reformatted code with black - Fixed import ordering with ruff - Disabled lint for UI component files with long CSS strings - Updated pyproject.toml with proper tool configuration
This commit is contained in:
@@ -40,7 +40,11 @@ __all__ = [
|
||||
]
|
||||
|
||||
try: # pragma: no cover - optional QuantLib modules
|
||||
from .american_pricing import AmericanOptionInputs, AmericanPricingResult, american_option_price_and_greeks
|
||||
from .american_pricing import (
|
||||
AmericanOptionInputs,
|
||||
AmericanPricingResult,
|
||||
american_option_price_and_greeks,
|
||||
)
|
||||
from .volatility import implied_volatility
|
||||
except ImportError: # pragma: no cover - optional dependency
|
||||
AmericanOptionInputs = None
|
||||
|
||||
@@ -105,15 +105,9 @@ def _american_price(
|
||||
calendar = ql.NullCalendar()
|
||||
|
||||
spot_handle = ql.QuoteHandle(ql.SimpleQuote(used_spot))
|
||||
dividend_curve = ql.YieldTermStructureHandle(
|
||||
ql.FlatForward(valuation_ql, params.dividend_yield, day_count)
|
||||
)
|
||||
risk_free_curve = ql.YieldTermStructureHandle(
|
||||
ql.FlatForward(valuation_ql, used_rate, day_count)
|
||||
)
|
||||
volatility_curve = ql.BlackVolTermStructureHandle(
|
||||
ql.BlackConstantVol(valuation_ql, calendar, used_vol, day_count)
|
||||
)
|
||||
dividend_curve = ql.YieldTermStructureHandle(ql.FlatForward(valuation_ql, params.dividend_yield, day_count))
|
||||
risk_free_curve = ql.YieldTermStructureHandle(ql.FlatForward(valuation_ql, used_rate, day_count))
|
||||
volatility_curve = ql.BlackVolTermStructureHandle(ql.BlackConstantVol(valuation_ql, calendar, used_vol, day_count))
|
||||
|
||||
process = ql.BlackScholesMertonProcess(
|
||||
spot_handle,
|
||||
@@ -129,7 +123,9 @@ def _american_price(
|
||||
return float(option.NPV())
|
||||
|
||||
|
||||
def american_option_price_and_greeks(params: AmericanOptionInputs) -> AmericanPricingResult:
|
||||
def american_option_price_and_greeks(
|
||||
params: AmericanOptionInputs,
|
||||
) -> AmericanPricingResult:
|
||||
"""Price an American option and estimate Greeks with finite differences.
|
||||
|
||||
Notes:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
from dataclasses import dataclass
|
||||
from datetime import date, timedelta
|
||||
import math
|
||||
from typing import Any, Literal
|
||||
|
||||
try: # pragma: no cover - optional dependency
|
||||
@@ -97,8 +97,7 @@ def _analytic_black_scholes(params: BlackScholesInputs, option_type: OptionType)
|
||||
sigma = params.volatility
|
||||
sqrt_t = math.sqrt(t)
|
||||
d1 = (
|
||||
math.log(params.spot / params.strike)
|
||||
+ (params.risk_free_rate - params.dividend_yield + 0.5 * sigma**2) * t
|
||||
math.log(params.spot / params.strike) + (params.risk_free_rate - params.dividend_yield + 0.5 * sigma**2) * t
|
||||
) / (sigma * sqrt_t)
|
||||
d2 = d1 - sigma * sqrt_t
|
||||
disc_r = math.exp(-params.risk_free_rate * t)
|
||||
@@ -126,7 +125,14 @@ def _analytic_black_scholes(params: BlackScholesInputs, option_type: OptionType)
|
||||
|
||||
gamma = (disc_q * pdf_d1) / (params.spot * sigma * sqrt_t)
|
||||
vega = params.spot * disc_q * pdf_d1 * sqrt_t
|
||||
return PricingResult(price=float(price), delta=float(delta), gamma=float(gamma), theta=float(theta), vega=float(vega), rho=float(rho))
|
||||
return PricingResult(
|
||||
price=float(price),
|
||||
delta=float(delta),
|
||||
gamma=float(gamma),
|
||||
theta=float(theta),
|
||||
vega=float(vega),
|
||||
rho=float(rho),
|
||||
)
|
||||
|
||||
|
||||
def black_scholes_price_and_greeks(params: BlackScholesInputs) -> PricingResult:
|
||||
@@ -143,12 +149,8 @@ def black_scholes_price_and_greeks(params: BlackScholesInputs) -> PricingResult:
|
||||
calendar = ql.NullCalendar()
|
||||
|
||||
spot_handle = ql.QuoteHandle(ql.SimpleQuote(params.spot))
|
||||
dividend_curve = ql.YieldTermStructureHandle(
|
||||
ql.FlatForward(valuation_ql, params.dividend_yield, day_count)
|
||||
)
|
||||
risk_free_curve = ql.YieldTermStructureHandle(
|
||||
ql.FlatForward(valuation_ql, params.risk_free_rate, day_count)
|
||||
)
|
||||
dividend_curve = ql.YieldTermStructureHandle(ql.FlatForward(valuation_ql, params.dividend_yield, day_count))
|
||||
risk_free_curve = ql.YieldTermStructureHandle(ql.FlatForward(valuation_ql, params.risk_free_rate, day_count))
|
||||
volatility = ql.BlackVolTermStructureHandle(
|
||||
ql.BlackConstantVol(valuation_ql, calendar, params.volatility, day_count)
|
||||
)
|
||||
|
||||
@@ -93,12 +93,8 @@ def implied_volatility(
|
||||
calendar = ql.NullCalendar()
|
||||
|
||||
spot_handle = ql.QuoteHandle(ql.SimpleQuote(spot))
|
||||
dividend_curve = ql.YieldTermStructureHandle(
|
||||
ql.FlatForward(valuation_ql, dividend_yield, day_count)
|
||||
)
|
||||
risk_free_curve = ql.YieldTermStructureHandle(
|
||||
ql.FlatForward(valuation_ql, risk_free_rate, day_count)
|
||||
)
|
||||
dividend_curve = ql.YieldTermStructureHandle(ql.FlatForward(valuation_ql, dividend_yield, day_count))
|
||||
risk_free_curve = ql.YieldTermStructureHandle(ql.FlatForward(valuation_ql, risk_free_rate, day_count))
|
||||
volatility_curve = ql.BlackVolTermStructureHandle(
|
||||
ql.BlackConstantVol(valuation_ql, calendar, initial_guess, day_count)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user