当前位置: 首页>>代码示例>>Java>>正文


Java TimeSeries类代码示例

本文整理汇总了Java中eu.verdelhan.ta4j.TimeSeries的典型用法代码示例。如果您正苦于以下问题:Java TimeSeries类的具体用法?Java TimeSeries怎么用?Java TimeSeries使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TimeSeries类属于eu.verdelhan.ta4j包,在下文中一共展示了TimeSeries类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: BuySignalIndicator

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
public BuySignalIndicator(TimeSeries series, int timeframe, Decimal momentum) {
    super(series);

    this.momentum = momentum;

    ClosePriceIndicator closePriceIndicator = new ClosePriceIndicator(series);

    EMAIndicator emaIndicator = new EMAIndicator(closePriceIndicator, timeframe);
    ParabolicSarIndicator sarIndicator = new ParabolicSarIndicator(series, timeframe);
    this.adxIndicator = new AverageDirectionalMovementIndicator(series, timeframe);

    // wait for stable turn from bearish to bullish market
    this.swapIndicator = new SwapIndicator(closePriceIndicator, sarIndicator);

    // consider prices above ema to be in upswing
    this.upSwingIndicator = new UpSwingIndicator(closePriceIndicator, emaIndicator);
}
 
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:18,代码来源:BuySignalIndicator.java

示例2: buildStrategy

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
/**
 * @param series a time series
 * @return a CCI correction strategy
 */
public static Strategy buildStrategy(TimeSeries series) {
    if (series == null) {
        throw new IllegalArgumentException("Series cannot be null");
    }

    CCIIndicator longCci = new CCIIndicator(series, 200);
    CCIIndicator shortCci = new CCIIndicator(series, 5);
    Decimal plus100 = Decimal.HUNDRED;
    Decimal minus100 = Decimal.valueOf(-100);

    Rule entryRule = new OverIndicatorRule(longCci, plus100) // Bull trend
            .and(new UnderIndicatorRule(shortCci, minus100)); // Signal

    Rule exitRule = new UnderIndicatorRule(longCci, minus100) // Bear trend
            .and(new OverIndicatorRule(shortCci, plus100)); // Signal

    Strategy strategy = new Strategy(entryRule, exitRule);
    strategy.setUnstablePeriod(5);
    return strategy;
}
 
开发者ID:romatroskin,项目名称:altrader,代码行数:25,代码来源:CCICorrectionStrategy.java

示例3: buildStrategy

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
/**
 * @param series a time series
 * @return a global extrema strategy
 */
public static Strategy buildStrategy(TimeSeries series) {
    if (series == null) {
        throw new IllegalArgumentException("Series cannot be null");
    }

    ClosePriceIndicator closePrices = new ClosePriceIndicator(series);

    // Getting the max price over the past week
    MaxPriceIndicator maxPrices = new MaxPriceIndicator(series);
    HighestValueIndicator weekMaxPrice = new HighestValueIndicator(maxPrices, NB_TICKS_PER_WEEK);
    // Getting the min price over the past week
    MinPriceIndicator minPrices = new MinPriceIndicator(series);
    LowestValueIndicator weekMinPrice = new LowestValueIndicator(minPrices, NB_TICKS_PER_WEEK);

    // Going long if the close price goes below the min price
    MultiplierIndicator downWeek = new MultiplierIndicator(weekMinPrice, Decimal.valueOf("1.004"));
    Rule buyingRule = new UnderIndicatorRule(closePrices, downWeek);

    // Going short if the close price goes above the max price
    MultiplierIndicator upWeek = new MultiplierIndicator(weekMaxPrice, Decimal.valueOf("0.996"));
    Rule sellingRule = new OverIndicatorRule(closePrices, upWeek);

    return new Strategy(buyingRule, sellingRule);
}
 
开发者ID:romatroskin,项目名称:altrader,代码行数:29,代码来源:GlobalExtremaStrategy.java

示例4: main

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
public static void main(String[] args) {

        // load data as TimeSeries
        Loader loader = new Loader();
        TimeSeries series = loader.getMinuteTimeSeries("ta4j-strategies\\src\\main\\data\\fb_minutes.csv", "Facebook");

        // create and initialize a strategy
        SimpleRangeScalper simpleRangeScalper = new SimpleRangeScalper();
        simpleRangeScalper.initStrategy(series);

        // run strategy on time series and analyse results
        StrategyAnalyser analyser = new StrategyAnalyser();
        analyser.printAllResults(simpleRangeScalper);

        // change parameters of the strategy and run again
        simpleRangeScalper.setParams(20, Decimal.valueOf(0.5));
        analyser.printAllResults(simpleRangeScalper);
    }
 
