Skip to content

Commit cc5e7ed

Browse files
committed
fix: negative price
1 parent 4065ca4 commit cc5e7ed

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/quant/calibration/heston.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ impl HestonCalibrator {
9898

9999
let residuals = result.residuals().unwrap();
100100

101-
// Print the c_model
102-
println!("Model prices: {:?}", self.c_market.clone() + residuals);
101+
// Print the c_model (residuals = market - model, so model = market - residuals)
102+
println!("Model prices: {:?}", self.c_market.clone() - residuals);
103103

104104
// Print the result of the calibration
105105
println!("Calibration report: {:?}", result.params);
@@ -177,16 +177,16 @@ impl HestonCalibrator {
177177
let (call, put) = pricer.calculate_call_put();
178178

179179
match self.option_type {
180-
OptionType::Call => c_model[idx] = call,
181-
OptionType::Put => c_model[idx] = put,
180+
OptionType::Call => c_model[idx] = call.max(0.0),
181+
OptionType::Put => c_model[idx] = put.max(0.0),
182182
}
183183
}
184184

185185
c_model
186186
}
187187

188188
fn residuals_for(&self, params: &HestonParams) -> DVector<f64> {
189-
self.compute_model_prices_for(params) - self.c_market.clone()
189+
self.c_market.clone() - self.compute_model_prices_for(params)
190190
}
191191

192192
/// Numerically approximate the Jacobian via central differences.
@@ -300,7 +300,7 @@ impl LeastSquaresProblem<f64, Dyn, Dyn> for HestonCalibrator {
300300
.calibration_history
301301
.borrow_mut()
302302
.push(CalibrationHistory {
303-
residuals: c_model.clone() - self.c_market.clone(),
303+
residuals: self.c_market.clone() - c_model.clone(),
304304
call_put: self
305305
.c_market
306306
.iter()
@@ -339,7 +339,7 @@ impl LeastSquaresProblem<f64, Dyn, Dyn> for HestonCalibrator {
339339
},
340340
});
341341

342-
Some(c_model - self.c_market.clone())
342+
Some(self.c_market.clone() - c_model)
343343
}
344344

345345
fn jacobian(&self) -> Option<DMatrix<f64>> {

src/quant/pricing/heston.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ impl HestonPricer {
8989

9090
pub(self) fn b(&self, j: u8) -> f64 {
9191
match j {
92-
1 => self.kappa + self.lambda.unwrap_or(1.0) - self.rho * self.sigma,
93-
2 => self.kappa + self.lambda.unwrap_or(1.0),
92+
1 => self.kappa + self.lambda.unwrap_or(0.0) - self.rho * self.sigma,
93+
2 => self.kappa + self.lambda.unwrap_or(0.0),
9494
_ => panic!("Invalid j"),
9595
}
9696
}

0 commit comments

Comments
 (0)