Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions quantwave-py/python/quantwave/backtest_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ def as_dict(self) -> dict[str, float]:

def keys(self):
return self.as_dict().keys()

def __getitem__(self, key: str):
return getattr(self, key)

def __contains__(self, key: object) -> bool:
# Without this, ``"x" in metrics`` falls back to integer-index iteration
# via __getitem__ (getattr(self, 0)) and raises TypeError.
return isinstance(key, str) and key in self.as_dict()

def __iter__(self):
return iter(self.keys())

@dataclass(frozen=True)
class BacktestStats:
"""Core summary statistics from a backtest run."""
Expand All @@ -50,6 +58,12 @@ def as_dict(self) -> dict[str, float]:

def keys(self):
return self.as_dict().keys()

def __getitem__(self, key: str):
return getattr(self, key)

def __contains__(self, key: object) -> bool:
return isinstance(key, str) and key in self.as_dict()

def __iter__(self):
return iter(self.keys())
24 changes: 24 additions & 0 deletions quantwave-py/src/indicators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,30 @@ pub struct GaussianHmmParamsPy {
/// Per-state λ (empty → 1.0 per state, Gaussian mode).
pub lambdas: Vec<f64>,
}
#[pymethods]
impl GaussianHmmParamsPy {
// Constructable from Python (input params, not a read-only result record):
// `qw.GaussianHmmParamsPy(n_states, delta, gamma_flat, means, stds, lambdas=[])`.
#[new]
#[pyo3(signature = (n_states, delta, gamma_flat, means, stds, lambdas = Vec::new()))]
pub fn new(
n_states: u32,
delta: Vec<f64>,
gamma_flat: Vec<f64>,
means: Vec<f64>,
stds: Vec<f64>,
lambdas: Vec<f64>,
) -> Self {
Self {
n_states,
delta,
gamma_flat,
means,
stds,
lambdas,
}
}
}

#[pyclass(get_all)]
#[derive(Clone)]
Expand Down
Loading