當前位置: 首頁>>代碼示例>>Java>>正文


Java CalendarDateSeries類代碼示例

本文整理匯總了Java中org.ojalgo.series.CalendarDateSeries的典型用法代碼示例。如果您正苦於以下問題:Java CalendarDateSeries類的具體用法?Java CalendarDateSeries怎麽用?Java CalendarDateSeries使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CalendarDateSeries類屬於org.ojalgo.series包,在下文中一共展示了CalendarDateSeries類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: estimateExcessDiffusionProcess

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public static GeometricBrownianMotion estimateExcessDiffusionProcess(final CalendarDateSeries<?> priceSeries,
        final CalendarDateSeries<?> riskFreeInterestRateSeries, final CalendarDateUnit timeUnit) {

    final SampleSet tmpSampleSet = FinanceUtils.makeExcessGrowthRateSampleSet(priceSeries, riskFreeInterestRateSeries);

    // The average number of millis between to subsequent keys in the series.
    double tmpStepSize = priceSeries.getResolution().size();
    // The time between to keys expressed in terms of the specified time meassure and unit.
    tmpStepSize /= timeUnit.size();

    final double tmpExp = tmpSampleSet.getMean();
    final double tmpVar = tmpSampleSet.getVariance();

    final double tmpDiff = PrimitiveFunction.SQRT.invoke(tmpVar / tmpStepSize);
    final double tmpDrift = (tmpExp / tmpStepSize) + ((tmpDiff * tmpDiff) / TWO);

    final GeometricBrownianMotion retVal = new GeometricBrownianMotion(tmpDrift, tmpDiff);

    return retVal;
}
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:21,代碼來源:FinanceUtils.java

示例2: forecast

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public static CalendarDateSeries<RandomNumber> forecast(final CalendarDateSeries<? extends Number> series, final int pointCount,
        final CalendarDateUnit timeUnit, final boolean includeOriginalSeries) {

    final CalendarDateSeries<RandomNumber> retVal = new CalendarDateSeries<>(timeUnit);
    retVal.name(series.getName()).colour(series.getColour());

    final double tmpSamplePeriod = (double) series.getAverageStepSize() / (double) timeUnit.size();
    final GeometricBrownianMotion tmpProcess = GeometricBrownianMotion.estimate(series.asPrimitive(), tmpSamplePeriod);

    if (includeOriginalSeries) {
        for (final Entry<CalendarDate, ? extends Number> tmpEntry : series.entrySet()) {
            retVal.put(tmpEntry.getKey(), new Deterministic(tmpEntry.getValue()));
        }
    }

    final CalendarDate tmpLastKey = series.lastKey();
    final double tmpLastValue = series.lastValue().doubleValue();

    tmpProcess.setValue(tmpLastValue);

    for (int i = 1; i <= pointCount; i++) {
        retVal.put(tmpLastKey.millis + (i * timeUnit.size()), tmpProcess.getDistribution(i));
    }

    return retVal;
}
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:27,代碼來源:FinanceUtils.java

示例3: makeQuotesSeries

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public static final CalendarDateSeries<Double> makeQuotesSeries(final PriceSeries aSeries, final List<? extends Quote> quotes) {

            final CalendarDateUnit tmpResolution = aSeries.getSeriesResolution();

            final CalendarDateSeries<Double> retVal = tmpResolution != null ? new CalendarDateSeries<>(tmpResolution) : new CalendarDateSeries<>();

            if (aSeries.getSeriesName() != null) {
                retVal.name(aSeries.getSeriesName());
            }

            if (aSeries.getSeriesColour() != null) {
                retVal.colour(ColourData.valueOf(aSeries.getSeriesColour()));
            }

            for (final Quote tmpQuote : quotes) {
                retVal.put(tmpQuote.getQuoteDate(), tmpQuote.getQuoteValue());
            }

            if (retVal.size() <= 0) {
                retVal.put(new Date(), PrimitiveMath.ONE);
            }

            retVal.complete();

            return retVal;
        }
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:27,代碼來源:PriceSeries.java