开发者ID:team172011,项目名称:ta4j-strategies,代码行数:19,代码来源:Run.java

示例5: CCICorrectionStrategy

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
public CCICorrectionStrategy(TimeSeries series, ClosePriceIndicator closePriceIndicator) {
  super(series, CCICorrectionStrategy.class.getSimpleName(), closePriceIndicator);
  if (series == null) {
    throw new IllegalArgumentException("Series cannot be null");
  }

  CCIIndicator longCci = new CCIIndicator(series, 200);
  CCIIndicator shortCci = new CCIIndicator(series, 5);
  Decimal plus100 = Decimal.HUNDRED;
  Decimal minus100 = Decimal.valueOf(-100);

  Rule entryRule = new OverIndicatorRule(longCci, plus100) // Bull trend
      .and(new UnderIndicatorRule(shortCci, minus100)); // Signal

  Rule exitRule = new UnderIndicatorRule(longCci, minus100) // Bear trend
      .and(new OverIndicatorRule(shortCci, plus100)); // Signal

  this.strategy = new Strategy(entryRule, exitRule);
}
 
开发者ID:the-james-burton,项目名称:the-turbine,代码行数:20,代码来源:CCICorrectionStrategy.java

示例6: instantiateIndicator

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
private BaseIndicator instantiateIndicator(IndicatorInstance instance) {
  BaseIndicator result = null;
  try {
    Constructor<?> indicatorConstructor = Class.forName(instance.getClassname()).getConstructor(
        IndicatorInstance.class,
        TimeSeries.class,
        ClosePriceIndicator.class);
    result = (BaseIndicator) indicatorConstructor.newInstance(instance, series, closePriceIndicator);
    logger.debug("instantiated [{}]: {}", getTicker(), result.getInstance().getName());
  } catch (Exception e) {
    // TODO exceptions from the constructor in are missing in this exception!
    logger.warn("could not instantiate {} for [{}]: {}",
        instance.getClassname(), getTicker(), e.getMessage());
  }
  return result;
}
 
开发者ID:the-james-burton,项目名称:the-turbine,代码行数:17,代码来源:Stock.java

示例7: getSeriesByDays

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
@Cacheable (name="TechnicalAnalysis_getSeriesByDays", ttl=600)
public TimeSeries getSeriesByDays(String symbol, String startDate, int days, boolean enforce) {
	
	String today = db.getTimestampFromDate(startDate, pattern).toString();
	TimeSeries series = null;
	
	// Default seriesSize and iteration to 0
	int seriesSize = 0;
	int iteration = 0;
	
	// Loop until the seriesSize matches the requested amount of days or until we have done 30 iterations (otherwise we end up in infinite loop!)
	while ((seriesSize < days) && (iteration < 30)) {
		String sd = db.subtractDaysFromDate(today, pattern, days + iteration);
		
		series = this.getSeriesByDate(symbol, sd, today);
		if (series != null) {
			seriesSize =  series.getTickCount();
		}
		
		// Increase the iteration by the difference between days and current seriesSize
		iteration = iteration + (days - seriesSize);
	}	
	
	return series;
	
}
 
开发者ID:sgrotz,项目名称:myopentrader,代码行数:27,代码来源:TechnicalAnalysis.java

示例8: countBack

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
private static TADecimal countBack(TimeSeries data, int i, int countBackSteps) {
    TimeSeries subSeries = data.subseries(data.getBegin(), i);
    TADecimal stopLoss = null;
    TADecimal lowest = subSeries.getTick(subSeries.getEnd()).getMinPrice();
    Integer stopLossIdx = null;
    int stepBacks = 0;
    if (lowest != null) {
        for (int j = subSeries.getEnd(); j >= subSeries.getBegin(); j--) {
            if (subSeries.getTick(j).getMinPrice().isLessThan(lowest)) {
                lowest = subSeries.getTick(j).getMinPrice();
                if (++stepBacks >= countBackSteps) { // Only look back a maximum of count back steps
                    stopLossIdx = j;
                    break;
                }
            }
        }
        stopLoss = stopLossIdx != null ? subSeries.getTick(stopLossIdx).getMinPrice()
                : null;
    }
    return stopLoss;
}
 
开发者ID:woodberry,项目名称:ta-toolbox,代码行数:22,代码来源:CountBackStopLossIndicator.java

