use serde::{Deserialize, Serialize};
use crate::calibration::config::OptimizationConfig;
use std::any::Any;
#[derive(Debug, Clone)]
pub struct MarketDataRow {
pub option_type: String,
pub strike_price: f64,
pub underlying_price: f64,
pub years_to_exp: f64,
pub market_iv: f64,
pub vega: f64,
pub expiration: i64,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct FixedParameters {
pub r: f64,
pub q: f64,
}
impl Default for FixedParameters {
fn default() -> Self {
Self { r: 0.02, q: 0.0 }
}
}
pub trait ModelCalibrator: Send + Sync {
fn model_name(&self) -> &str;
fn param_count(&self) -> usize;
fn param_bounds(&self) -> &[(f64, f64)];
fn evaluate_objective(&self, x: &[f64], data: &[MarketDataRow]) -> f64;
fn price_options(
&self,
market_data: &[MarketDataRow],
best_params: &[f64],
config: &OptimizationConfig,
) -> Vec<PricingResult>;
fn param_names(&self) -> Vec<&str>;
fn set_prev_solution(&mut self, _prev_solution: Vec<f64>) {
}
fn set_temporal_reg_lambda(&mut self, _lambda: f64) {
}
fn expand_bounds_if_needed(
&mut self,
_params: &[f64],
_proximity_threshold: f64,
_expansion_factor: f64,
) -> bool {
false
}
fn as_any(&self) -> &dyn Any;
}
#[derive(Debug, Clone)]
pub struct PricingResult {
pub option_type: String,
pub strike_price: f64,
pub underlying_price: f64,
pub years_to_exp: f64,
pub model_price: f64,
pub model_iv: f64,
}