Changeset 159
- Timestamp:
- 05/09/08 20:08:07 (1 year ago)
- Files:
-
- trunk/QLNet/QLNet/Cashflows/Dividend.cs (added)
- trunk/QLNet/QLNet/Instruments/DividendVanillaOption.cs (added)
- trunk/QLNet/QLNet/Methods/Finitedifferences/AmericanCondition.cs (added)
- trunk/QLNet/QLNet/Methods/Finitedifferences/ParallelEvolver.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Methods/Finitedifferences/StepCondition.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Methods/Finitedifferences/finitedifferencemodel.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Pricingengines/vanilla/FDAmericanEngine.cs (added)
- trunk/QLNet/QLNet/Pricingengines/vanilla/FDMultiPeriodEngine.cs (added)
- trunk/QLNet/QLNet/Pricingengines/vanilla/FDStepConditionEngine.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Pricingengines/vanilla/FDVanillaEngine.cs (modified) (2 diffs)
- trunk/QLNet/QLNet/Pricingengines/vanilla/fdconditions.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Pricingengines/vanilla/fddividendengine.cs (added)
- trunk/QLNet/QLNet/QLNet.csproj (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/QLNet/QLNet/Methods/Finitedifferences/ParallelEvolver.cs
r158 r159 26 26 /*! \ingroup findiff */ 27 27 28 public class StepConditionSet<array_type> : List<StepCondition<array_type>>, ICondition where array_type : Vector { 28 public class StepConditionSet<array_type> : List<IStepCondition<array_type>>, IStepCondition<array_type> 29 where array_type : Vector { 29 30 public void applyTo(object o, double t) { 30 List< StepCondition<array_type>> a = o as List<StepCondition<array_type>>;31 List<IStepCondition<array_type>> a = o as List<IStepCondition<array_type>>; 31 32 for (int i=0; i < Count; i++) { 32 33 this[i].applyTo(a[i], t); trunk/QLNet/QLNet/Methods/Finitedifferences/StepCondition.cs
r158 r159 23 23 24 24 namespace QLNet { 25 public interface ICondition { 25 //! condition to be applied at every time step 26 /*! \ingroup findiff */ 27 public interface IStepCondition<array_type> where array_type : Vector { 26 28 void applyTo(object o, double t); 27 29 } 28 30 29 //! condition to be applied at every time step 30 /*! \ingroup findiff */ 31 public abstract class StepCondition<Dummy> : ICondition where Dummy : Vector { 32 public abstract void applyTo(object a, double t); 31 32 /* Abstract base class which allows step conditions to use both payoff and array functions */ 33 public class CurveDependentStepCondition<array_type> : IStepCondition<array_type> where array_type : Vector { 34 CurveWrapper curveItem_; 35 36 protected CurveDependentStepCondition(Option.Type type, double strike) { 37 curveItem_ = new PayoffWrapper(type, strike); 38 } 39 protected CurveDependentStepCondition(Payoff p) { 40 curveItem_ = new PayoffWrapper(p); 41 } 42 protected CurveDependentStepCondition(array_type a) { 43 curveItem_ = new ArrayWrapper(a); 44 } 45 46 protected double getValue(array_type a, int index) { 47 return curveItem_.getValue(a, index); 48 } 49 50 public void applyTo(object o, double t) { 51 Vector a = (Vector)o; 52 for (int i = 0; i < a.size(); i++) { 53 a[i] = applyToValue(a[i], getValue((array_type)o, i)); 54 } 55 } 56 57 protected virtual double applyToValue(double a, double b) { throw new NotImplementedException(); } 58 59 protected abstract class CurveWrapper { 60 public abstract double getValue(array_type a, int i); 61 } 62 63 protected class ArrayWrapper : CurveWrapper { 64 private array_type value_; 65 66 public ArrayWrapper(array_type a) { 67 value_ = a; 68 } 69 70 public override double getValue(array_type a, int i) { 71 return value_[i]; 72 } 73 } 74 75 protected class PayoffWrapper : CurveWrapper { 76 private Payoff payoff_; 77 78 public PayoffWrapper(Payoff p) { 79 payoff_ = p; 80 } 81 public PayoffWrapper(Option.Type type, double strike) { 82 payoff_ = new PlainVanillaPayoff(type, strike); 83 } 84 public override double getValue(array_type a, int i) { 85 return a[i]; 86 } 87 } 33 88 } 89 34 90 35 91 //! %null step condition 36 92 /*! \ingroup findiff */ 37 public class NullCondition<array_type> : StepCondition<array_type> where array_type : Vector {38 public overridevoid applyTo(object a, double t) { }93 public class NullCondition<array_type> : IStepCondition<array_type> where array_type : Vector { 94 public void applyTo(object a, double t) { } 39 95 } 40 96 } trunk/QLNet/QLNet/Methods/Finitedifferences/finitedifferencemodel.cs
r158 r159 51 51 \warning being this a rollback, <tt>from</tt> must be a later time than <tt>to</tt>. */ 52 52 public void rollback(ref object a, double from, double to, int steps) { rollbackImpl(ref a, from, to, steps, null); } 53 public void rollback(ref object a, double from, double to, int steps, I Conditioncondition) {53 public void rollback(ref object a, double from, double to, int steps, IStepCondition<Vector> condition) { 54 54 rollbackImpl(ref a,from,to,steps, condition); 55 55 } 56 56 57 private void rollbackImpl(ref object a, double from, double to, int steps, I Conditioncondition) {57 private void rollbackImpl(ref object a, double from, double to, int steps, IStepCondition<Vector> condition) { 58 58 59 59 if (!(from >= to)) throw new ApplicationException("trying to roll back from " + from + " to " + to); trunk/QLNet/QLNet/Pricingengines/vanilla/FDStepConditionEngine.cs
r158 r159 25 25 //! Finite-differences pricing engine for American-style vanilla options 26 26 public class FDStepConditionEngine : FDVanillaEngine { 27 protected StepCondition<Vector> stepCondition_;27 protected IStepCondition<Vector> stepCondition_; 28 28 protected SampledCurve prices_; 29 29 protected TridiagonalOperator controlOperator_; trunk/QLNet/QLNet/Pricingengines/vanilla/FDVanillaEngine.cs
r158 r159 67 67 } 68 68 69 protected v oid setupArguments(IPricingEngineArguments a) {69 protected virtual void setupArguments(IPricingEngineArguments a) { 70 70 OneAssetOption.Arguments args = a as OneAssetOption.Arguments; 71 71 if (args == null) throw new ApplicationException("incorrect argument type"); … … 144 144 } 145 145 146 //public class FDEngineAdapter<Base, Engine> : Base, Engine { 147 // public FDEngineAdapter(GeneralizedBlackScholesProcess process, Size timeSteps=100, Size gridPoints=100, bool timeDependent = false) 148 // : base(process, timeSteps, gridPoints,timeDependent) { 149 // process.registerWith(update); 150 // } 151 152 // protected override void calculate() { 153 // setupArguments(&(this->arguments_)); 154 // calculate(&(this->results_)); 155 // } 156 //} 146 147 public class FDEngineAdapter<Base, Engine> { 148 //Base optionBase; 149 150 ////public FDEngineAdapter(GeneralizedBlackScholesProcess process, Size timeSteps=100, Size gridPoints=100, bool timeDependent = false) 151 //public FDEngineAdapter(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) 152 // : base(process, timeSteps, gridPoints, timeDependent) { 153 // process.registerWith(update); 154 //} 155 156 //protected void calculate() { 157 // optionBase.setupArguments(arguments_); 158 // optionBase.calculate(results_); 159 //} 160 } 157 161 } trunk/QLNet/QLNet/Pricingengines/vanilla/fdconditions.cs
r158 r159 23 23 24 24 namespace QLNet { 25 //public class FDAmericanCondition<baseEngine> : FDVanillaEngine where baseEngine : FDVanillaEngine {26 //public FDAmericanCondition(GeneralizedBlackScholesProcess process,27 // Size timeSteps = 100, Size gridPoints = 100,28 // bool timeDependent = false)29 // : base(process, timeSteps, gridPoints, timeDependent) {}25 public class FDAmericanCondition<baseEngine> : FDVanillaEngine where baseEngine : FDVanillaEngine { 26 //public FDAmericanCondition(GeneralizedBlackScholesProcess process, 27 // int timeSteps = 100, int gridPoints = 100, bool timeDependent = false) 28 public FDAmericanCondition(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent) 29 : base(process, timeSteps, gridPoints, timeDependent) { } 30 30 31 // protected void initializeStepCondition() { 32 // baseEngine::stepCondition_ = 33 // boost::shared_ptr<StandardStepCondition>( 34 // new AmericanCondition(baseEngine::intrinsicValues_.values())); 35 // } 36 //} 31 protected void initializeStepCondition() { 32 // baseEngine::stepCondition_ = new AmericanCondition(baseEngine::intrinsicValues_.values()); 33 } 34 } 37 35 } trunk/QLNet/QLNet/QLNet.csproj
r158 r159 56 56 <Compile Include="Cashflows\DigitalCoupon.cs" /> 57 57 <Compile Include="Cashflows\DigitalIborCoupon.cs" /> 58 <Compile Include="Cashflows\Dividend.cs" /> 58 59 <Compile Include="Cashflows\FixedRateCoupon.cs" /> 59 60 <Compile Include="Cashflows\FloatingRateCoupon.cs" /> … … 116 117 <Compile Include="Instruments\Bonds\Zerocouponbond.cs" /> 117 118 <Compile Include="Instruments\CapFloor.cs" /> 119 <Compile Include="Instruments\DividendVanillaOption.cs" /> 118 120 <Compile Include="Instruments\EuropeanOption.cs" /> 119 121 <Compile Include="Instruments\fixedratebondforward.cs" /> … … 179 181 <Compile Include="Math\transformedgrid.cs" /> 180 182 <Compile Include="Math\Vector.cs" /> 183 <Compile Include="Methods\Finitedifferences\AmericanCondition.cs" /> 181 184 <Compile Include="Methods\Finitedifferences\BoundaryCondition.cs" /> 182 185 <Compile Include="Methods\Finitedifferences\bsmoperator.cs" /> … … 227 230 <Compile Include="Pricingengines\vanilla\bjerksundstenslandengine.cs" /> 228 231 <Compile Include="Pricingengines\vanilla\discretizedvanillaoption.cs" /> 232 <Compile Include="Pricingengines\vanilla\FDAmericanEngine.cs" /> 229 233 <Compile Include="Pricingengines\vanilla\fdconditions.cs" /> 234 <Compile Include="Pricingengines\vanilla\fddividendengine.cs" /> 230 235 <Compile Include="Pricingengines\vanilla\FDEuropeanEngine.cs" /> 236 <Compile Include="Pricingengines\vanilla\FDMultiPeriodEngine.cs" /> 231 237 <Compile Include="Pricingengines\vanilla\FDStepConditionEngine.cs" /> 232 238 <Compile Include="Pricingengines\vanilla\FDVanillaEngine.cs" />