示例4: makeRiskFreeReturn

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public static BigDecimal makeRiskFreeReturn(final FinancialMarket market) {

            BigDecimal retVal = BigMath.ZERO;

            if (market.isHistoricalRiskFreeReturn()) {
                final CalendarDateSeries<Double> tmpRiskFreeSeries = market.getRiskFreeSeries();
                final Double tmpLastValue = tmpRiskFreeSeries.lastValue();
                retVal = BigFunction.DIVIDE.invoke(new BigDecimal(tmpLastValue), BigMath.HUNDRED);
            }

            final BigDecimal tmpAdjustment = market.getRiskFreeReturnAdjustment();
            if (tmpAdjustment.signum() != 0) {
                retVal = retVal.add(tmpAdjustment);
            }

            return retVal;
        }
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:18,代碼來源:FinancialMarket.java

示例5: add

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public void add(final CalendarDateSeries<?> aSeries) {

        final String tmpName = aSeries.getName();

        final TimeSeries tmpSeries = new TimeSeries(tmpName);
        for (final Entry<CalendarDate, ? extends Number> tmpEntry : aSeries.entrySet()) {
            final CalendarDate tmpKey = tmpEntry.getKey();
            final FixedMillisecond tmpPeriod = new FixedMillisecond(tmpKey.millis);
            final Number tmpValue = tmpEntry.getValue();
            final TimeSeriesDataItem tmpItem = new TimeSeriesDataItem(tmpPeriod, tmpValue);
            tmpSeries.add(tmpItem);
        }
        myCollection.addSeries(tmpSeries);

        ColourData tmpColour2 = aSeries.getColour();
        if (tmpColour2 == null) {
            tmpColour2 = ColourData.random();
            aSeries.colour(tmpColour2);
        }
        final int tmpRgb = tmpColour2.getRGB();
        final Color tmpColour = new Color(tmpRgb);

        this.putColour(tmpName, tmpColour);
    }
 
開發者ID:optimatika,項目名稱:ojAlgo-extensions,代碼行數:25,代碼來源:CalendarDateSeriesCollection.java

示例6: getPriceSeries

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public CalendarDateSeries<Double> getPriceSeries() {
    try {
        return this.getPriceSeries(this.getResourceLocator().getStreamReader());
    } catch (final Exception exception) {
        exception.printStackTrace();
        this.handleException(mySymbol, myResolution, myResourceLocator, exception);
        return new CalendarDateSeries<Double>(myResolution).name(mySymbol);
    }
}
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:10,代碼來源:DataSource.java

示例7: collectQuotesSeries

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
/**
 * NOT coordinated, completed, pruned or anything...
 */
public static CoordinationSet<Double> collectQuotesSeries(final Collection<? extends PriceSeries> series, final CalendarDateUnit resolution) {

    final CoordinationSet<Double> retVal = new CoordinationSet<>(resolution);

    for (final PriceSeries tmpSeries : series) {
        final CalendarDateSeries<Double> tmpQuotesSeries = tmpSeries.getQuotesSeries();
        BasicLogger.debug(tmpQuotesSeries);
        BasicLogger.debug("\t" + SampleSet.wrap(tmpQuotesSeries.asPrimitive()));
        retVal.put(tmpQuotesSeries);
    }

    return retVal;
}
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:17,代碼來源:PriceSeries.java

示例8: makeAnnualisedProcess

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
/**
 * @return Annualised, and normalised, geometric brownian motion
 */
public static GeometricBrownianMotion makeAnnualisedProcess(final FinancialMarket.Asset asset) {

    final CalendarDateSeries<Double> tmpAssetSeries = asset.getAssetSeries();

    final PrimitiveSeries tmpSamples = tmpAssetSeries.asPrimitive();
    final double tmpSamplePeriod = CalendarDateUnit.YEAR.convert(tmpAssetSeries.getResolution());

    final GeometricBrownianMotion retVal = GeometricBrownianMotion.estimate(tmpSamples, tmpSamplePeriod);
    retVal.setValue(PrimitiveMath.ONE);
    return retVal;
}
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:15,代碼來源:FinancialMarket.java

