Search in sources :

Example 6 with CalendarDate

use of org.ojalgo.type.CalendarDate in project ojAlgo by optimatika.

the class ImplicitTimeSeries method keys.

@Override
public final long[] keys() {
    final long[] retVal = new long[this.size()];
    CalendarDate tmpKey = myFirst;
    retVal[0] = tmpKey.millis;
    for (int t = 1; t < retVal.length; t++) {
        tmpKey = tmpKey.step(myResolution);
        retVal[t] = tmpKey.millis;
    }
    return retVal;
}
Also used : CalendarDate(org.ojalgo.type.CalendarDate)

Example 7 with CalendarDate

use of org.ojalgo.type.CalendarDate in project ojAlgo by optimatika.

the class CalendarDateSeries method getPrimitiveKeys.

public long[] getPrimitiveKeys() {
    final long[] retVal = new long[this.size()];
    int i = 0;
    for (final CalendarDate tmpKey : this.keySet()) {
        retVal[i] = tmpKey.millis;
        i++;
    }
    return retVal;
}
Also used : CalendarDate(org.ojalgo.type.CalendarDate)

Example 8 with CalendarDate

use of org.ojalgo.type.CalendarDate in project ojAlgo by optimatika.

the class CoordinationSet method prune.

/**
 * Will prune and resample the data
 */
public CoordinationSet<N> prune(final CalendarDateUnit resolution) {
    final CoordinationSet<N> retVal = new CoordinationSet<>(resolution);
    final CalendarDate tmpLatestFirstKey = this.getLatestFirstKey();
    final CalendarDate tmpEarliestLastKey = this.getEarliestLastKey();
    for (final Map.Entry<String, CalendarDateSeries<N>> tmpEntry : this.entrySet()) {
        retVal.put(tmpEntry.getKey(), tmpEntry.getValue().resample(tmpLatestFirstKey, tmpEarliestLastKey, resolution));
    }
    return retVal;
}
Also used : CalendarDate(org.ojalgo.type.CalendarDate) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with CalendarDate

use of org.ojalgo.type.CalendarDate in project ojAlgo by optimatika.

the class SeriesInterpolator method getCombination.

public CalendarDateSeries<Double> getCombination(final Number inputKey) {
    final BigDecimal tmpInputKey = TypeUtils.toBigDecimal(inputKey, myContext);
    if (myCoordinatedSet == null) {
        myCoordinatedSet = myOriginalSet.prune();
        myCoordinatedSet.complete();
    }
    final CalendarDateSeries<Double> retVal = new CalendarDateSeries<>(myCoordinatedSet.getResolution());
    BigDecimal tmpLowerKey = null;
    BigDecimal tmpUpperKey = null;
    for (final BigDecimal tmpIterKey : myKeys.keySet()) {
        if (tmpIterKey.compareTo(tmpInputKey) != 1) {
            if ((tmpLowerKey == null) || (tmpIterKey.compareTo(tmpLowerKey) == 1)) {
                tmpLowerKey = tmpIterKey;
            }
        }
        if (tmpIterKey.compareTo(tmpInputKey) != -1) {
            if ((tmpUpperKey == null) || (tmpIterKey.compareTo(tmpInputKey) != -1)) {
                tmpUpperKey = tmpIterKey;
            }
        }
    }
    @SuppressWarnings("unchecked") final long[] tmpSeriesKeys = ((CalendarDateSeries<Double>) myCoordinatedSet.values().toArray()[0]).getPrimitiveKeys();
    double tmpFactor;
    double[] tmpSeriesValues;
    if ((tmpLowerKey == null) && (tmpUpperKey != null)) {
        tmpFactor = tmpInputKey.doubleValue() / tmpUpperKey.doubleValue();
        tmpSeriesValues = myCoordinatedSet.get(myKeys.get(tmpUpperKey)).asPrimitive().toRawCopy1D();
        for (int i = 0; i < tmpSeriesValues.length; i++) {
            tmpSeriesValues[i] *= tmpFactor;
        }
    } else if ((tmpLowerKey != null) && (tmpUpperKey == null)) {
        tmpFactor = tmpInputKey.doubleValue() / tmpLowerKey.doubleValue();
        tmpSeriesValues = myCoordinatedSet.get(myKeys.get(tmpLowerKey)).asPrimitive().toRawCopy1D();
        for (int i = 0; i < tmpSeriesValues.length; i++) {
            tmpSeriesValues[i] *= tmpFactor;
        }
    } else if ((tmpLowerKey != null) && (tmpUpperKey != null)) {
        if (tmpLowerKey.equals(tmpUpperKey)) {
            tmpSeriesValues = myCoordinatedSet.get(myKeys.get(tmpLowerKey)).asPrimitive().toRawCopy1D();
        } else {
            final double[] tmpLowerValues = myCoordinatedSet.get(myKeys.get(tmpLowerKey)).asPrimitive().toRawCopy1D();
            final double[] tmpUpperValues = myCoordinatedSet.get(myKeys.get(tmpUpperKey)).asPrimitive().toRawCopy1D();
            tmpFactor = (tmpInputKey.doubleValue() - tmpLowerKey.doubleValue()) / (tmpUpperKey.doubleValue() - tmpLowerKey.doubleValue());
            tmpSeriesValues = new double[tmpSeriesKeys.length];
            for (int i = 0; i < tmpSeriesValues.length; i++) {
                tmpSeriesValues[i] = (tmpFactor * tmpUpperValues[i]) + ((PrimitiveMath.ONE - tmpFactor) * tmpLowerValues[i]);
            }
        }
    } else {
        tmpSeriesValues = new double[tmpSeriesKeys.length];
    }
    for (int i = 0; i < tmpSeriesKeys.length; i++) {
        retVal.put(new CalendarDate(tmpSeriesKeys[i]), tmpSeriesValues[i]);
    }
    return retVal;
}
Also used : CalendarDate(org.ojalgo.type.CalendarDate) BigDecimal(java.math.BigDecimal)

