Package org.jquantlib.methods.finitedifferences

Examples of org.jquantlib.methods.finitedifferences.TridiagonalOperator


        final BoundaryConditionSet<BoundaryCondition<TridiagonalOperator>> bcSet = new BoundaryConditionSet<BoundaryCondition<TridiagonalOperator>>();
        final StepConditionSet<Array> conditionSet = new StepConditionSet<Array>();

        prices =  new SampledCurve(intrinsicValues);
        controlPrices = new SampledCurve(intrinsicValues);
        controlOperator =  new TridiagonalOperator(finiteDifferenceOperator);
        controlBCs.add(bcS.get(0));
        controlBCs.add(bcS.get(1));

        operatorSet.add(finiteDifferenceOperator);
        operatorSet.add(controlOperator);
View Full Code Here


        final BoundaryConditionSet<BoundaryCondition<TridiagonalOperator>> bcSet = new BoundaryConditionSet<BoundaryCondition<TridiagonalOperator>>();
        final StepConditionSet<Array> conditionSet = new StepConditionSet<Array>();

        prices =  new SampledCurve(intrinsicValues);
        controlPrices = new SampledCurve(intrinsicValues);
        controlOperator =  new TridiagonalOperator(finiteDifferenceOperator);
        controlBCs.add(bcS.get(0));
        controlBCs.add(bcS.get(1));

        operatorSet.add(finiteDifferenceOperator);
        operatorSet.add(controlOperator);
View Full Code Here

        high.set(0, 7);
        high.set(1, 9);


        final TridiagonalOperator t = new TridiagonalOperator(low, mid, high);

        final Array rhs = new Array(3);
        rhs.set(0, 7);
        rhs.set(1, 8);
        rhs.set(2, 7);

        final Array solved = t.solveFor(rhs);
        final Array expected = new Array(new double[] { 20.0, -33.285714285714285, 13.428571428571429 });

        for (int i=0; i<3; i++) {
            final double error = Math.abs(solved.get(i) - expected.get(i));
            if (error > 1e-15) {
View Full Code Here

                S[i] = (vy_[i+1] - vy_[i])/dx[i];
            }

            // first derivative approximation
            if (da==CubicInterpolation.DerivativeApprox.Spline) {
                final TridiagonalOperator L = new TridiagonalOperator(n);
                for (int i=1; i<n-1; ++i) {
                    L.setMidRow(i, dx[i], 2.0*(dx[i]+dx[i-1]), dx[i-1]);
                    tmp[i] = 3.0*(dx[i]*S[i-1] + dx[i-1]*S[i]);
                }

                // left boundary condition
                switch (leftType) {
                  case NotAKnot:
                    // ignoring end condition value
                    L.setFirstRow(dx[1]*(dx[1]+dx[0]),
                                  (dx[0]+dx[1])*(dx[0]+dx[1]));
                    tmp[0] = S[0]*dx[1]*(2.0*dx[1]+3.0*dx[0]) +
                             S[1]*dx[0]*dx[0];
                    break;
                  case FirstDerivative:
                    L.setFirstRow(1.0, 0.0);
                    tmp[0] = leftValue;
                    break;
                  case SecondDerivative:
                    L.setFirstRow(2.0, 1.0);
                    tmp[0] = 3.0*S[0] - leftValue*dx[0]/2.0;
                    break;
                  case Periodic:
                  case Lagrange:
                    // ignoring end condition value
                    throw new LibraryException("this end condition is not implemented yet");
                  default:
                    throw new LibraryException("unknown end condition");
                }

                // right boundary condition
                switch (rightType) {
                  case NotAKnot:
                    // ignoring end condition value
                    L.setLastRow(-(dx[n-2]+dx[n-3])*(dx[n-2]+dx[n-3]),
                                 -dx[n-3]*(dx[n-3]+dx[n-2]));
                    tmp[n-1] = -S[n-3]*dx[n-2]*dx[n-2] -
                                 S[n-2]*dx[n-3]*(3.0*dx[n-2]+2.0*dx[n-3]);
                    break;
                  case FirstDerivative:
                    L.setLastRow(0.0, 1.0);
                    tmp[n-1] = rightValue;
                    break;
                  case SecondDerivative:
                    L.setLastRow(1.0, 2.0);
                    tmp[n-1] = 3.0*S[n-2] + rightValue*dx[n-2]/2.0;
                    break;
                  case Periodic:
                  case Lagrange:
                    // ignoring end condition value
                    throw new LibraryException("this end condition is not implemented yet");
                  default:
                    throw new LibraryException("unknown end condition");
                }

                // solve the system
                tmp = L.solveFor(tmp);
            } else { // local schemes
                if (n==2) {
                    tmp[0] = tmp[1] = S[0];
                } else {
                    switch (da) {
View Full Code Here

TOP

Related Classes of org.jquantlib.methods.finitedifferences.TridiagonalOperator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.