示例9: makeAssetSeries

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public static CalendarDateSeries<Double> makeAssetSeries(final FinancialMarket.Asset asset, final FinancialMarket market) {

            final String tmpSeriesKey = asset.getRawHistoricalValues().getName();

            final CalendarDate tmpHistoricalHorizon = market.getHistoricalHorizon();

            CoordinationSet<Double> tmpMarketData = market.getCoordinatedMarketData();
            CalendarDateSeries<Double> tmpCalendarDateSeries = tmpMarketData.get(tmpSeriesKey);

            if (tmpCalendarDateSeries == null) {
                final CalendarDateSeries<Double> tmpRawHistoricalValues = asset.getRawHistoricalValues();
                tmpRawHistoricalValues.complete();
                tmpMarketData.put(tmpRawHistoricalValues);
                tmpMarketData = tmpMarketData.prune();
                tmpCalendarDateSeries = tmpMarketData.get(tmpSeriesKey);
            }

            CalendarDateSeries<Double> retVal = tmpCalendarDateSeries.tailMap(tmpHistoricalHorizon);

            if (market.isHistoricalRiskFreeReturn()) {

                final CalendarDateSeries<Double> tmpRawHistoricalRiskFreeReturns = market.getRawHistoricalRiskFreeReturns();
                final String tmpName = tmpRawHistoricalRiskFreeReturns.getName();
                final CalendarDateSeries<Double> tmpRiskFreeInterestRateSeries = tmpMarketData.get(tmpName).tailMap(tmpHistoricalHorizon);

                retVal = FinanceUtils.makeNormalisedExcessPrice(retVal, tmpRiskFreeInterestRateSeries);
            }

            // TODO Fix this
            // retVal.modifyAll(PrimitiveFunction.MULTIPLY.second(PrimitiveMath.HUNDRED / retVal.firstValue().doubleValue()));

            final String tmpAssetKey = asset.getAssetKey();
            retVal.name(tmpAssetKey);
            final Color tmpAssetColour = asset.getAssetColour();
            retVal.colour(new ColourData(tmpAssetColour.getRGB()));

            return retVal;
        }
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:39,代碼來源:FinancialMarket.java

示例10: testDailyComparison

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public void testDailyComparison() {

        final String tmpYahooSymbol = "AAPL";
        final String tmpGoogleSymbol = "NASDAQ:AAPL";

        final YahooSymbol tmpYahooSource = new YahooSymbol(tmpYahooSymbol, CalendarDateUnit.DAY);
        final CalendarDateSeries<Double> tmpYahooPrices = tmpYahooSource.getPriceSeries();

        final GoogleSymbol tmpGoogleSource = new GoogleSymbol(tmpGoogleSymbol, CalendarDateUnit.DAY);
        final CalendarDateSeries<Double> tmpGooglePrices = tmpGoogleSource.getPriceSeries();

        CoordinationSet<Double> tmpCoordinator = new CoordinationSet<>();
        tmpCoordinator.put(tmpYahooPrices);
        tmpCoordinator.put(tmpGooglePrices);
        tmpCoordinator.complete();
        tmpCoordinator = tmpCoordinator.prune();
        final CalendarDateSeries<Double> tmpPrunedYahoo = tmpCoordinator.get(tmpYahooSymbol);
        final CalendarDateSeries<Double> tmpPrunedGoogle = tmpCoordinator.get(tmpGoogleSymbol);

        TestUtils.assertEquals("count", tmpPrunedYahoo.size(), tmpPrunedGoogle.size());
        TestUtils.assertEquals("Last Value", tmpPrunedYahoo.lastValue(), tmpPrunedGoogle.lastValue(), NumberContext.getGeneral(8, 14));
        // Doesn't work. Goggle and Yahoo seemsto have different data
        // JUnitUtils.assertEquals("First Value", tmpPrunedYahoo.firstValue(), tmpPrunedGoogle.firstValue(), PrimitiveMath.IS_ZERO);

        //        for (final CalendarDate tmpKey : tmpCoordinator.getAllContainedKeys()) {
        //            final double tmpYahooValue = tmpPrunedYahoo.get(tmpKey);
        //            final double tmpGoogleValue = tmpPrunedGoogle.get(tmpKey);
        //            if (tmpYahooValue != tmpGoogleValue) {
        //                BasicLogger.logDebug("Date={} Yahoo={} Google={}", tmpKey, tmpYahooValue, tmpGoogleValue);
        //            }
        //        }
    }
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:33,代碼來源:SymbolDataTest.java

