Package org.jquantlib.math.matrixutilities

Examples of org.jquantlib.math.matrixutilities.Matrix$RangeRow


        outerProduct(range(augmented(aA)), range(augmented(aB)));
        outerProduct(range(augmented(range(augmented(aA)))), range(augmented(range(augmented(aB)))));
    }

    private void outerProduct(final Array aA, final Array aB) {
        final Matrix mC = new Matrix( new double[][] {
                {  6.08.010.02.0 },
                3.04.0,   5.01.0 },
                { -6.0, -8.0, -10.0, -2.0 }
        });

        final Matrix m = aA.outerProduct(aB);
        if (!MatrixTest.equals(m, mC)) {
            fail("'outerProduct' failed");
        }
    }
View Full Code Here


        this.lowerExtrapolation = lowerExtrapolation;
        this.upperExtrapolation = upperExtrapolation;


        this.times = new Array(dates.length+1); // TODO: verify if length is correct
        this.variances = new Matrix(strikes.size(), dates.length+1); // TODO: verify if length is correct
        this.strikes = new Array(strikes.size()+1); // TODO: verify if length is correct

        for(int i = 1; i < strikes.size()+1; i++) {
            this.strikes.set(i, strikes.get(i-1));
        }
View Full Code Here

        }

        // ! Joint process of the two variables

        public StochasticProcess process() {
            final Matrix correlation = new Matrix(2, 2);
            correlation.set(0, 0, 1.0);
            correlation.set(1, 1, 1.0);
            correlation.set(0, 1, correlation_);
            correlation.set(1, 0, correlation_);
            final ArrayList<StochasticProcess1D> processes = new ArrayList<StochasticProcess1D>();
            processes.add(0, xProcess_);
            processes.add(1, xProcess_);
            return (new StochasticProcessArray(processes, correlation));
        }
View Full Code Here

    QL.require(sampleNumber > 1.0, UNSUFFICIENT_SAMPLE_NUMBER);

    final Array m = mean();
    final /*@Real*/ double inv = 1.0/sampleWeight;

    final Matrix result = quadraticSum.mul(inv);
    result.subAssign(m.outerProduct(m));

    result.mulAssign( sampleNumber/(sampleNumber-1.0) );
    return result;
  }
View Full Code Here

  /**
   * returns the correlation Matrix
   */
  public Matrix correlation() /*@ReadOnly*/ {
    final Matrix corr = covariance();
    final Array v = corr.diagonal();
    for (/*@Size*/ int i=0; i<dimension_; i++){
      for (/*@Size*/ int j=0; j<dimension_; j++){
        if (i==j) {
          if (v.$[v._(i)]==0.0) {
            corr.$[corr._(i,j)] = 1.0;
          } else {
            corr.$[corr._(i,j)] *= 1.0/Math.sqrt(v.$[v._(i)] * v.$[v._(j)]);
          }
        } else {
          if (v.$[v._(i)]==0.0 && v.$[v._(j)]==0) {
            corr.$[corr._(i,j)] = 1.0;
          } else if (v.$[v._(i)]==0.0 || v.$[v._(j)]==0.0) {
            corr.$[corr._(i,j)] = 0.0;
          } else {
            corr.$[corr._(i,j)] *= 1.0/Math.sqrt(v.$[v._(i)]*v.$[v._(j)]);
          }
        }
      } // j for
    } // i for
    return corr;
View Full Code Here

        for (int i=0; i<dimension; i++) {
          stats[i] = new Statistics();
        }
        results = new double[dimension];
      }
      quadraticSum = new Matrix(dimension_, dimension_);
    } else {
      dimension_ = dimension;
    }
  }
View Full Code Here

    }

    @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

            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 Matrix diffusion(/* @Time */final double t) {
        return diffusion(t, new Array(0)); //ZH:QL097 using Null<Array>
    }

    public Matrix covariance(/* @Time */final double t, final Array x) {
        final Matrix sigma = this.diffusion(t, x);
        return sigma.mul(sigma.transpose());
    }
View Full Code Here

        // because it is too slow and too inefficient.
        // This method is useful for testing and R&D.
        // Please overload the method within derived classes.
        QL.require(!x.empty() , "can not handle given x here"); // TODO: message

        final Matrix tmp = new Matrix(size_, size_);
        for (int i = 0; i < size_; ++i) {
            for (int j = 0; j <= i; ++j) {
                final Var_Helper helper = new Var_Helper(this, i, j);
                final GaussKronrodAdaptive integrator = new GaussKronrodAdaptive(1e-10, 10000);
                for(int k = 0; k<64; ++k) {
                    tmp.set(i, j, tmp.get(i, j)+integrator.op(helper, k*t/64.0,(k+1)*t/64.0));
                }
                tmp.set(j,i, tmp.get(i, j));
            }
        }

        return tmp;
    }
View Full Code Here

TOP

Related Classes of org.jquantlib.math.matrixutilities.Matrix$RangeRow

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.