Example 10 with CalendarDate

use of org.ojalgo.type.CalendarDate in project ojAlgo by optimatika.

the class CoordinationSet method prune.

/**
 * @return A new CoordinationSet where all series have the same first and last keys.
 */
public CoordinationSet<N> prune() {
    final CoordinationSet<N> retVal = new CoordinationSet<>(this.getResolution());
    final CalendarDate tmpFirstKey = this.getLatestFirstKey();
    final CalendarDate tmpLastKey = this.getEarliestLastKey();
    if (tmpLastKey.compareTo(tmpFirstKey) != -1) {
        for (final CalendarDateSeries<N> tmpSeries : this.values()) {
            final CalendarDateSeries<N> tmpSubMap = tmpSeries.subMap(tmpFirstKey, true, tmpLastKey, true);
            retVal.put(tmpSubMap);
        }
    }
    final CalendarDate tmpEarliestFirstKey = retVal.getEarliestFirstKey();
    final CalendarDate tmpLatestFirstKey = retVal.getLatestFirstKey();
    final CalendarDate tmpEarliestLastKey = retVal.getEarliestLastKey();
    final CalendarDate tmpLatestLastKey = retVal.getLatestLastKey();
    if ((tmpEarliestFirstKey == null) || !tmpEarliestFirstKey.equals(tmpFirstKey)) {
        throw new ProgrammingError("Something went wrong!");
    }
    if ((tmpLatestFirstKey == null) || !tmpLatestFirstKey.equals(tmpFirstKey)) {
        throw new ProgrammingError("Something went wrong!");
    }
    if ((tmpEarliestLastKey == null) || !tmpEarliestLastKey.equals(tmpLastKey)) {
        throw new ProgrammingError("Something went wrong!");
    }
    if ((tmpLatestLastKey == null) || !tmpLatestLastKey.equals(tmpLastKey)) {
        throw new ProgrammingError("Something went wrong!");
    }
    return retVal;
}
Also used : CalendarDate(org.ojalgo.type.CalendarDate) ProgrammingError(org.ojalgo.ProgrammingError)

Aggregations

CalendarDate (org.ojalgo.type.CalendarDate)14 CalendarDateSeries (org.ojalgo.series.CalendarDateSeries)5 BigDecimal (java.math.BigDecimal)4 GeometricBrownianMotion (org.ojalgo.random.process.GeometricBrownianMotion)2 CalendarDateUnit (org.ojalgo.type.CalendarDateUnit)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1 ProgrammingError (org.ojalgo.ProgrammingError)1 SimpleAsset (org.ojalgo.finance.portfolio.SimpleAsset)1 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)1 Deterministic (org.ojalgo.random.Deterministic)1 RandomNumber (org.ojalgo.random.RandomNumber)1 GeometricBrownian1D (org.ojalgo.random.process.GeometricBrownian1D)1 CalendarDateDuration (org.ojalgo.type.CalendarDateDuration)1