Ejemplo n.º 1
0
        public void calculate()
        {
            setupArguments(arguments_);
            setGridLimits();
            initializeInitialCondition();
            initializeOperator();
            initializeBoundaryConditions();

            var model = new FiniteDifferenceModel <CrankNicolson <TridiagonalOperator> >(finiteDifferenceOperator_, BCs_);

            prices_ = (SampledCurve)intrinsicValues_.Clone();

            // this is a workaround for pointers to avoid unsafe code
            // in the grid calculation Vector temp goes through many operations
            object temp = prices_.values();

            model.rollback(ref temp, getResidualTime(), 0, timeSteps_);
            prices_.setValues((Vector)temp);

            results_.value = prices_.valueAtCenter();
            results_.delta = prices_.firstDerivativeAtCenter();
            results_.gamma = prices_.secondDerivativeAtCenter();
            results_.theta = Utils.blackScholesTheta(process_,
                                                     results_.value.GetValueOrDefault(),
                                                     results_.delta.GetValueOrDefault(),
                                                     results_.gamma.GetValueOrDefault());
            results_.additionalResults["priceCurve"] = prices_;
        }
Ejemplo n.º 2
0
        public FDEuropeanEngine(GeneralizedBlackScholesProcess process, int timeSteps, int gridPoints, bool timeDependent)
            : base(process, timeSteps, gridPoints, timeDependent)
        {
            prices_ = new SampledCurve(gridPoints);

            process.registerWith(update);
        }
 public void swap(SampledCurve arg0)
 {
     NQuantLibcPINVOKE.SampledCurve_swap(swigCPtr, SampledCurve.getCPtr(arg0));
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 4
0
        public void testConstruction()
        {
            //("Testing sampled curve construction...");

            SampledCurve curve = new SampledCurve(Utils.BoundedGrid(-10.0, 10.0, 100));
            FSquared     f2    = new FSquared();

            curve.sample(f2.value);
            double expected = 100.0;

            if (Math.Abs(curve.value(0) - expected) > 1e-5)
            {
                Assert.Fail("function sampling failed");
            }

            curve.setValue(0, 2.0);
            if (Math.Abs(curve.value(0) - 2.0) > 1e-5)
            {
                Assert.Fail("curve value setting failed");
            }

            Vector value = curve.values();

            value[1] = 3.0;
            if (Math.Abs(curve.value(1) - 3.0) > 1e-5)
            {
                Assert.Fail("curve value grid failed");
            }

            curve.shiftGrid(10.0);
            if (Math.Abs(curve.gridValue(0) - 0.0) > 1e-5)
            {
                Assert.Fail("sample curve shift grid failed");
            }
            if (Math.Abs(curve.value(0) - 2.0) > 1e-5)
            {
                Assert.Fail("sample curve shift grid - value failed");
            }

            curve.sample(f2.value);
            curve.regrid(Utils.BoundedGrid(0.0, 20.0, 200));
            double tolerance = 1.0e-2;

            for (int i = 0; i < curve.size(); i++)
            {
                double grid = curve.gridValue(i);
                double v    = curve.value(i);
                double exp  = f2.value(grid);
                if (Math.Abs(v - exp) > tolerance)
                {
                    Assert.Fail("sample curve regriding failed" +
                                "\n    at " + (i + 1) + " point " + "(x = " + grid + ")" +
                                "\n    grid value: " + v +
                                "\n    expected:   " + exp);
                }
            }
        }
Ejemplo n.º 5
0
        public SampledCurve priceCurve()
        {
            SampledCurve ret = new SampledCurve(NQuantLibcPINVOKE.VanillaOption_priceCurve(swigCPtr), true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SampledCurve obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Ejemplo n.º 7
0
 public SampledCurve priceCurve() {
   SampledCurve ret = new SampledCurve(NQuantLibcPINVOKE.DividendVanillaOption_priceCurve(swigCPtr), true);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Ejemplo n.º 8
0
 public void swap(SampledCurve arg0) {
   NQuantLibcPINVOKE.SampledCurve_swap(swigCPtr, SampledCurve.getCPtr(arg0));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Ejemplo n.º 9
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SampledCurve obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }