Changeset 149
- Timestamp:
- 05/05/08 15:45:25 (5 months ago)
- Files:
-
- trunk/QLNet/QLNet/Instruments/CapFloor.cs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/QLNet/QLNet/Instruments/CapFloor.cs
r148 r149 271 271 NewtonSafe solver = new NewtonSafe(); 272 272 solver.setMaxEvaluations(maxEvaluations); 273 //return solver.solve(f, accuracy, guess, minVol, maxVol);274 return 0;273 return solver.solve(f, accuracy, guess, minVol, maxVol); 274 //return 0; 275 275 } 276 276 … … 377 377 public abstract class CapFloorEngine 378 378 : GenericEngine<CapFloor.Arguments, CapFloor.Results> {}; 379 380 public class ImpliedVolHelper 379 380 public class ImpliedVolHelper : ISolver1d 381 381 { 382 382 private IPricingEngine engine_; … … 392 392 targetValue_ = targetValue; 393 393 394 vol_ = new SimpleQuote(-1.0); 394 395 Handle<Quote> h = new Handle<Quote>(vol_); 395 396 engine_ = (IPricingEngine)new BlackCapFloorEngine(discountCurve_, h); … … 402 403 //Real derivative(Volatility x) const; 403 404 404 405 406 //double ImpliedVolHelper::operator()(Volatility x) const 407 //{ 408 // if (x!=vol_->value()) { 409 // vol_->setValue(x); 410 // engine_->calculate(); 411 // } 412 // return results_->value-targetValue_; 413 // } 414 415 public double derivative(double x) 405 public override double value(double x) 416 406 { 417 407 if (x!=vol_.value()) … … 420 410 engine_.calculate(); 421 411 } 412 413 return results_.value.Value -targetValue_; 414 } 415 416 public override double derivative(double x) 417 { 418 if (x!=vol_.value()) 419 { 420 vol_.setValue(x); 421 engine_.calculate(); 422 } 422 423 if ( ! results_.additionalResults.Keys.Contains("vega") ) 423 424 throw new Exception("vega not provided");