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


Java Tick类代码示例

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


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

示例1: createOHLCDataset

import org.ta4j.core.Tick; //导入依赖的package包/类
/**
 * Builds a JFreeChart OHLC dataset from a ta4j time series.
 * @param series a time series
 * @return an Open-High-Low-Close dataset
 */
private static OHLCDataset createOHLCDataset(TimeSeries series) {
    final int nbTicks = series.getTickCount();
    
    Date[] dates = new Date[nbTicks];
    double[] opens = new double[nbTicks];
    double[] highs = new double[nbTicks];
    double[] lows = new double[nbTicks];
    double[] closes = new double[nbTicks];
    double[] volumes = new double[nbTicks];
    
    for (int i = 0; i < nbTicks; i++) {
        Tick tick = series.getTick(i);
        dates[i] = new Date(tick.getEndTime().toEpochSecond() * 1000);
        opens[i] = tick.getOpenPrice().toDouble();
        highs[i] = tick.getMaxPrice().toDouble();
        lows[i] = tick.getMinPrice().toDouble();
        closes[i] = tick.getClosePrice().toDouble();
        volumes[i] = tick.getVolume().toDouble();
    }
    
    OHLCDataset dataset = new DefaultHighLowDataset("btc", dates, highs, lows, opens, closes, volumes);
    
    return dataset;
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:30,代码来源:CandlestickChart.java

示例2: calculate

import org.ta4j.core.Tick; //导入依赖的package包/类
@Override
protected Boolean calculate(int index) {
    if (index < 1) {
        // Harami is a 2-candle pattern
        return false;
    }
    Tick prevTick = series.getTick(index-1);
    Tick currTick = series.getTick(index);
    if (prevTick.isBearish() && currTick.isBullish()) {
        final Decimal prevOpenPrice = prevTick.getOpenPrice();
        final Decimal prevClosePrice = prevTick.getClosePrice();
        final Decimal currOpenPrice = currTick.getOpenPrice();
        final Decimal currClosePrice = currTick.getClosePrice();
        return currOpenPrice.isLessThan(prevOpenPrice) && currOpenPrice.isGreaterThan(prevClosePrice)
                && currClosePrice.isLessThan(prevOpenPrice) && currClosePrice.isGreaterThan(prevClosePrice);
    }
    return false;
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:19,代码来源:BullishHaramiIndicator.java

示例3: testTickMerger3

import org.ta4j.core.Tick; //导入依赖的package包/类
/**
 * Test three tick merge
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout=6000)
public void testTickMerger3() throws InterruptedException, IOException, ParseException {
	
       final SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
       
	final CountDownLatch latch = new CountDownLatch(2);
	
	final BiConsumer<BitfinexCurrencyPair, Tick> tickConsumer = (s, t) -> {
		latch.countDown();
	};
	
	final TickMerger tickMerger = new TickMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, tickConsumer);
	tickMerger.addNewPrice(parser.parse("01:01:23").getTime(), 1.0, 5.0);
	tickMerger.addNewPrice(parser.parse("01:01:33").getTime(), 2.0, 5.0);
	tickMerger.addNewPrice(parser.parse("01:02:53").getTime(), 2.0, 5.0);

	tickMerger.close();
	
	latch.await();
}
 
开发者ID:jnidzwetzki,项目名称:crypto-bot,代码行数:27,代码来源:TickMegerTest.java

示例4: calculate

import org.ta4j.core.Tick; //导入依赖的package包/类
@Override
protected Boolean calculate(int index) {
    if (index < 1) {
        // Engulfing is a 2-candle pattern
        return false;
    }
    Tick prevTick = series.getTick(index-1);
    Tick currTick = series.getTick(index);
    if (prevTick.isBullish() && currTick.isBearish()) {
        final Decimal prevOpenPrice = prevTick.getOpenPrice();
        final Decimal prevClosePrice = prevTick.getClosePrice();
        final Decimal currOpenPrice = currTick.getOpenPrice();
        final Decimal currClosePrice = currTick.getClosePrice();
        return currOpenPrice.isGreaterThan(prevOpenPrice) && currOpenPrice.isGreaterThan(prevClosePrice)
                && currClosePrice.isLessThan(prevOpenPrice) && currClosePrice.isLessThan(prevClosePrice);
    }
    return false;
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:19,代码来源:BearishEngulfingIndicator.java

示例5: calculate

import org.ta4j.core.Tick; //导入依赖的package包/类
@Override
protected Boolean calculate(int index) {
    if (index < 1) {
        // Engulfing is a 2-candle pattern
        return false;
    }
    Tick prevTick = series.getTick(index-1);
    Tick currTick = series.getTick(index);
    if (prevTick.isBearish() && currTick.isBullish()) {
        final Decimal prevOpenPrice = prevTick.getOpenPrice();
        final Decimal prevClosePrice = prevTick.getClosePrice();
        final Decimal currOpenPrice = currTick.getOpenPrice();
        final Decimal currClosePrice = currTick.getClosePrice();
        return currOpenPrice.isLessThan(prevOpenPrice) && currOpenPrice.isLessThan(prevClosePrice)
                && currClosePrice.isGreaterThan(prevOpenPrice) && currClosePrice.isGreaterThan(prevClosePrice);
    }
    return false;
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:19,代码来源:BullishEngulfingIndicator.java

示例6: getPreviousPeriod

import org.ta4j.core.Tick; //导入依赖的package包/类
private long getPreviousPeriod(Tick tick, int indexOfPreviousTick) {
	switch (timeLevel) {
           case DAY: // return previous day
               int prevCalendarDay =  tick.getEndTime().minusDays(1).getDayOfYear();
               // skip weekend and holidays:
               while (getTimeSeries().getTick(indexOfPreviousTick).getEndTime().getDayOfYear() != prevCalendarDay && indexOfPreviousTick > 0) {
                   prevCalendarDay--;
               }
               return prevCalendarDay;
           case WEEK: // return previous week
               return tick.getEndTime().minusWeeks(1).get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
           case MONTH: // return previous month
               return tick.getEndTime().minusMonths(1).getMonthValue();
           default: // return previous year
               return tick.getEndTime().minusYears(1).getYear();
	}
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:18,代码来源:PivotPointIndicator.java

示例7: testTickMerger4

import org.ta4j.core.Tick; //导入依赖的package包/类
/**
 * Test three tick merge with other timestamps
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout=6000)
public void testTickMerger4() throws InterruptedException, IOException, ParseException {
	
       final SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
       
	final CountDownLatch latch = new CountDownLatch(2);
	
	final BiConsumer<BitfinexCurrencyPair, Tick> tickConsumer = (s, t) -> {
		latch.countDown();
	};
	
	final TickMerger tickMerger = new TickMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, tickConsumer);
	tickMerger.addNewPrice(parser.parse("01:01:23").getTime(), 1.0, 5.0);
	tickMerger.addNewPrice(parser.parse("01:01:33").getTime(), 2.0, 5.0);
	tickMerger.addNewPrice(parser.parse("02:02:53").getTime(), 2.0, 5.0);

	tickMerger.close();
	
	latch.await();
}
 
开发者ID:jnidzwetzki,项目名称:crypto-bot,代码行数:27,代码来源:TickMegerTest.java

示例8: calculate

import org.ta4j.core.Tick; //导入依赖的package包/类
@Override
protected Decimal calculate(int index) {
    if (index == 0) {
        return Decimal.THOUSAND;
    }
    
    Tick currentTick = series.getTick(index);
    Tick previousTick = series.getTick(index - 1);
    Decimal previousValue = getValue(index - 1);
    
    if (currentTick.getVolume().isGreaterThan(previousTick.getVolume())) {
        Decimal currentPrice = currentTick.getClosePrice();
        Decimal previousPrice = previousTick.getClosePrice();
        Decimal priceChangeRatio = currentPrice.minus(previousPrice).dividedBy(previousPrice);
        return previousValue.plus(priceChangeRatio.multipliedBy(previousValue));
    }
    return previousValue;
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:19,代码来源:PVIIndicator.java

示例9: averageDirectionalMovement

import org.ta4j.core.Tick; //导入依赖的package包/类
@Test
public void averageDirectionalMovement()
{
    MockTick tick1 = new MockTick(0, 0, 13, 7);
    MockTick tick2 = new MockTick(0, 0, 11, 5);
    MockTick tick3 = new MockTick(0, 0, 15, 3);
    MockTick tick4 = new MockTick(0, 0, 14, 2);
    MockTick tick5 = new MockTick(0, 0, 13, 0.2);
    
    List<Tick> ticks = new ArrayList<Tick>();
    ticks.add(tick1);
    ticks.add(tick2);
    ticks.add(tick3);
    ticks.add(tick4);
    ticks.add(tick5);
    
    MockTimeSeries series = new MockTimeSeries(ticks);
    AverageDirectionalMovementDownIndicator admdown = new AverageDirectionalMovementDownIndicator(series, 3);
    assertDecimalEquals(admdown.getValue(0), 1);
    assertDecimalEquals(admdown.getValue(1), 4d/3);
    assertDecimalEquals(admdown.getValue(2), 4d/3 * 2d/3);
    assertDecimalEquals(admdown.getValue(3), (4d/3 * 2d/3) * 2d/3 + 1d/3);
    assertDecimalEquals(admdown.getValue(4), ((4d/3 * 2d/3) * 2d/3 + 1d/3) * 2d/3 + 1.8 * 1d/3);
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:25,代码来源:AverageDirectionalMovementDownIndicatorTest.java

示例10: setUp

import org.ta4j.core.Tick; //导入依赖的package包/类
@Before
public void setUp() {
    Random r = new Random();
    List<Tick> ticks = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        double open = r.nextDouble();
        double close = r.nextDouble();
        double max = Math.max(close+r.nextDouble(), open+r.nextDouble());
        double min = Math.min(0, Math.min(close-r.nextDouble(), open-r.nextDouble()));
        ZonedDateTime dateTime = ZonedDateTime.now();
        Tick tick = new BaseTick(dateTime, open, close, max, min, i);
        ticks.add(tick);
    }
    this.series = new BaseTimeSeries("test", ticks);

    this.openPriceIndicator = new OpenPriceIndicator(this.series);
    this.minPriceIndicator = new MinPriceIndicator(this.series);
    this.maxPriceIndicator = new MaxPriceIndicator(this.series);
    this.volumeIndicator = new VolumeIndicator(this.series);
    this.closePriceIndicator = new ClosePriceIndicator(this.series);
    this.emaIndicator = new EMAIndicator(this.closePriceIndicator, 20);
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:23,代码来源:PreviousValueIndicatorTest.java

示例11: averageDirectionalMovement

import org.ta4j.core.Tick; //导入依赖的package包/类
@Test
public void averageDirectionalMovement()
{
    List<Tick> ticks = new ArrayList<Tick>();
    ticks.add(new MockTick(0, 0, 10, 2));
    ticks.add(new MockTick(0, 0, 12, 2));
    ticks.add(new MockTick(0, 0, 15, 2));
    ticks.add(new MockTick(0, 0, 11, 2));
    ticks.add(new MockTick(0, 0, 13, 7));
    
    MockTimeSeries series = new MockTimeSeries(ticks);
    AverageDirectionalMovementUpIndicator admup = new AverageDirectionalMovementUpIndicator(series, 3);
    assertDecimalEquals(admup.getValue(0), 1);
    assertDecimalEquals(admup.getValue(1), 4d/3);
    assertDecimalEquals(admup.getValue(2), 4d/3 * 2d/3 + 1);
    assertDecimalEquals(admup.getValue(3), (4d/3 * 2d/3 + 1) * 2d/3);
    assertDecimalEquals(admup.getValue(4), (4d/3 * 2d/3 + 1) * 2d/3 * 2d/3 + 2d/3);
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:19,代码来源:AverageDirectionalMovementUpIndicatorTest.java

示例12: sumOfVolume

import org.ta4j.core.Tick; //导入依赖的package包/类
@Test
public void sumOfVolume() {
    List<Tick> ticks = new ArrayList<Tick>();
    ticks.add(new MockTick(0, 10));
    ticks.add(new MockTick(0, 11));
    ticks.add(new MockTick(0, 12));
    ticks.add(new MockTick(0, 13));
    ticks.add(new MockTick(0, 150));
    ticks.add(new MockTick(0, 155));
    ticks.add(new MockTick(0, 160));
    VolumeIndicator volumeIndicator = new VolumeIndicator(new MockTimeSeries(ticks), 3);
    
    assertDecimalEquals(volumeIndicator.getValue(0), 10);
    assertDecimalEquals(volumeIndicator.getValue(1), 21);
    assertDecimalEquals(volumeIndicator.getValue(2), 33);
    assertDecimalEquals(volumeIndicator.getValue(3), 36);
    assertDecimalEquals(volumeIndicator.getValue(4), 175);
    assertDecimalEquals(volumeIndicator.getValue(5), 318);
    assertDecimalEquals(volumeIndicator.getValue(6), 465);
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:21,代码来源:VolumeIndicatorTest.java

示例13: getValue

import org.ta4j.core.Tick; //导入依赖的package包/类
@Test
public void getValue()
{
    List<Tick> ticks = new ArrayList<Tick>();
    
    ticks.add(new MockTick(0, 0, 10, 2));
    ticks.add(new MockTick(0, 0, 12, 2));
    ticks.add(new MockTick(0, 0, 15, 2));
    ticks.add(new MockTick(0, 0, 11, 2));
    ticks.add(new MockTick(0, 0, 13, 7));
    
    MockTimeSeries series = new MockTimeSeries(ticks);
    DirectionalUpIndicator dup = new DirectionalUpIndicator(series, 3);
    assertDecimalEquals(dup.getValue(0), 1);
    assertDecimalEquals(dup.getValue(1), (4d/3) / (14d/3));
    assertDecimalEquals(dup.getValue(2), (4d/3 * 2d/3 + 1) / (14d/3 * 2d/3 + 15d/3));
    assertDecimalEquals(dup.getValue(3), ((4d/3 * 2d/3 + 1) * 2d/3) / (((14d/3 * 2d/3 + 15d/3) * 2d/3) + 11d/3));
    assertDecimalEquals(dup.getValue(4), ((4d/3 * 2d/3 + 1) * 2d/3 * 2d/3 + 2d/3) / (((((14d/3 * 2d/3 + 15d/3) * 2d/3) + 11d/3) * 2d/3) + 13d/3));
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:20,代码来源:DirectionalUpIndicatorTest.java

示例14: setUp

import org.ta4j.core.Tick; //导入依赖的package包/类
@Before
public void setUp() {
    List<Tick> ticks = new ArrayList<Tick>();

    ticks.add(new MockTick(0, 0, 16, 8));
    ticks.add(new MockTick(0, 0, 12, 6));
    ticks.add(new MockTick(0, 0, 18, 14));
    ticks.add(new MockTick(0, 0, 10, 6));
    ticks.add(new MockTick(0, 0, 32, 6));
    ticks.add(new MockTick(0, 0, 2, 2));
    ticks.add(new MockTick(0, 0, 0, 0));
    ticks.add(new MockTick(0, 0, 8, 1));
    ticks.add(new MockTick(0, 0, 83, 32));
    ticks.add(new MockTick(0, 0, 9, 3));
    

    this.timeSeries = new MockTimeSeries(ticks);
    average = new MedianPriceIndicator(timeSeries);
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:20,代码来源:MedianPriceIndicatorTest.java

示例15: averageDirectionalMovement

import org.ta4j.core.Tick; //导入依赖的package包/类
@Test
public void averageDirectionalMovement()
{
    
    List<Tick> ticks = new ArrayList<Tick>();
    ticks.add(new MockTick(0, 0, 13, 7));
    ticks.add(new MockTick(0, 0, 11, 5));
    ticks.add(new MockTick(0, 0, 15, 3));
    ticks.add(new MockTick(0, 0, 14, 2));
    ticks.add(new MockTick(0, 0, 13, 0.2));
    
    MockTimeSeries series = new MockTimeSeries(ticks);
    DirectionalDownIndicator ddown = new DirectionalDownIndicator(series, 3);
    assertDecimalEquals(ddown.getValue(0), 1);
    assertDecimalEquals(ddown.getValue(1), (4d/3) / (13d/3));
    assertDecimalEquals(ddown.getValue(2), (4d/3 * 2d/3) / (13d/3 * 2d/3 + 15d/3));
    assertDecimalEquals(ddown.getValue(3), ((4d/3 * 2d/3) * 2d/3 + 1d/3) / (((13d/3 * 2d/3 + 15d/3) * 2d/3) + 14d/3));
    assertDecimalEquals(ddown.getValue(4), (((4d/3 * 2d/3) * 2d/3 + 1d/3) * 2d/3 + 1.8 * 1d/3) / (((((13d/3 * 2d/3 + 15d/3) * 2d/3) + 14d/3) * 2d/3) + 13d/3));
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:20,代码来源:DirectionalDownIndicatorTest.java


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