Changeset 161
- Timestamp:
- 05/10/08 12:40:56 (2 months ago)
- Files:
-
- trunk/QLNet/QLNet/Methods/Finitedifferences/ShoutCondition.cs (added)
- trunk/QLNet/QLNet/Pricingengines/vanilla/FDMultiPeriodEngine.cs (modified) (4 diffs)
- trunk/QLNet/QLNet/Pricingengines/vanilla/FDStepConditionEngine.cs (modified) (4 diffs)
- trunk/QLNet/QLNet/Pricingengines/vanilla/FDVanillaEngine.cs (modified) (4 diffs)
- trunk/QLNet/QLNet/Pricingengines/vanilla/fdconditions.cs (modified) (2 diffs)
- trunk/QLNet/QLNet/QLNet.csproj (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/QLNet/QLNet/Pricingengines/vanilla/FDMultiPeriodEngine.cs
r160 r161 23 23 24 24 namespace QLNet { 25 public class FDMultiPeriodEngine : FD VanillaEngine {25 public class FDMultiPeriodEngine : FDConditionEngineTemplate { 26 26 protected List<Event> events_; 27 27 protected List<double> stoppingTimes_; 28 28 protected int timeStepPerPeriod_; 29 protected SampledCurve prices_;30 31 protected IStepCondition<Vector> stepCondition_;32 29 protected FiniteDifferenceModel<CrankNicolson<TridiagonalOperator>> model_; 33 30 34 31 public FDMultiPeriodEngine() { } // required for generics 35 public override IOptionPricingEngine factory(GeneralizedBlackScholesProcess process,36 int timeSteps, int gridPoints, bool timeDependent) {37 return new FDMultiPeriodEngine(process, timeSteps, gridPoints, timeDependent);38 }39 32 40 33 //protected FDMultiPeriodEngine(GeneralizedBlackScholesProcess process, … … 57 50 protected virtual void executeIntermediateStep(int step) { throw new NotSupportedException(); } 58 51 59 protected virtualvoid initializeStepCondition() {52 protected override void initializeStepCondition() { 60 53 stepCondition_ = new NullCondition<Vector>(); 61 54 } … … 69 62 } 70 63 71 #region IOptionPricingEngine72 64 public override void setupArguments(IPricingEngineArguments a) { 73 65 base.setupArguments(a); … … 173 165 results.additionalResults.Add("priceCurve", prices_); 174 166 } 175 176 #endregion177 167 } 178 168 } trunk/QLNet/QLNet/Pricingengines/vanilla/FDStepConditionEngine.cs
r160 r161 24 24 namespace QLNet { 25 25 //! Finite-differences pricing engine for American-style vanilla options 26 public class FDStepConditionEngine : FDVanillaEngine { 27 protected IStepCondition<Vector> stepCondition_; 28 protected SampledCurve prices_; 26 public class FDStepConditionEngine : FDConditionEngineTemplate { 29 27 protected TridiagonalOperator controlOperator_; 30 28 protected List<BoundaryCondition<IOperator>> controlBCs_; … … 33 31 // required for generics 34 32 public FDStepConditionEngine() { } 35 public override IOptionPricingEngine factory(GeneralizedBlackScholesProcess process,36 int timeSteps, int gridPoints, bool timeDependent) {37 return new FDStepConditionEngine(process, timeSteps, gridPoints, timeDependent);38 }39 40 33 41 34 //public FDStepConditionEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, … … 46 39 controlPrices_ = new SampledCurve(gridPoints); 47 40 } 48 49 protected virtual void initializeStepCondition() { }50 41 51 42 public override void calculate(IPricingEngineResults r) { … … 114 105 + black.gamma(spot); 115 106 results.additionalResults.Add("priceCurve", prices_); 116 } 117 107 } 118 108 } 119 109 } trunk/QLNet/QLNet/Pricingengines/vanilla/FDVanillaEngine.cs
r160 r161 24 24 namespace QLNet { 25 25 //! Finite-differences pricing engine for BSM one asset options 26 /*! The name is a misnomer as this is a base class for any finite 27 difference scheme. Its main job is to handle grid layout. 26 /*! The name is a misnomer as this is a base class for any finite difference scheme. Its main job is to handle grid layout. 28 27 29 28 \ingroup vanillaengines 30 29 */ 31 public class FDVanillaEngine : IOptionPricingEngine{30 public class FDVanillaEngine { 32 31 protected GeneralizedBlackScholesProcess process_; 33 32 protected int timeSteps_, gridPoints_; … … 48 47 const double safetyZoneFactor_ = 1.1; 49 48 50 // required for generics 49 // required for generics and template iheritance 51 50 public FDVanillaEngine() { } 52 public virtual IOptionPricingEngine factory(GeneralizedBlackScholesProcess process,53 int timeSteps, int gridPoints, bool timeDependent) {51 public virtual FDVanillaEngine factory(GeneralizedBlackScholesProcess process, 52 int timeSteps, int gridPoints, bool timeDependent) { 54 53 return new FDVanillaEngine(process, timeSteps, gridPoints, timeDependent); 55 54 } … … 141 140 } 142 141 143 #region IOptionPricingEngine144 142 public virtual void setupArguments(IPricingEngineArguments a) { 145 143 OneAssetOption.Arguments args = a as OneAssetOption.Arguments; … … 151 149 } 152 150 public virtual void calculate(IPricingEngineResults r) { throw new NotSupportedException(); } 153 #endregion154 151 } 155 152 156 153 157 public interface IOptionPricingEngine {158 void calculate(IPricingEngineResults r);159 void setupArguments(IPricingEngineArguments a);160 IOptionPricingEngine factory(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent);161 }162 163 154 public class FDEngineAdapter<Base, Engine, ArgumentsType, ResultsType> : FDVanillaEngine 164 where Base : IOptionPricingEngine, new()155 where Base : FDVanillaEngine, new() 165 156 where Engine : IGenericEngine<ArgumentsType, ResultsType> 166 157 where ArgumentsType : IPricingEngineArguments, new() 167 158 where ResultsType : IPricingEngineResults, new() { 168 159 160 // a wrap-up of base engine 169 161 Base optionBase; 170 162 trunk/QLNet/QLNet/Pricingengines/vanilla/fdconditions.cs
r160 r161 23 23 24 24 namespace QLNet { 25 public class FDAmericanCondition<baseEngine> : FDVanillaEngine, IOptionPricingEngine 26 where baseEngine : IOptionPricingEngine, new() { 27 baseEngine engine_; 25 // this is template version to serve as base for FDStepConditionEngine and FDMultiPeriodEngine 26 public class FDConditionEngineTemplate : FDVanillaEngine { 27 #region Common definitions for deriving classes 28 protected IStepCondition<Vector> stepCondition_; 29 protected SampledCurve prices_; 30 protected virtual void initializeStepCondition() { throw new NotSupportedException(); } 31 #endregion 28 32 29 33 // required for generics 30 public FDAmericanCondition() { } 31 public override IOptionPricingEngine factory(GeneralizedBlackScholesProcess process, 34 public FDConditionEngineTemplate() { } 35 36 public FDConditionEngineTemplate(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) 37 : base(process, timeSteps, gridPoints, timeDependent) { } 38 } 39 40 // this is template version to serve as base for FDAmericanCondition and FDShoutCondition 41 public class FDConditionTemplate<baseEngine> : FDConditionEngineTemplate where baseEngine : FDVanillaEngine, new() { 42 #region Common definitions for deriving classes 43 protected baseEngine engine_; 44 public override FDVanillaEngine factory(GeneralizedBlackScholesProcess process, 32 45 int timeSteps, int gridPoints, bool timeDependent) { 33 46 engine_ = (baseEngine)new baseEngine().factory(process, timeSteps, gridPoints, timeDependent); … … 35 48 } 36 49 50 // below is a wrap-up of baseEngine instead of c++ template inheritance 51 public override void setupArguments(IPricingEngineArguments a) { engine_.setupArguments(a); } 52 public override void calculate(IPricingEngineResults r) { engine_.calculate(r); } 53 #endregion 54 55 // required for generics 56 public FDConditionTemplate() { } 57 58 public FDConditionTemplate(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) 59 : base(process, timeSteps, gridPoints, timeDependent) { 60 // init engine 61 factory(process, timeSteps, gridPoints, timeDependent); 62 } 63 } 64 65 66 public class FDAmericanCondition<baseEngine> : FDConditionTemplate<baseEngine> 67 where baseEngine : FDVanillaEngine, new() { 68 69 // required for generics 70 public FDAmericanCondition() { } 71 37 72 //public FDAmericanCondition(GeneralizedBlackScholesProcess process, 38 73 // int timeSteps = 100, int gridPoints = 100, bool timeDependent = false) 39 public FDAmericanCondition(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) { 74 public FDAmericanCondition(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) 75 : base(process, timeSteps, gridPoints, timeDependent) { } 76 77 protected override void initializeStepCondition() { 78 stepCondition_ = new AmericanCondition(intrinsicValues_.values()); 40 79 } 80 } 41 81 42 protected void initializeStepCondition() {43 // stepCondition_ = new AmericanCondition(intrinsicValues_.values());44 }45 82 46 public override void setupArguments(IPricingEngineArguments a) { 47 engine_.setupArguments(a); 48 } 49 public override void calculate(IPricingEngineResults r) { 50 engine_.calculate(r); 83 public class FDShoutCondition<baseEngine> : FDConditionTemplate<baseEngine> 84 where baseEngine : FDVanillaEngine, new() { 85 86 // required for generics 87 public FDShoutCondition() { } 88 89 //public FDShoutCondition(GeneralizedBlackScholesProcess process, 90 // Size timeSteps = 100, Size gridPoints = 100, bool timeDependent = false) 91 public FDShoutCondition(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) 92 : base(process, timeSteps, gridPoints, timeDependent) { } 93 94 protected override void initializeStepCondition() { 95 double residualTime = getResidualTime(); 96 double riskFreeRate = process_.riskFreeRate().link.zeroRate(residualTime, Compounding.Continuous).rate(); 97 98 stepCondition_ = new ShoutCondition(intrinsicValues_.values(), residualTime, riskFreeRate); 51 99 } 52 100 } trunk/QLNet/QLNet/QLNet.csproj
r159 r161 194 194 <Compile Include="Methods\Finitedifferences\pdebsm.cs" /> 195 195 <Compile Include="Methods\Finitedifferences\pdeshortrate.cs" /> 196 <Compile Include="Methods\Finitedifferences\ShoutCondition.cs" /> 196 197 <Compile Include="Methods\Finitedifferences\StepCondition.cs" /> 197 198 <Compile Include="Methods\Finitedifferences\TridiagonalOperator.cs" />