示例11: makeExcessGrowthRateSampleSet

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
/**
 * @param priceSeries A series of prices
 * @param riskFreeInterestRateSeries A series of interest rates (risk free return expressed in %, 5.0
 *        means 5.0% annualized risk free return)
 * @return A sample set of price growth rates adjusted for risk free return
 */
public static SampleSet makeExcessGrowthRateSampleSet(final CalendarDateSeries<?> priceSeries, final CalendarDateSeries<?> riskFreeInterestRateSeries) {

    if (priceSeries.size() != riskFreeInterestRateSeries.size()) {
        throw new IllegalArgumentException("The two series must have the same size (number of elements).");
    }

    if (!priceSeries.firstKey().equals(riskFreeInterestRateSeries.firstKey())) {
        throw new IllegalArgumentException("The two series must have the same first key (date or calendar).");
    }

    if (!priceSeries.lastKey().equals(riskFreeInterestRateSeries.lastKey())) {
        throw new IllegalArgumentException("The two series must have the same last key (date or calendar).");
    }

    final double[] tmpPrices = priceSeries.asPrimitive().toRawCopy1D();
    final double[] tmpRiskFreeInterestRates = riskFreeInterestRateSeries.asPrimitive().toRawCopy1D();

    final Array1D<Double> retVal = Array1D.PRIMITIVE64.makeZero(tmpPrices.length - 1);

    final CalendarDateUnit tmpUnit = priceSeries.getResolution();
    double tmpThisRiskFree, tmpNextRiskFree, tmpAvgRiskFree, tmpRiskFreeGrowthRate, tmpThisPrice, tmpNextPrice, tmpPriceGrowthFactor, tmpPriceGrowthRate,
            tmpAdjustedPriceGrowthRate;

    for (int i = 0; i < retVal.size(); i++) {

        tmpThisRiskFree = tmpRiskFreeInterestRates[i] / PrimitiveMath.HUNDRED;
        tmpNextRiskFree = tmpRiskFreeInterestRates[i + 1] / PrimitiveMath.HUNDRED;
        tmpAvgRiskFree = (tmpThisRiskFree + tmpNextRiskFree) / PrimitiveMath.TWO;
        tmpRiskFreeGrowthRate = FinanceUtils.toGrowthRateFromAnnualReturn(tmpAvgRiskFree, tmpUnit);

        tmpThisPrice = tmpPrices[i];
        tmpNextPrice = tmpPrices[i + 1];
        tmpPriceGrowthFactor = tmpNextPrice / tmpThisPrice;
        tmpPriceGrowthRate = PrimitiveFunction.LOG.invoke(tmpPriceGrowthFactor);

        tmpAdjustedPriceGrowthRate = tmpPriceGrowthRate - tmpRiskFreeGrowthRate;

        retVal.set(i, tmpAdjustedPriceGrowthRate);
    }

    return SampleSet.wrap(retVal);
}
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:49,代碼來源:FinanceUtils.java

示例12: makeNormalisedExcessPrice

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
/**
 * @param priceSeries A series of prices
 * @param riskFreeInterestRateSeries A series of interest rates (risk free return expressed in %, 5.0
 *        means 5.0% annualized risk free return)
 * @return A sample set of price growth rates adjusted for risk free return
 */
public static CalendarDateSeries<Double> makeNormalisedExcessPrice(final CalendarDateSeries<?> priceSeries,
        final CalendarDateSeries<?> riskFreeInterestRateSeries) {

    if (priceSeries.size() != riskFreeInterestRateSeries.size()) {
        throw new IllegalArgumentException("The two series must have the same size (number of elements).");
    }

    if (!priceSeries.firstKey().equals(riskFreeInterestRateSeries.firstKey())) {
        throw new IllegalArgumentException("The two series must have the same first key (date or calendar).");
    }

    if (!priceSeries.lastKey().equals(riskFreeInterestRateSeries.lastKey())) {
        throw new IllegalArgumentException("The two series must have the same last key (date or calendar).");
    }

    final long[] tmpDates = priceSeries.getPrimitiveKeys();
    final double[] tmpPrices = priceSeries.asPrimitive().toRawCopy1D();
    final double[] tmpRiskFreeInterestRates = riskFreeInterestRateSeries.asPrimitive().toRawCopy1D();

    final CalendarDateUnit tmpResolution = priceSeries.getResolution();

    final CalendarDateSeries<Double> retVal = new CalendarDateSeries<>(tmpResolution);

    double tmpThisRiskFree, tmpLastRiskFree, tmpAvgRiskFree, tmpRiskFreeGrowthFactor, tmpThisPrice, tmpLastPrice, tmpPriceGrowthFactor,
            tmpAdjustedPriceGrowthFactor;

    double tmpAggregatedExcessPrice = PrimitiveMath.ONE;
    retVal.put(new CalendarDate(tmpDates[0]), tmpAggregatedExcessPrice);
    for (int i = 1; i < priceSeries.size(); i++) {

        tmpThisRiskFree = tmpRiskFreeInterestRates[i] / PrimitiveMath.HUNDRED;
        tmpLastRiskFree = tmpRiskFreeInterestRates[i - 1] / PrimitiveMath.HUNDRED;
        tmpAvgRiskFree = (tmpThisRiskFree + tmpLastRiskFree) / PrimitiveMath.TWO;
        tmpRiskFreeGrowthFactor = FinanceUtils.toGrowthFactorFromAnnualReturn(tmpAvgRiskFree, tmpResolution);

        tmpThisPrice = tmpPrices[i];
        tmpLastPrice = tmpPrices[i - 1];
        tmpPriceGrowthFactor = tmpThisPrice / tmpLastPrice;

        tmpAdjustedPriceGrowthFactor = tmpPriceGrowthFactor / tmpRiskFreeGrowthFactor;

        tmpAggregatedExcessPrice *= tmpAdjustedPriceGrowthFactor;

        retVal.put(new CalendarDate(tmpDates[i]), tmpAggregatedExcessPrice);
    }

    return retVal.name(priceSeries.getName()).colour(priceSeries.getColour());
}
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:55,代碼來源:FinanceUtils.java

示例13: get

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public synchronized CalendarDateSeries<Double> get(final DataSource<?> key) {

        final CalendarDate tmpNow = new CalendarDate();

        Value tmpValue = myCache.get(key);

        if (tmpValue != null) {

            if (myResolution.count(tmpValue.updated.millis, tmpNow.millis) > 0L) {
                this.update(tmpValue, key, tmpNow);
            }

        } else {

            tmpValue = new SourceCache.Value(key.getSymbol(), myResolution);

            myCache.put(key, tmpValue);

            this.update(tmpValue, key, tmpNow);
        }

        tmpValue.used = tmpNow;

        return tmpValue.series;
    }
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:26,代碼來源:SourceCache.java

