• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Decimal类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: BuySignalIndicator

import eu.verdelhan.ta4j.Decimal; //导入依赖的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.Decimal; //导入依赖的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.Decimal; //导入依赖的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.Decimal; //导入依赖的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: calculate

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
@Override
protected Decimal calculate(int index) {
    Decimal sum1 = Decimal.ZERO;
    Decimal sum2 = Decimal.ZERO;
    for (int i = Math.max(0, index - timeFrame + 1); i <= index; i++) {
        Decimal close = indicator.getValue(i);
        Decimal prevClose = previousPriceIndicator.getValue(i);

        Decimal d = close.minus(prevClose);
        if (d.compareTo(Decimal.ZERO) >= 0) {
            sum1 = sum1.plus(d);
        } else {
            sum2 = sum2.plus(d.multipliedBy(NEGATIVE_ONE));
        }
    }
    return sum1.minus(sum2).dividedBy(sum1.plus(sum2)).multipliedBy
            (Decimal.HUNDRED);
}
 
开发者ID:KosherBacon,项目名称:JavaBitcoinTrader,代码行数:19,代码来源:CMOIndicator.java


示例6: CCICorrectionStrategy

import eu.verdelhan.ta4j.Decimal; //导入依赖的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


示例7: calculateRegressionLine

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
/**
 * Calculates the regression line.
 * @param startIndex the start index (inclusive) in the time series
 * @param endIndex the end index (inclusive) in the time series
 */