示例9: RangeIndicator

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
public RangeIndicator(TimeSeries timeSeries, double displacementLower, double displacementUpper, int timeFrame) {
    if (timeSeries == null) {
        throw new IllegalArgumentException("Supplied TimeSeries is invalid: NULL");
    }
    if (displacementLower <= 0) {
        throw new IllegalArgumentException("Supplied DisplacementLower is invalid: Cannot be less than or equal to zero");
    }
    if (displacementUpper <= 0) {
        throw new IllegalArgumentException("Supplied DisplacementUpper is invalid: Cannot be less than or equal to zero");
    }
    if (timeFrame <= 0) {
        throw new IllegalArgumentException("Supplied TimeFrame is invalid: Cannot be less than or equal to zero");
    }
    this.timeSeries = timeSeries;
    this.hmaIndicator = new HMAIndicator(timeSeries, timeFrame);
    this.atrIndicator = new AverageTrueRangeIndicator(timeSeries, timeFrame);
    this.tradersAtrIndicator = new TradersATRIndicator(atrIndicator, hmaIndicator, displacementLower);
    this.displacementUpper = TADecimal.valueOf(displacementUpper);
}
 
开发者ID:woodberry,项目名称:ta-toolbox,代码行数:20,代码来源:RangeIndicator.java

示例10: countBack

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
private static Integer countBack(TimeSeries data, int pivotPtIdx, int countBackSteps) {
    Integer cblIdx = null;
    if (pivotPtIdx >= countBackSteps) {
        int stepBacks = 0;
        TADecimal highest = data.getTick(pivotPtIdx).getMaxPrice();
        for (int j = pivotPtIdx; j >= data.getBegin(); j--) {
            if (data.getTick(j).getMaxPrice().isGreaterThan(highest)) {
                highest = data.getTick(j).getMaxPrice();
                if (++stepBacks >= countBackSteps) { // Only look back a maximum of count back steps
                    cblIdx = j;
                    break;
                }
            }
        }
    }
    return cblIdx;
}
 
开发者ID:woodberry,项目名称:ta-toolbox,代码行数:18,代码来源:CountBackLineIndicator.java

示例11: NR7BreakoutIndicator

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
/**
 * Bulkowski's NR7 (Narrow Range) - based on 7 periods of data
 *
 * The NR7 is based on the high-low price range that is the smallest of the prior six days (seven days total). 
 * When an NR7 occurs, it means that today's price is the narrowest of the seven days.
 *
 * http://thepatternsite.com/nr7.html
 *
 * @param timeSeries A TimeSeries, containing both a max and min price
 * @param nr7Index The index position where the nr7 signal exists
 */
public NR7BreakoutIndicator(TimeSeries timeSeries, int nr7Index) {
    if (timeSeries == null) {
        throw new IllegalArgumentException("Supplied TimeSeries is invalid: NULL");
    }
    if (timeSeries.getSize() <= 2) {
        throw new IllegalArgumentException("Supplied TimeSeries is invalid: Cannot be less than size of 2");
    }
    if (nr7Index == timeSeries.getEnd()) {
        throw new IllegalArgumentException("Supplied Integer index is invalid: Cannot be the last index within the TimeSeries");
    }
    if (nr7Index > timeSeries.getEnd()) {
        throw new IllegalArgumentException("Supplied Integer index is invalid: Not within the TimeSeries");
    }
    this.nr7Index = nr7Index;
    this.firstIndex = nr7Index + 1; // First possible breakout occurs after the nr7 tick
    this.timeSeries = timeSeries;
}
 
开发者ID:woodberry,项目名称:ta-toolbox,代码行数:29,代码来源:NR7BreakoutIndicator.java

示例12: testCalculateWhenHopeSustainabilityTurnsToConfidentTC1

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
@Test
public void testCalculateWhenHopeSustainabilityTurnsToConfidentTC1() {
    final TADecimal entry = TADecimal.valueOf(4245.7);
    TimeSeries timeSeries = new TimeSeries(StubDataTestUtils.createTickData("/TEST_TREND_VOLATILITY_LINE_TC1.stub", "\t", null, DTF));
    TrendVolatilityLineIndicator tvlIndicator = new TrendVolatilityLineIndicator(new GuppyMultipleMovingAverageIndicator(new ClosePriceIndicator(timeSeries)), entry);

    TrendVolatilityLine tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("10/8/12", DTF)));
    assertNotNull(tvl.getValue());
    assertEquals(4245.7, tvl.getValue().toDouble(), DELTA);
    assertEquals(Sustainability.HOPE, tvl.getSustainability());
    
    tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("13/8/12", DTF)));
    assertNotNull(tvl.getValue());
    assertEquals(4245.7, tvl.getValue().toDouble(), DELTA);
    assertEquals(Sustainability.CONFIDENT, tvl.getSustainability());
}
 