示例14: testStepping

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public void testStepping() {

        final PrimitiveDenseStore tmpCorrelation = PrimitiveDenseStore.FACTORY.makeEye(3, 3);

        final GeometricBrownianMotion tmpOrgProc1 = new SimpleAsset(0.0, 0.01, PrimitiveMath.THIRD).forecast();
        final GeometricBrownianMotion tmpOrgProc2 = new SimpleAsset(0.0, 0.02, PrimitiveMath.THIRD).forecast();
        final GeometricBrownianMotion tmpOrgProc3 = new SimpleAsset(0.0, 0.03, PrimitiveMath.THIRD).forecast();

        TestUtils.assertEquals(0.01, tmpOrgProc1.getStandardDeviation(), 0.005);
        TestUtils.assertEquals(0.02, tmpOrgProc2.getStandardDeviation(), 0.005);
        TestUtils.assertEquals(0.03, tmpOrgProc3.getStandardDeviation(), 0.005);

        final ArrayList<GeometricBrownianMotion> tmpProcs = new ArrayList<>();
        tmpProcs.add(tmpOrgProc1);
        tmpProcs.add(tmpOrgProc2);
        tmpProcs.add(tmpOrgProc3);
        final GeometricBrownian1D tmpGB1D = new GeometricBrownian1D(tmpCorrelation, tmpProcs);
        final List<CalendarDateSeries<Double>> tmpSeries = new ArrayList<>();

        tmpSeries.add(new CalendarDateSeries<Double>(CalendarDateUnit.MONTH));
        tmpSeries.add(new CalendarDateSeries<Double>(CalendarDateUnit.MONTH));
        tmpSeries.add(new CalendarDateSeries<Double>(CalendarDateUnit.MONTH));

        CalendarDate tmpCalendarDateKey = CalendarDate.make(CalendarDateUnit.MONTH);

        tmpSeries.get(0).put(tmpCalendarDateKey, tmpOrgProc1.getValue());
        tmpSeries.get(1).put(tmpCalendarDateKey, tmpOrgProc2.getValue());
        tmpSeries.get(2).put(tmpCalendarDateKey, tmpOrgProc3.getValue());

        for (int t = 0; t < 1000; t++) {

            tmpGB1D.step(1.0 / 12.0);
            tmpCalendarDateKey = tmpCalendarDateKey.step(CalendarDateUnit.MONTH);

            tmpSeries.get(0).put(tmpCalendarDateKey, tmpGB1D.getValue(0));
            tmpSeries.get(1).put(tmpCalendarDateKey, tmpGB1D.getValue(1));
            tmpSeries.get(2).put(tmpCalendarDateKey, tmpGB1D.getValue(2));
        }

        final GeometricBrownianMotion tmpNewProc1 = GeometricBrownianMotion.estimate(tmpSeries.get(0).asPrimitive(), 1.0 / 12.0);
        final GeometricBrownianMotion tmpNewProc2 = GeometricBrownianMotion.estimate(tmpSeries.get(1).asPrimitive(), 1.0 / 12.0);
        final GeometricBrownianMotion tmpNewProc3 = GeometricBrownianMotion.estimate(tmpSeries.get(2).asPrimitive(), 1.0 / 12.0);

        TestUtils.assertEquals(0.01, tmpNewProc1.getStandardDeviation(), 0.005);
        TestUtils.assertEquals(0.02, tmpNewProc2.getStandardDeviation(), 0.005);
        TestUtils.assertEquals(0.03, tmpNewProc3.getStandardDeviation(), 0.005);

    }
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:49,代碼來源:MultidimensionalSimulatorTest.java

示例15: testResample