private void calculateRegressionLine(int startIndex, int endIndex) {
    // First pass: compute xBar and yBar
    Decimal sumX = Decimal.ZERO;
    Decimal sumY = Decimal.ZERO;
    for (int i = startIndex; i <= endIndex; i++) {
        sumX = sumX.plus(Decimal.valueOf(i));
        sumY = sumY.plus(indicator.getValue(i));
    }
    Decimal nbObservations = Decimal.valueOf(endIndex - startIndex + 1);
    Decimal xBar = sumX.dividedBy(nbObservations);
    Decimal yBar = sumY.dividedBy(nbObservations);
    
    // Second pass: compute slope and intercept
    Decimal xxBar = Decimal.ZERO;
    Decimal xyBar = Decimal.ZERO;
    for (int i = startIndex; i <= endIndex; i++) {
        Decimal dX = Decimal.valueOf(i).minus(xBar);
        Decimal dY = indicator.getValue(i).minus(yBar);
        xxBar = xxBar.plus(dX.multipliedBy(dX));
        xyBar = xyBar.plus(dX.multipliedBy(dY));
    }
    
    slope = xyBar.dividedBy(xxBar);
    intercept = yBar.minus(slope.multipliedBy(xBar));
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:31,代码来源:SimpleLinearRegressionIndicator.java


示例8: isSatisfied

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
@Override
public boolean isSatisfied(int index, TradingRecord tradingRecord) {
    boolean satisfied = false;
    // No trading history or no trade opened, no gain
    if (tradingRecord != null) {
        Trade currentTrade = tradingRecord.getCurrentTrade();
        if (currentTrade.isOpened()) {
            Decimal entryPrice = currentTrade.getEntry().getPrice();
            Decimal currentPrice = closePrice.getValue(index);
            Decimal threshold = entryPrice.multipliedBy(gainRatioThreshold);
            if (currentTrade.getEntry().isBuy()) {
                satisfied = currentPrice.isGreaterThanOrEqual(threshold);
            } else {
                satisfied = currentPrice.isLessThanOrEqual(threshold);
            }
        }
    }
    traceIsSatisfied(index, satisfied);
    return satisfied;
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:21,代码来源:StopGainRule.java


示例9: calculate

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
/**
 * Calculates the cash flow for a single trade.
 * @param trade a single trade
 */
private void calculate(Trade trade) {
    final int entryIndex = trade.getEntry().getIndex();
    int begin = entryIndex + 1;
    if (begin > values.size()) {
        Decimal lastValue = values.get(values.size() - 1);
        values.addAll(Collections.nCopies(begin - values.size(), lastValue));
    }
    int end = trade.getExit().getIndex();
    for (int i = Math.max(begin, 1); i <= end; i++) {
        Decimal ratio;
        if (trade.getEntry().isBuy()) {
            ratio = timeSeries.getTick(i).getClosePrice().dividedBy(timeSeries.getTick(entryIndex).getClosePrice());
        } else {
            ratio = timeSeries.getTick(entryIndex).getClosePrice().dividedBy(timeSeries.getTick(i).getClosePrice());
        }
        values.add(values.get(entryIndex).multipliedBy(ratio));
    }
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:23,代码来源:CashFlow.java


示例10: calculateMaximumDrawdown

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
/**
 * Calculates the maximum drawdown from a cash flow over a series.
 * @param series the time series
 * @param cashFlow the cash flow
 * @return the maximum drawdown from a cash flow over a series
 */
private Decimal calculateMaximumDrawdown(TimeSeries series, CashFlow cashFlow) {
    Decimal maximumDrawdown = Decimal.ZERO;
    Decimal maxPeak = Decimal.ZERO;
    if (!series.isEmpty()) {
    	// The series is not empty
     for (int i = series.getBeginIndex(); i <= series.getEndIndex(); i++) {
         Decimal value = cashFlow.getValue(i);
         if (value.isGreaterThan(maxPeak)) {
             maxPeak = value;
         }
	
         Decimal drawdown = maxPeak.minus(value).dividedBy(maxPeak);
         if (drawdown.isGreaterThan(maximumDrawdown)) {
             maximumDrawdown = drawdown;
         }
     }
    }
    return maximumDrawdown;
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:26,代码来源:MaximumDrawdownCriterion.java


示例11: calculate

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
@Override
public double calculate(TimeSeries series, TradingRecord tradingRecord) {
    int numberOfProfitable = 0;
    for (Trade trade : tradingRecord.getTrades()) {
        int entryIndex = trade.getEntry().getIndex();
        int exitIndex = trade.getExit().getIndex();

        Decimal result;
        if (trade.getEntry().isBuy()) {
            // buy-then-sell trade
            result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice());
        } else {
            // sell-then-buy trade
            result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice());
        }
        if (result.isGreaterThan(Decimal.ONE)) {
            numberOfProfitable++;
        }
    }
    return ((double) numberOfProfitable) / tradingRecord.getTradeCount();
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:22,代码来源:AverageProfitableTradesCriterion.java


示例12: isSatisfied

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
@Test
public void isSatisfied() {
    final Decimal tradedAmount = Decimal.ONE;
    
    // 5% stop-loss
    rule = new StopLossRule(closePrice, Decimal.valueOf("5"));
    
    assertFalse(rule.isSatisfied(0, null));
    assertFalse(rule.isSatisfied(1, tradingRecord));
    
    // Enter at 114
    tradingRecord.enter(2, Decimal.valueOf("114"), tradedAmount);
    assertFalse(rule.isSatisfied(2, tradingRecord));
    assertFalse(rule.isSatisfied(3, tradingRecord));
    assertTrue(rule.isSatisfied(4, tradingRecord));
    // Exit
    tradingRecord.exit(5);
    
    // Enter at 128
    tradingRecord.enter(5, Decimal.valueOf("128"), tradedAmount);
    assertFalse(rule.isSatisfied(5, tradingRecord));
    assertTrue(rule.isSatisfied(6, tradingRecord));
    assertTrue(rule.isSatisfied(7, tradingRecord));
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:25,代码来源:StopLossRuleTest.java


示例13: isSatisfied

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
@Test
public void isSatisfied() {
    final Decimal tradedAmount = Decimal.ONE;
    
    // 30% stop-gain
    rule = new StopGainRule(closePrice, Decimal.valueOf("30"));
    
    assertFalse(rule.isSatisfied(0, null));
    assertFalse(rule.isSatisfied(1, tradingRecord));
    
    // Enter at 108
    tradingRecord.enter(2, Decimal.valueOf("108"), tradedAmount);
    assertFalse(rule.isSatisfied(2, tradingRecord));
    assertFalse(rule.isSatisfied(3, tradingRecord));
    assertTrue(rule.isSatisfied(4, tradingRecord));
    // Exit
    tradingRecord.exit(5);
    
    // Enter at 118
    tradingRecord.enter(5, Decimal.valueOf("118"), tradedAmount);
    assertFalse(rule.isSatisfied(5, tradingRecord));
    assertTrue(rule.isSatisfied(6, tradingRecord));
    assertTrue(rule.isSatisfied(7, tradingRecord));
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:25,代码来源:StopGainRuleTest.java


示例14: testStrategies

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
@Test
public void testStrategies() { 
    
    PeriodicalGrowthRateIndicator gri = new PeriodicalGrowthRateIndicator(this.closePrice,5);

    // Rules
    Rule buyingRule = new CrossedUpIndicatorRule(gri, Decimal.ZERO); 
    Rule sellingRule = new CrossedDownIndicatorRule(gri, Decimal.ZERO);     
    
    Strategy strategy = new BaseStrategy(buyingRule, sellingRule);
            
    // Check trades
    int result = seriesManager.run(strategy).getTradeCount();             
    int expResult = 3;
    
    assertEquals(expResult, result);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:18,代码来源:PeriodicalGrowthRateIndicatorTest.java


示例15: calculate

import eu.verdelhan.ta4j.Decimal; //导入依赖的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:mdeverdelhan,项目名称:ta4j-origins,代码行数:19,代码来源:BullishHaramiIndicator.java


示例16: calculate

import eu.verdelhan.ta4j.Decimal; //导入依赖的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:mdeverdelhan,项目名称:ta4j-origins,代码行数:19,代码来源:BearishEngulfingIndicator.java


示例17: convertTick

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
private BaseTick convertTick(BittrexChartData data) {

        return new BaseTick(ZonedDateTime.ofInstant(data.getTimeStamp().toInstant(), ZoneId.systemDefault()),
                Decimal.valueOf(data.getOpen().toString()),
                Decimal.valueOf(data.getHigh().toString()),
                Decimal.valueOf(data.getLow().toString()),
                Decimal.valueOf(data.getClose().toString()),
                Decimal.valueOf(data.getVolume().toString()));
    }
 
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:10,代码来源:BittrexDataConverter.java


示例18: calculate

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
@Override
protected Boolean calculate(int index) {

    Boolean upSwing = upSwingIndicator.getValue(index);
    Boolean swap = swapIndicator.getValue(index);
    Decimal adxValue = adxIndicator.getValue(index);
    Boolean adx = adxValue.isGreaterThan(momentum);

    LOGGER.debug("@index={} upSwing={} swap={} adx={} (value={}, momentum={})", index, upSwing, swap, adx, adxValue,
            momentum);

    return upSwing && swap && adx;
}
 
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:14,代码来源:BuySignalIndicator.java


示例19: getBuySignal

import eu.verdelhan.ta4j.Decimal; //导入依赖的package包/类
@Override
public boolean getBuySignal(TimeSeries tickers) {

    BuySignalIndicator buySignal = new BuySignalIndicator(tickers, 33, Decimal.valueOf(0.25));

    // Need to go through all index to initialize indicators
    for (int i = tickers.getBeginIndex(); i <= tickers.getEndIndex(); i++) {
        buySignal.getValue(i);
    }

    boolean signal = buySignal.getValue(tickers.getEndIndex());
    LOGGER.debug("buy_trigger: {} (end time={})", signal, tickers.getLastTick().getEndTime());
    return signal;
}
 
开发者ID:jeperon,项目名称:freqtrade-java,代码行数:15,代码来源:AnalyzeServiceImpl.java


示例20: buildStrategy

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

    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);

    // The bias is bullish when the shorter-moving average moves above the longer moving average.
    // The bias is bearish when the shorter-moving average moves below the longer moving average.
    EMAIndicator shortEma = new EMAIndicator(closePrice, 9);
    EMAIndicator longEma = new EMAIndicator(closePrice, 26);

    StochasticOscillatorKIndicator stochasticOscillK = new StochasticOscillatorKIndicator(series, 14);

    MACDIndicator macd = new MACDIndicator(closePrice, 9, 26);
    EMAIndicator emaMacd = new EMAIndicator(macd, 18);

    // Entry rule
    Rule entryRule = new OverIndicatorRule(shortEma, longEma) // Trend
            .and(new CrossedDownIndicatorRule(stochasticOscillK, Decimal.valueOf(20))) // Signal 1
            .and(new OverIndicatorRule(macd, emaMacd)); // Signal 2

    // Exit rule
    Rule exitRule = new UnderIndicatorRule(shortEma, longEma) // Trend
            .and(new CrossedUpIndicatorRule(stochasticOscillK, Decimal.valueOf(80))) // Signal 1
            .and(new UnderIndicatorRule(macd, emaMacd)); // Signal 2

    return new Strategy(entryRule, exitRule);
}
 
开发者ID:romatroskin,项目名称:altrader,代码行数:34,代码来源:MovingMomentumStrategy.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UpgradeStatusReport类代码示例发布时间:2022-05-23
下一篇:
Java PlatformBitmapFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap