Package org.jquantlib.math.matrixutilities

Examples of org.jquantlib.math.matrixutilities.Array


        return 0;
    }

    @Override
    public Array drift(/* @Time */final double t, final Array x) {
        final Array f = new Array(size_);
        final Matrix covariance = lfmParam_.covariance(t, x);
        final int m = 0;//NextA
        for (int k = m; k < size_; ++k) {
            m1.set(k, accrualPeriod_.get(k) * x.get(k) / (1 + accrualPeriod_.get(k) * x.get(k)));
            final double value = m1.innerProduct(covariance.constRangeCol(k), m, k+1-m) - 0.5 * covariance.get(k, k);
            f.set(k, value);
        }
        return f;
    }
View Full Code Here


        return lfmParam_.covariance(dt, x).mul(lfmParam_.covariance(dt, x).mulAssign(dt));
    }

    @Override
    public Array apply(final Array x0, final Array dx){
        final Array tmp = new Array(size_);
        for(int k = 0; k<size_; ++k) {
            tmp.set(k, x0.get(k)*Math.exp(dx.get(k)));
        }
        return tmp;
    }
View Full Code Here

        if (true)
            throw new UnsupportedOperationException("work in progress");
        final int m   = 0;//nextIndexReset(t0);
        final double sdt = Math.sqrt(dt);

        final Array f = x0.clone();
        final Matrix diff       = lfmParam_.diffusion(t0, x0);
        final Matrix covariance = lfmParam_.covariance(t0, x0);

        // TODO: review iterators
        for (int k=m; k<size_; ++k) {
            final double y = accrualPeriod_.get(k)*x0.get(k);
            m1.set(k,y/(1+y));

            final double d = (m1.innerProduct(covariance.constRangeCol(k), m, k+1-m)-0.5*covariance.get(k, k)) * dt;
            final double r = diff.rangeRow(k).innerProduct(dw)*sdt;
            final double x = y*Math.exp(d + r);
            m2.set(k, x/(1+x));

            final double ip = m2.innerProduct(covariance.constRangeCol(k), m, k+1-m);
            final double value = x0.get(k) * Math.exp(0.5*(d+ip-0.5*covariance.get(k,k))*dt) + r;
            f.set(k, value);
        }

        return f;
    }
View Full Code Here

    }

    public abstract Matrix diffusion(/* @Time */double t, final Array x);

    public Matrix diffusion(/* @Time */final double t) {
        return diffusion(t, new Array());
    }
View Full Code Here

        final Matrix sigma = this.diffusion(t, x);
        return sigma.mul(sigma.transpose());
    }

    public Matrix covariance(/* @Time */final double t) {
        return diffusion(t, new Array());
    }
View Full Code Here

        return tmp;
    }

    public Matrix integratedCovariance(/* @Time */final double t) {
        return integratedCovariance(t, new Array());
    }
View Full Code Here

    public Array expectation(final /*@Time*/double t0, final Array x0, final /*@Time*/double dt)  {
        final double [] tmp = new double[size()];
        for (int i=0; i<size(); i++) {
            tmp[i] = processes_.get(i).expectation(t0, x0.get(i), dt);
        }
        return new Array(tmp);
    }
View Full Code Here

    }

    @Override
    public Array evolve(final /*@Time*/ double t0, final Array x0, final /*@Time*/double dt, final Array dw)  {

        final Array dz = sqrtCorrelation_.mul(dw);
        final double[] tmp = new double[size()];
        for (int i=0; i<size(); i++) {
            tmp[i] = processes_.get(i).evolve(t0, x0.get(i), dt, dz.get(i));
        }

        return new Array(tmp);
    }
View Full Code Here

    public Array apply(final Array x0, final Array dx)  {
        final double [] tmp = new double[size()];
        for (int i=0; i<size(); i++) {
            tmp[i] = processes_.get(i).apply(x0.get(i), dx.get(i));
        }
        return new Array(tmp);
    }
View Full Code Here

        return results_;
    }

    public Matrix correlation() {
        final Matrix correlation = covariance();
        final Array variances = correlation.diagonal();
        for (int i = 0; i < dimension_; i++) {
            for (int j = 0; j < dimension_; j++)
                if (i == j) {
                    if (variances.get(i) == 0.0) {
                        correlation.set(i, j, 1.0);
                    } else {
                        correlation.set(i, j, correlation.get(i, j) * 1.0 / Math.sqrt(variances.get(i) * variances.get(j)));
                    }
                } else if (variances.get(i) == 0.0 && variances.get(j) == 0) {
                    correlation.set(i, j, 1.0);
                } else if (variances.get(i) == 0.0 || variances.get(j) == 0.0) {
                    correlation.set(i, j, 1.0);
                } else {
                    correlation.set(i, j, correlation.get(i, j) * 1.0 / Math.sqrt(variances.get(i) * variances.get(j)));
                }
        }

        return correlation;
    }
View Full Code Here

TOP

Related Classes of org.jquantlib.math.matrixutilities.Array

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.