deriweave-python 0.3.0__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ """Composable derivatives pricing through the native DeriWeave C++20 engine."""
2
+ from datetime import date
3
+ from typing import Optional, Sequence
4
+
5
+ from . import _core
6
+ from .composition import (
7
+ Asset, ValueExpression, Spot, Variance, Constant, Scaled, Call, Put, Digital,
8
+ Basket, Average, WorstOf, BestOf, Conditional, CashflowRule, ComposedProduct,
9
+ Product, DiscreteBarrier, SpotControl, Market, BlackScholes, Heston, Merton,
10
+ Kou, VarianceGamma, NIG, price, ExerciseTime, simulate_path, evaluate,
11
+ evaluate_expression, simulation_dates, has_finite_spot_moment,
12
+ )
13
+
14
+ from .structured import (
15
+ AutocallObservation, AutocallProduct, ExerciseOpportunity, Bermudan, American,
16
+ train_longstaff_schwartz,
17
+ )
18
+
19
+ LsmSettings = _core.LsmSettings
20
+ ExercisePolicy = _core.ExercisePolicy
21
+ MarketPath = _core.MarketPath
22
+ Cashflow = _core.Cashflow
23
+ build_info = _core.build_info
24
+ PricingResult = _core.PricingResult
25
+ SimulationSettings = _core.SimulationSettings
26
+ __version__ = "0.3.0"
27
+
28
+
29
+ def _parts(valuation_date: Optional[date]) -> tuple[int, int, int]:
30
+ d = date.today() if valuation_date is None else valuation_date
31
+ if not isinstance(d, date):
32
+ raise TypeError("valuation_date must be a datetime.date or None")
33
+ return d.year, d.month, d.day
34
+
35
+
36
+ def european(
37
+ option_type: str,
38
+ *,
39
+ spot: float,
40
+ strike: float,
41
+ volatility: float,
42
+ rate: float,
43
+ maturity: float,
44
+ dividend_yield: float = 0.0,
45
+ settings: Optional[SimulationSettings] = None,
46
+ valuation_date: Optional[date] = None,
47
+ ) -> PricingResult:
48
+ """Price a European call or put under one-asset Black-Scholes."""
49
+ year, month, day = _parts(valuation_date)
50
+ return _core.price_european_bs(
51
+ option_type, spot, strike, volatility, rate, maturity, dividend_yield,
52
+ year, month, day, settings if settings is not None else SimulationSettings(),
53
+ )
54
+
55
+
56
+ def asian(
57
+ option_type: str,
58
+ *,
59
+ spot: float,
60
+ strike: float,
61
+ volatility: float,
62
+ rate: float,
63
+ maturity: float,
64
+ observation_dates: Sequence[float],
65
+ dividend_yield: float = 0.0,
66
+ settings: Optional[SimulationSettings] = None,
67
+ valuation_date: Optional[date] = None,
68
+ ) -> PricingResult:
69
+ """Price a fixed-strike arithmetic Asian call or put with discrete monitoring."""
70
+ year, month, day = _parts(valuation_date)
71
+ return _core.price_asian_bs(
72
+ option_type, spot, strike, volatility, rate, maturity, dividend_yield,
73
+ list(observation_dates), year, month, day,
74
+ settings if settings is not None else SimulationSettings(),
75
+ )
76
+
77
+
78
+ def basket(
79
+ option_type: str,
80
+ *,
81
+ spots: Sequence[float],
82
+ volatilities: Sequence[float],
83
+ dividend_yields: Sequence[float],
84
+ weights: Sequence[float],
85
+ correlation: Sequence[Sequence[float]],
86
+ strike: float,
87
+ rate: float,
88
+ maturity: float,
89
+ settings: Optional[SimulationSettings] = None,
90
+ valuation_date: Optional[date] = None,
91
+ ) -> PricingResult:
92
+ """Price a weighted basket call or put under correlated Black-Scholes assets."""
93
+ year, month, day = _parts(valuation_date)
94
+ return _core.price_basket_bs(
95
+ option_type, list(spots), list(volatilities), list(dividend_yields),
96
+ list(weights), [list(row) for row in correlation], strike, rate,
97
+ maturity, year, month, day,
98
+ settings if settings is not None else SimulationSettings(),
99
+ )
100
+
101
+
102
+ __all__ = [
103
+ "PricingResult", "SimulationSettings", "european", "asian", "basket",
104
+ "Asset", "ValueExpression", "Spot", "Variance", "Constant", "Scaled", "Call", "Put",
105
+ "Digital", "Basket", "Average", "WorstOf", "BestOf", "Conditional",
106
+ "CashflowRule", "ComposedProduct", "Product", "DiscreteBarrier", "SpotControl",
107
+ "AutocallObservation", "AutocallProduct", "ExerciseOpportunity", "Bermudan", "American",
108
+ "ExerciseTime", "LsmSettings", "ExercisePolicy", "train_longstaff_schwartz",
109
+ "MarketPath", "Cashflow", "simulate_path", "evaluate", "evaluate_expression",
110
+ "simulation_dates", "build_info", "has_finite_spot_moment",
111
+ "Market", "BlackScholes", "Heston", "Merton", "Kou", "VarianceGamma", "NIG", "price",
112
+ ]
Binary file
deriweave_py/_core.pyi ADDED
@@ -0,0 +1,108 @@
1
+ from typing import Any, Sequence
2
+
3
+ class SimulationSettings:
4
+ n_simulations: int
5
+ max_time_step: float
6
+ seed: int
7
+ antithetic: bool
8
+ use_openmp: bool
9
+ num_threads: int
10
+ use_control_variate: bool
11
+ block_size: int
12
+ def __init__(self, n_simulations: int = 20000, max_time_step: float = 1.,
13
+ seed: int = 42, antithetic: bool = True, use_openmp: bool = False,
14
+ num_threads: int = 1, use_control_variate: bool = False,
15
+ block_size: int = 1024) -> None: ...
16
+
17
+ class PricingResult:
18
+ @property
19
+ def price(self) -> float: ...
20
+ @property
21
+ def variance(self) -> float: ...
22
+ @property
23
+ def standard_error(self) -> float: ...
24
+ @property
25
+ def confidence_interval_95(self) -> tuple[float, float]: ...
26
+ @property
27
+ def observation_count(self) -> int: ...
28
+ @property
29
+ def trajectory_count(self) -> int: ...
30
+ @property
31
+ def beta(self) -> float: ...
32
+ @property
33
+ def control_requested(self) -> bool: ...
34
+ @property
35
+ def control_applied(self) -> bool: ...
36
+
37
+ class LsmSettings:
38
+ training_paths: int
39
+ seed: int
40
+ max_time_step: float
41
+ polynomial_degree: int
42
+ max_exercise_time_step: float
43
+ def __init__(self, training_paths: int = 20000, seed: int = 7919,
44
+ max_time_step: float = 1/52, polynomial_degree: int = 2,
45
+ max_exercise_time_step: float = 1/52) -> None: ...
46
+
47
+ class ExercisePolicy:
48
+ @property
49
+ def exercise_dates(self) -> list[float]: ...
50
+ @property
51
+ def required_dates(self) -> list[float]: ...
52
+ @property
53
+ def training_seed(self) -> int: ...
54
+ @property
55
+ def training_path_count(self) -> int: ...
56
+ @property
57
+ def state_dimension(self) -> int: ...
58
+ def fitted_degree(self, exercise_index: int) -> int | None: ...
59
+ def fitted_basis_size(self, exercise_index: int) -> int: ...
60
+
61
+ class Cashflow:
62
+ @property
63
+ def payment_date(self) -> float: ...
64
+ @property
65
+ def amount(self) -> float: ...
66
+
67
+ class MarketPath:
68
+ def __init__(self, dates: Sequence[float], assets: Sequence[str], prices: Any,
69
+ variances: Any = None) -> None: ...
70
+ @property
71
+ def dates(self) -> list[float]: ...
72
+ @property
73
+ def assets(self) -> list[str]: ...
74
+ @property
75
+ def prices(self) -> Any: ...
76
+ @property
77
+ def variances(self) -> Any | None: ...
78
+ @property
79
+ def has_variances(self) -> bool: ...
80
+ def spot_at(self, asset: str, at: float) -> float: ...
81
+ def variance_at(self, asset: str, at: float) -> float: ...
82
+
83
+ def build_info() -> dict[str, Any]: ...
84
+ def price_composed(product: dict, market: dict, model: dict,
85
+ settings: SimulationSettings, control: dict | None = None) -> PricingResult: ...
86
+ def price_exercise_policy(policy: ExercisePolicy, market: dict, model: dict,
87
+ settings: SimulationSettings, control: dict | None) -> PricingResult: ...
88
+ def train_longstaff_schwartz(contract: dict, market: dict, model: dict,
89
+ settings: LsmSettings) -> ExercisePolicy: ...
90
+ def simulate_path(market: dict, model: dict, dates: Sequence[float], seed: int) -> MarketPath: ...
91
+ def evaluate(product: dict, path: MarketPath) -> list[Cashflow]: ...
92
+ def evaluate_expression(value: dict, path: MarketPath) -> float: ...
93
+ def simulation_dates(product: dict, settings: SimulationSettings,
94
+ control: dict | None = None) -> list[float]: ...
95
+ def price_european_bs(option_type: str, spot: float, strike: float, volatility: float,
96
+ rate: float, maturity: float, dividend_yield: float,
97
+ year: int, month: int, day: int, settings: SimulationSettings) -> PricingResult: ...
98
+ def price_asian_bs(option_type: str, spot: float, strike: float, volatility: float,
99
+ rate: float, maturity: float, dividend_yield: float,
100
+ observation_dates: Sequence[float], year: int, month: int, day: int,
101
+ settings: SimulationSettings) -> PricingResult: ...
102
+ def price_basket_bs(option_type: str, spots: Sequence[float], volatilities: Sequence[float],
103
+ dividend_yields: Sequence[float], weights: Sequence[float],
104
+ correlation: Sequence[Sequence[float]], strike: float, rate: float,
105
+ maturity: float, year: int, month: int, day: int,
106
+ settings: SimulationSettings) -> PricingResult: ...
107
+
108
+ def has_finite_spot_moment(model: dict, market: dict, asset: str, order: float) -> bool: ...