Changeset 158
- Timestamp:
- 05/08/08 22:20:31 (2 months ago)
- Files:
-
- trunk/QLNet/EquityOption/EquityOption.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Methods/Finitedifferences/ParallelEvolver.cs (added)
- trunk/QLNet/QLNet/Methods/Finitedifferences/StepCondition.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Methods/Finitedifferences/cranknicolson.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Methods/Finitedifferences/finitedifferencemodel.cs (modified) (3 diffs)
- trunk/QLNet/QLNet/Methods/Finitedifferences/mixedscheme.cs (modified) (3 diffs)
- trunk/QLNet/QLNet/Pricingengines/vanilla/FDEuropeanEngine.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Pricingengines/vanilla/FDStepConditionEngine.cs (added)
- trunk/QLNet/QLNet/Pricingengines/vanilla/FDVanillaEngine.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Pricingengines/vanilla/fdconditions.cs (added)
- trunk/QLNet/QLNet/QLNet.csproj (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/QLNet/EquityOption/EquityOption.cs
r155 r158 135 135 //bermudanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( 136 136 // new FDBermudanEngine(bsmProcess,timeSteps,timeSteps-1))); 137 //americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( 138 // new FDAmericanEngine(bsmProcess,timeSteps,timeSteps-1))); 139 140 Console.Write("{0,-" + widths[0] + "}", method); 141 Console.Write("{0,-" + widths[1] + ":0.000000}", europeanOption.NPV()); 142 Console.Write("{0,-" + widths[2] + ":0.000000}", bermudanOption.NPV()); 137 //americanOption.setPricingEngine(new FDAmericanEngine(bsmProcess,timeSteps,timeSteps-1)); 138 139 Console.Write("{0,-" + widths[0] + "}", method); 140 Console.Write("{0,-" + widths[1] + ":0.000000}", europeanOption.NPV()); 141 //Console.Write("{0,-" + widths[2] + ":0.000000}", bermudanOption.NPV()); 143 142 Console.WriteLine("{0,-" + widths[3] + ":0.000000}", americanOption.NPV()); 144 143 trunk/QLNet/QLNet/Methods/Finitedifferences/StepCondition.cs
r126 r158 23 23 24 24 namespace QLNet { 25 public interface ICondition { 26 void applyTo(object o, double t); 27 } 28 25 29 //! condition to be applied at every time step 26 30 /*! \ingroup findiff */ 27 public abstract class StepCondition { 28 public abstract void applyTo(Vector a, double t); 31 public abstract class StepCondition<Dummy> : ICondition where Dummy : Vector { 32 public abstract void applyTo(object a, double t); 33 } 34 35 //! %null step condition 36 /*! \ingroup findiff */ 37 public class NullCondition<array_type> : StepCondition<array_type> where array_type : Vector { 38 public override void applyTo(object a, double t) { } 29 39 } 30 40 } trunk/QLNet/QLNet/Methods/Finitedifferences/cranknicolson.cs
r152 r158 39 39 : base(L, 0.5, bcs) { } 40 40 41 public IMixedScheme factory( IOperator L, List<BoundaryCondition<IOperator>>bcs) {42 return new CrankNicolson<Operator>((Operator)L, bcs);41 public IMixedScheme factory(object L, object bcs) { 42 return new CrankNicolson<Operator>((Operator)L, (List<BoundaryCondition<IOperator>>)bcs); 43 43 } 44 44 } trunk/QLNet/QLNet/Methods/Finitedifferences/finitedifferencemodel.cs
r155 r158 30 30 31 31 // constructors 32 public FiniteDifferenceModel( IOperator L, List<BoundaryCondition<IOperator>>bcs)32 public FiniteDifferenceModel(object L, object bcs) 33 33 : this(L, bcs, new List<double>()) { } 34 public FiniteDifferenceModel( IOperator L, List<BoundaryCondition<IOperator>>bcs, List<double> stoppingTimes) {34 public FiniteDifferenceModel(object L, object bcs, List<double> stoppingTimes) { 35 35 evolver_ = (Evolver)new Evolver().factory(L, bcs); 36 36 stoppingTimes_ = stoppingTimes; … … 50 50 /*! solves the problem between the given times, applying a condition at every step. 51 51 \warning being this a rollback, <tt>from</tt> must be a later time than <tt>to</tt>. */ 52 public void rollback(ref Vectora, double from, double to, int steps) { rollbackImpl(ref a, from, to, steps, null); }53 public void rollback(ref Vector a, double from, double to, int steps, StepCondition condition) {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, ICondition condition) { 54 54 rollbackImpl(ref a,from,to,steps, condition); 55 55 } 56 56 57 private void rollbackImpl(ref Vector a, double from, double to, int steps, StepCondition condition) {57 private void rollbackImpl(ref object a, double from, double to, int steps, ICondition condition) { 58 58 59 59 if (!(from >= to)) throw new ApplicationException("trying to roll back from " + from + " to " + to); … … 72 72 // perform a small step to stoppingTimes_[j]... 73 73 evolver_.setStep(now-stoppingTimes_[j]); 74 evolver_.step(ref a, now);74 evolver_.step(ref a, now); 75 75 if (condition != null) 76 76 condition.applyTo(a,stoppingTimes_[j]); trunk/QLNet/QLNet/Methods/Finitedifferences/mixedscheme.cs
r155 r158 24 24 namespace QLNet { 25 25 public interface ISchemeFactory { 26 IMixedScheme factory( IOperator L, List<BoundaryCondition<IOperator>>bcs);26 IMixedScheme factory(object L, object bcs); 27 27 } 28 28 29 29 public interface IMixedScheme { 30 void step(ref Vectora, double t);30 void step(ref object a, double t); 31 31 void setStep(double dt); 32 32 } … … 58 58 } 59 59 60 public void step(ref Vector a, double t) { 60 public void step(ref object o, double t) { 61 Vector a = (Vector)o; 62 61 63 int i; 62 64 for (i=0; i<bcs_.Count; i++) … … 84 86 bcs_[i].applyAfterSolving(a); 85 87 } 88 89 o = a; 86 90 } 87 91 trunk/QLNet/QLNet/Pricingengines/vanilla/FDEuropeanEngine.cs
r155 r158 56 56 // this is a workaround for pointers to avoid unsafe code 57 57 // in the grid calculation Vector temp goes through many operations 58 Vectortemp = prices_.values();58 object temp = prices_.values(); 59 59 model.rollback(ref temp, getResidualTime(), 0, timeSteps_); 60 prices_.setValues( temp);60 prices_.setValues((Vector)temp); 61 61 62 62 results_.value = prices_.valueAtCenter(); trunk/QLNet/QLNet/Pricingengines/vanilla/FDVanillaEngine.cs
r131 r158 143 143 } 144 144 } 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 //} 145 157 } trunk/QLNet/QLNet/QLNet.csproj
r156 r158 187 187 <Compile Include="Methods\Finitedifferences\mixedscheme.cs" /> 188 188 <Compile Include="Methods\Finitedifferences\OperatorFactory.cs" /> 189 <Compile Include="Methods\Finitedifferences\ParallelEvolver.cs" /> 189 190 <Compile Include="Methods\Finitedifferences\pde.cs" /> 190 191 <Compile Include="Methods\Finitedifferences\pdebsm.cs" /> … … 226 227 <Compile Include="Pricingengines\vanilla\bjerksundstenslandengine.cs" /> 227 228 <Compile Include="Pricingengines\vanilla\discretizedvanillaoption.cs" /> 229 <Compile Include="Pricingengines\vanilla\fdconditions.cs" /> 228 230 <Compile Include="Pricingengines\vanilla\FDEuropeanEngine.cs" /> 231 <Compile Include="Pricingengines\vanilla\FDStepConditionEngine.cs" /> 229 232 <Compile Include="Pricingengines\vanilla\FDVanillaEngine.cs" /> 230 233 <Compile Include="Pricingengines\vanilla\Integralengine.cs" />