Assembla home | Assembla project page
 

Changeset 158

Show
Ignore:
Timestamp:
05/08/08 22:20:31 (2 months ago)
Author:
snovik
Message:

New: Started to work on Finite Differences for American Options

Files:

Legend:

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

    r155 r158  
    135135            //bermudanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( 
    136136            //             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()); 
    143142            Console.WriteLine("{0,-" + widths[3] + ":0.000000}", americanOption.NPV()); 
    144143 
  • trunk/QLNet/QLNet/Methods/Finitedifferences/StepCondition.cs

    r126 r158  
    2323 
    2424namespace QLNet { 
     25    public interface ICondition { 
     26        void applyTo(object o, double t); 
     27    } 
     28 
    2529    //! condition to be applied at every time step 
    2630    /*! \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) { } 
    2939    } 
    3040} 
  • trunk/QLNet/QLNet/Methods/Finitedifferences/cranknicolson.cs

    r152 r158  
    3939            : base(L, 0.5, bcs) { } 
    4040 
    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); 
    4343        } 
    4444    } 
  • trunk/QLNet/QLNet/Methods/Finitedifferences/finitedifferencemodel.cs

    r155 r158  
    3030 
    3131        // constructors 
    32         public FiniteDifferenceModel(IOperator L, List<BoundaryCondition<IOperator>> bcs) 
     32        public FiniteDifferenceModel(object L, object bcs) 
    3333            : 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) { 
    3535            evolver_ = (Evolver)new Evolver().factory(L, bcs); 
    3636            stoppingTimes_ = stoppingTimes; 
     
    5050        /*! solves the problem between the given times, applying a condition at every step. 
    5151            \warning being this a rollback, <tt>from</tt> must be a later time than <tt>to</tt>. */ 
    52         public void rollback(ref Vector a, 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) { 
    5454            rollbackImpl(ref a,from,to,steps, condition); 
    5555        } 
    5656 
    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) { 
    5858 
    5959            if (!(from >= to)) throw new ApplicationException("trying to roll back from " + from + " to " + to); 
     
    7272                        // perform a small step to stoppingTimes_[j]... 
    7373                        evolver_.setStep(now-stoppingTimes_[j]); 
    74                         evolver_.step(ref a,now); 
     74                        evolver_.step(ref a, now); 
    7575                        if (condition != null) 
    7676                            condition.applyTo(a,stoppingTimes_[j]); 
  • trunk/QLNet/QLNet/Methods/Finitedifferences/mixedscheme.cs

    r155 r158  
    2424namespace QLNet { 
    2525    public interface ISchemeFactory { 
    26         IMixedScheme factory(IOperator L, List<BoundaryCondition<IOperator>> bcs); 
     26        IMixedScheme factory(object L, object bcs); 
    2727    } 
    2828 
    2929    public interface IMixedScheme { 
    30         void step(ref Vector a, double t); 
     30        void step(ref object a, double t); 
    3131        void setStep(double dt); 
    3232    } 
     
    5858        } 
    5959 
    60         public void step(ref Vector a, double t) { 
     60        public void step(ref object o, double t) { 
     61            Vector a = (Vector)o; 
     62 
    6163            int i; 
    6264            for (i=0; i<bcs_.Count; i++) 
     
    8486                    bcs_[i].applyAfterSolving(a); 
    8587            } 
     88 
     89            o = a; 
    8690        } 
    8791 
  • trunk/QLNet/QLNet/Pricingengines/vanilla/FDEuropeanEngine.cs

    r155 r158  
    5656            // this is a workaround for pointers to avoid unsafe code 
    5757            // in the grid calculation Vector temp goes through many operations 
    58             Vector temp = prices_.values(); 
     58            object temp = prices_.values(); 
    5959            model.rollback(ref temp, getResidualTime(), 0, timeSteps_); 
    60             prices_.setValues(temp); 
     60            prices_.setValues((Vector)temp); 
    6161 
    6262            results_.value = prices_.valueAtCenter(); 
  • trunk/QLNet/QLNet/Pricingengines/vanilla/FDVanillaEngine.cs

    r131 r158  
    143143        } 
    144144    } 
     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    //} 
    145157} 
  • trunk/QLNet/QLNet/QLNet.csproj

    r156 r158  
    187187    <Compile Include="Methods\Finitedifferences\mixedscheme.cs" /> 
    188188    <Compile Include="Methods\Finitedifferences\OperatorFactory.cs" /> 
     189    <Compile Include="Methods\Finitedifferences\ParallelEvolver.cs" /> 
    189190    <Compile Include="Methods\Finitedifferences\pde.cs" /> 
    190191    <Compile Include="Methods\Finitedifferences\pdebsm.cs" /> 
     
    226227    <Compile Include="Pricingengines\vanilla\bjerksundstenslandengine.cs" /> 
    227228    <Compile Include="Pricingengines\vanilla\discretizedvanillaoption.cs" /> 
     229    <Compile Include="Pricingengines\vanilla\fdconditions.cs" /> 
    228230    <Compile Include="Pricingengines\vanilla\FDEuropeanEngine.cs" /> 
     231    <Compile Include="Pricingengines\vanilla\FDStepConditionEngine.cs" /> 
    229232    <Compile Include="Pricingengines\vanilla\FDVanillaEngine.cs" /> 
    230233    <Compile Include="Pricingengines\vanilla\Integralengine.cs" />