Assembla home | Assembla project page
 

Changeset 149

Show
Ignore:
Timestamp:
05/05/08 15:45:25 (5 months ago)
Author:
Vice
Message:

Volatility Cap&Floor test .

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QLNet/QLNet/Instruments/CapFloor.cs

    r148 r149  
    271271         NewtonSafe solver = new NewtonSafe(); 
    272272         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; 
    275275      } 
    276276 
     
    377377   public abstract class CapFloorEngine  
    378378        : GenericEngine<CapFloor.Arguments, CapFloor.Results> {}; 
    379     
    380    public class ImpliedVolHelper  
     379 
     380   public class ImpliedVolHelper : ISolver1d 
    381381   { 
    382382      private IPricingEngine engine_; 
     
    392392         targetValue_ = targetValue; 
    393393 
     394         vol_ = new SimpleQuote(-1.0); 
    394395         Handle<Quote> h = new Handle<Quote>(vol_); 
    395396         engine_ = (IPricingEngine)new BlackCapFloorEngine(discountCurve_, h); 
     
    402403      //Real derivative(Volatility x) const; 
    403404 
    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) 
    416406      { 
    417407         if (x!=vol_.value())  
     
    420410            engine_.calculate(); 
    421411         } 
     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         } 
    422423         if ( ! results_.additionalResults.Keys.Contains("vega") ) 
    423424            throw new Exception("vega not provided");