Esempio n. 1
0
  /* (non-Javadoc)
   * @see net.finmath.stochastic.RandomVariableInterface#add(net.finmath.stochastic.RandomVariableInterface)
   */
  public RandomVariableInterface add(RandomVariableInterface randomVariable) {
    // Set time of this random variable to maximum of time with respect to which measurability is
    // known.
    double newTime = Math.max(time, randomVariable.getFiltrationTime());

    if (isDeterministic() && randomVariable.isDeterministic()) {
      double newValueIfNonStochastic = valueIfNonStochastic + randomVariable.get(0);
      return new RandomVariable(newTime, newValueIfNonStochastic);
    } else if (isDeterministic()) return randomVariable.add(this);
    else {
      double[] newRealizations = new double[Math.max(size(), randomVariable.size())];
      for (int i = 0; i < newRealizations.length; i++)
        newRealizations[i] = realizations[i] + randomVariable.get(i);
      return new RandomVariable(newTime, newRealizations);
    }
  }