Assembla home | Assembla project page
 

Changeset 159

Show
Ignore:
Timestamp:
05/09/08 20:08:07 (1 year ago)
Author:
snovik
Message:

New: More American Option classes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QLNet/QLNet/Methods/Finitedifferences/ParallelEvolver.cs

    r158 r159  
    2626    /*! \ingroup findiff */ 
    2727 
    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 { 
    2930        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>>; 
    3132            for (int i=0; i < Count; i++) { 
    3233                this[i].applyTo(a[i], t); 
  • trunk/QLNet/QLNet/Methods/Finitedifferences/StepCondition.cs

    r158 r159  
    2323 
    2424namespace 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 { 
    2628        void applyTo(object o, double t); 
    2729    } 
    2830 
    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        } 
    3388    } 
     89 
    3490 
    3591    //! %null step condition 
    3692    /*! \ingroup findiff */ 
    37     public class NullCondition<array_type> : StepCondition<array_type> where array_type : Vector { 
    38         public override void 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) { } 
    3995    } 
    4096} 
  • trunk/QLNet/QLNet/Methods/Finitedifferences/finitedifferencemodel.cs

    r158 r159  
    5151            \warning being this a rollback, <tt>from</tt> must be a later time than <tt>to</tt>. */ 
    5252        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) { 
     53        public void rollback(ref object a, double from, double to, int steps, IStepCondition<Vector> condition) { 
    5454            rollbackImpl(ref a,from,to,steps, condition); 
    5555        } 
    5656 
    57         private void rollbackImpl(ref object a, double from, double to, int steps, ICondition condition) { 
     57        private void rollbackImpl(ref object a, double from, double to, int steps, IStepCondition<Vector> condition) { 
    5858 
    5959            if (!(from >= to)) throw new ApplicationException("trying to roll back from " + from + " to " + to); 
  • trunk/QLNet/QLNet/Pricingengines/vanilla/FDStepConditionEngine.cs

    r158 r159  
    2525    //! Finite-differences pricing engine for American-style vanilla options 
    2626    public class FDStepConditionEngine : FDVanillaEngine { 
    27         protected StepCondition<Vector> stepCondition_; 
     27        protected IStepCondition<Vector> stepCondition_; 
    2828        protected SampledCurve prices_; 
    2929        protected TridiagonalOperator controlOperator_; 
  • trunk/QLNet/QLNet/Pricingengines/vanilla/FDVanillaEngine.cs

    r158 r159  
    6767        } 
    6868 
    69         protected void setupArguments(IPricingEngineArguments a) { 
     69        protected virtual void setupArguments(IPricingEngineArguments a) { 
    7070            OneAssetOption.Arguments args = a as OneAssetOption.Arguments; 
    7171            if (args == null) throw new ApplicationException("incorrect argument type"); 
     
    144144    } 
    145145 
    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    } 
    157161} 
  • trunk/QLNet/QLNet/Pricingengines/vanilla/fdconditions.cs

    r158 r159  
    2323 
    2424namespace 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) {
    3030       
    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    } 
    3735} 
  • trunk/QLNet/QLNet/QLNet.csproj

    r158 r159  
    5656    <Compile Include="Cashflows\DigitalCoupon.cs" /> 
    5757    <Compile Include="Cashflows\DigitalIborCoupon.cs" /> 
     58    <Compile Include="Cashflows\Dividend.cs" /> 
    5859    <Compile Include="Cashflows\FixedRateCoupon.cs" /> 
    5960    <Compile Include="Cashflows\FloatingRateCoupon.cs" /> 
     
    116117    <Compile Include="Instruments\Bonds\Zerocouponbond.cs" /> 
    117118    <Compile Include="Instruments\CapFloor.cs" /> 
     119    <Compile Include="Instruments\DividendVanillaOption.cs" /> 
    118120    <Compile Include="Instruments\EuropeanOption.cs" /> 
    119121    <Compile Include="Instruments\fixedratebondforward.cs" /> 
     
    179181    <Compile Include="Math\transformedgrid.cs" /> 
    180182    <Compile Include="Math\Vector.cs" /> 
     183    <Compile Include="Methods\Finitedifferences\AmericanCondition.cs" /> 
    181184    <Compile Include="Methods\Finitedifferences\BoundaryCondition.cs" /> 
    182185    <Compile Include="Methods\Finitedifferences\bsmoperator.cs" /> 
     
    227230    <Compile Include="Pricingengines\vanilla\bjerksundstenslandengine.cs" /> 
    228231    <Compile Include="Pricingengines\vanilla\discretizedvanillaoption.cs" /> 
     232    <Compile Include="Pricingengines\vanilla\FDAmericanEngine.cs" /> 
    229233    <Compile Include="Pricingengines\vanilla\fdconditions.cs" /> 
     234    <Compile Include="Pricingengines\vanilla\fddividendengine.cs" /> 
    230235    <Compile Include="Pricingengines\vanilla\FDEuropeanEngine.cs" /> 
     236    <Compile Include="Pricingengines\vanilla\FDMultiPeriodEngine.cs" /> 
    231237    <Compile Include="Pricingengines\vanilla\FDStepConditionEngine.cs" /> 
    232238    <Compile Include="Pricingengines\vanilla\FDVanillaEngine.cs" />