开发者ID:woodberry,项目名称:ta-toolbox,代码行数:17,代码来源:TrendVolatilityLineIndicatorTest.java

示例13: testCalculateWhenConfidentSustainabilityTurnsToCertaintyTC1

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
@Test
public void testCalculateWhenConfidentSustainabilityTurnsToCertaintyTC1() {
    final TADecimal entry = TADecimal.valueOf(4245.7);
    TimeSeries timeSeries = new TimeSeries(StubDataTestUtils.createTickData("/TEST_TREND_VOLATILITY_LINE_TC1.stub", "\t", null, DTF));
    TrendVolatilityLineIndicator tvlIndicator = new TrendVolatilityLineIndicator(new GuppyMultipleMovingAverageIndicator(new ClosePriceIndicator(timeSeries)), entry);
    
    TrendVolatilityLine tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("20/8/12", DTF)));
    assertNotNull(tvl.getValue());
    assertEquals(4245.7, tvl.getValue().toDouble(), DELTA);
    assertEquals(Sustainability.CONFIDENT, tvl.getSustainability());
    
    tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("21/8/12", DTF)));
    assertNotNull(tvl.getValue());
    assertEquals(4245.7, tvl.getValue().toDouble(), DELTA);
    assertEquals(Sustainability.CERTAINTY, tvl.getSustainability());
}
 
开发者ID:woodberry,项目名称:ta-toolbox,代码行数:17,代码来源:TrendVolatilityLineIndicatorTest.java

示例14: testCalculateTVLValueUpdatesWhenTrendRisesWithinCertaintyTC1

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
@Test
public void testCalculateTVLValueUpdatesWhenTrendRisesWithinCertaintyTC1() {
    final TADecimal entry = TADecimal.valueOf(4245.7);
    TimeSeries timeSeries = new TimeSeries(StubDataTestUtils.createTickData("/TEST_TREND_VOLATILITY_LINE_TC1.stub", "\t", null, DTF));
    TrendVolatilityLineIndicator tvlIndicator = new TrendVolatilityLineIndicator(new GuppyMultipleMovingAverageIndicator(new ClosePriceIndicator(timeSeries)), entry);

    TrendVolatilityLine tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("31/8/12", DTF)));
    assertNotNull(tvl.getValue());
    assertEquals(4245.7, tvl.getValue().toDouble(), DELTA);
    assertEquals(Sustainability.CERTAINTY, tvl.getSustainability());

    tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("3/9/12", DTF)));
    assertNotNull(tvl.getValue());
    assertEquals(4293.182773, tvl.getValue().toDouble(), DELTA);
    assertEquals(Sustainability.CERTAINTY, tvl.getSustainability());
}
 
开发者ID:woodberry,项目名称:ta-toolbox,代码行数:17,代码来源:TrendVolatilityLineIndicatorTest.java

示例15: testCalculateFromSpecificIndexTC1

import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
@Test
public void testCalculateFromSpecificIndexTC1() {
    final TADecimal entry = TADecimal.valueOf(4245.7);
    TimeSeries timeSeries = new TimeSeries(StubDataTestUtils.createTickData("/TEST_TREND_VOLATILITY_LINE_TC1.stub", "\t", null, DTF));
    final int index = index(timeSeries, DateTime.parse("27/07/12", DTF));
    TrendVolatilityLineIndicator tvlIndicator = new TrendVolatilityLineIndicator(new GuppyMultipleMovingAverageIndicator(new ClosePriceIndicator(timeSeries)), index, entry);

    TrendVolatilityLine tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("30/7/12", DTF)));
    assertEquals(Sustainability.HOPE, tvl.getSustainability());
    tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("13/8/12", DTF)));
    assertEquals(Sustainability.CONFIDENT, tvl.getSustainability());
    tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("21/08/12", DTF)));
    assertEquals(Sustainability.CERTAINTY, tvl.getSustainability());
    tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("12/11/12", DTF)));
    assertEquals(Sustainability.UNKNOWN, tvl.getSustainability());
}
 
开发者ID:woodberry,项目名称:ta-toolbox,代码行数:17,代码来源:TrendVolatilityLineIndicatorTest.java


注:本文中的eu.verdelhan.ta4j.TimeSeries类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。