import org.ojalgo.series.CalendarDateSeries; //導入依賴的package包/類
public void testResample() {

        final YahooSymbol tmpYahooSymbol = new YahooSymbol("AAPL", CalendarDateUnit.DAY);
        final List<YahooSymbol.Data> tmpHistoricalPrices = tmpYahooSymbol.getHistoricalPrices();
        final double tmpLastPrice = tmpHistoricalPrices.get(tmpHistoricalPrices.size() - 1).getPrice();

        final CalendarDateSeries<Double> tmpDaySeries = new CalendarDateSeries<Double>(CalendarDateUnit.DAY).name("Day");
        final CalendarDateSeries<Double> tmpWeekSeries = new CalendarDateSeries<Double>(CalendarDateUnit.WEEK).name("Week");
        final CalendarDateSeries<Double> tmpMonthSeries = new CalendarDateSeries<Double>(CalendarDateUnit.MONTH).name("Month");
        final CalendarDateSeries<Double> tmpQuarterSeries = new CalendarDateSeries<Double>(CalendarDateUnit.QUARTER).name("Quarter");
        final CalendarDateSeries<Double> tmpYearSeries = new CalendarDateSeries<Double>(CalendarDateUnit.YEAR).name("Year");
        final CalendarDateSeries<Double> tmpDecadeSeries = new CalendarDateSeries<Double>(CalendarDateUnit.DECADE).name("Decade");
        final CalendarDateSeries<Double> tmpCenturySeries = new CalendarDateSeries<Double>(CalendarDateUnit.CENTURY).name("Century");
        final CalendarDateSeries<Double> tmpMilleniumSeries = new CalendarDateSeries<Double>(CalendarDateUnit.MILLENIUM).name("MIllenium");

        for (final DatePrice tmpDatePrice : tmpHistoricalPrices) {
            tmpDaySeries.put(tmpDatePrice.key, tmpDatePrice.getPrice());
            tmpWeekSeries.put(tmpDatePrice.key, tmpDatePrice.getPrice());
            tmpMonthSeries.put(tmpDatePrice.key, tmpDatePrice.getPrice());
            tmpQuarterSeries.put(tmpDatePrice.key, tmpDatePrice.getPrice());
            tmpYearSeries.put(tmpDatePrice.key, tmpDatePrice.getPrice());
            tmpDecadeSeries.put(tmpDatePrice.key, tmpDatePrice.getPrice());
            tmpCenturySeries.put(tmpDatePrice.key, tmpDatePrice.getPrice());
            tmpMilleniumSeries.put(tmpDatePrice.key, tmpDatePrice.getPrice());
        }

        tmpDaySeries.complete();
        tmpWeekSeries.complete();
        tmpMonthSeries.complete();
        tmpQuarterSeries.complete();
        tmpYearSeries.complete();
        tmpDecadeSeries.complete();
        tmpCenturySeries.complete();
        tmpMilleniumSeries.complete();

        TestUtils.assertEquals("Day Series Last Value", tmpLastPrice, tmpDaySeries.lastValue(), 1E-14 / PrimitiveMath.THREE);
        TestUtils.assertEquals("Week Series Last Value", tmpLastPrice, tmpWeekSeries.lastValue(), 1E-14 / PrimitiveMath.THREE);
        TestUtils.assertEquals("Month Series Last Value", tmpLastPrice, tmpMonthSeries.lastValue(), 1E-14 / PrimitiveMath.THREE);
        TestUtils.assertEquals("Quarter Series Last Value", tmpLastPrice, tmpQuarterSeries.lastValue(), 1E-14 / PrimitiveMath.THREE);
        TestUtils.assertEquals("Year Series Last Value", tmpLastPrice, tmpYearSeries.lastValue(), 1E-14 / PrimitiveMath.THREE);
        TestUtils.assertEquals("Decade Series Last Value", tmpLastPrice, tmpDecadeSeries.lastValue(), 1E-14 / PrimitiveMath.THREE);
        TestUtils.assertEquals("Century Series Last Value", tmpLastPrice, tmpCenturySeries.lastValue(), 1E-14 / PrimitiveMath.THREE);
        TestUtils.assertEquals("Millenium Series Last Value", tmpLastPrice, tmpMilleniumSeries.lastValue(), 1E-14 / PrimitiveMath.THREE);

        TestUtils.assertEquals(tmpMilleniumSeries.asPrimitive(), tmpCenturySeries.resample(CalendarDateUnit.MILLENIUM).asPrimitive());
        TestUtils.assertEquals(tmpMilleniumSeries.asPrimitive(), tmpDecadeSeries.resample(CalendarDateUnit.MILLENIUM).asPrimitive());
        TestUtils.assertEquals(tmpMilleniumSeries.asPrimitive(), tmpYearSeries.resample(CalendarDateUnit.MILLENIUM).asPrimitive());
        TestUtils.assertEquals(tmpMilleniumSeries.asPrimitive(), tmpQuarterSeries.resample(CalendarDateUnit.MILLENIUM).asPrimitive());
        TestUtils.assertEquals(tmpMilleniumSeries.asPrimitive(), tmpMonthSeries.resample(CalendarDateUnit.MILLENIUM).asPrimitive());
        TestUtils.assertEquals(tmpMilleniumSeries.asPrimitive(), tmpDaySeries.resample(CalendarDateUnit.MILLENIUM).asPrimitive());

        TestUtils.assertEquals(tmpCenturySeries.asPrimitive(), tmpDecadeSeries.resample(CalendarDateUnit.CENTURY).asPrimitive());
        TestUtils.assertEquals(tmpCenturySeries.asPrimitive(), tmpYearSeries.resample(CalendarDateUnit.CENTURY).asPrimitive());
        TestUtils.assertEquals(tmpCenturySeries.asPrimitive(), tmpQuarterSeries.resample(CalendarDateUnit.CENTURY).asPrimitive());
        TestUtils.assertEquals(tmpCenturySeries.asPrimitive(), tmpMonthSeries.resample(CalendarDateUnit.CENTURY).asPrimitive());
        TestUtils.assertEquals(tmpCenturySeries.asPrimitive(), tmpDaySeries.resample(CalendarDateUnit.CENTURY).asPrimitive());

        TestUtils.assertEquals(tmpDecadeSeries.asPrimitive(), tmpYearSeries.resample(CalendarDateUnit.DECADE).asPrimitive());
        TestUtils.assertEquals(tmpDecadeSeries.asPrimitive(), tmpQuarterSeries.resample(CalendarDateUnit.DECADE).asPrimitive());
        TestUtils.assertEquals(tmpDecadeSeries.asPrimitive(), tmpMonthSeries.resample(CalendarDateUnit.DECADE).asPrimitive());
        TestUtils.assertEquals(tmpDecadeSeries.asPrimitive(), tmpDaySeries.resample(CalendarDateUnit.DECADE).asPrimitive());

        TestUtils.assertEquals(tmpYearSeries.asPrimitive(), tmpQuarterSeries.resample(CalendarDateUnit.YEAR).asPrimitive());
        TestUtils.assertEquals(tmpYearSeries.asPrimitive(), tmpMonthSeries.resample(CalendarDateUnit.YEAR).asPrimitive());
        TestUtils.assertEquals(tmpYearSeries.asPrimitive(), tmpDaySeries.resample(CalendarDateUnit.YEAR).asPrimitive());

        TestUtils.assertEquals(tmpQuarterSeries.asPrimitive(), tmpMonthSeries.resample(CalendarDateUnit.QUARTER).asPrimitive());
        TestUtils.assertEquals(tmpQuarterSeries.asPrimitive(), tmpDaySeries.resample(CalendarDateUnit.QUARTER).asPrimitive());

        TestUtils.assertEquals(tmpMonthSeries.asPrimitive(), tmpDaySeries.resample(CalendarDateUnit.MONTH).asPrimitive());

        TestUtils.assertEquals(tmpWeekSeries.asPrimitive(), tmpDaySeries.resample(CalendarDateUnit.WEEK).asPrimitive());
    }
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:74,代碼來源:CalendarDateSeriesTest.java


注:本文中的org.ojalgo.series.CalendarDateSeries類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。