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


Java Decimal.valueOf方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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 BaseStrategy(entryRule, exitRule);
    strategy.setUnstablePeriod(5);
    return strategy;
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:25,代码来源:CCICorrectionStrategy.java

示例5: 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 BaseStrategy(buyingRule, sellingRule);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:29,代码来源:GlobalExtremaStrategy.java

示例6: keltnerChannelLowerIndicatorTest

import eu.verdelhan.ta4j.Decimal; //导入方法依赖的package包/类
@Test
public void keltnerChannelLowerIndicatorTest() {
    KeltnerChannelMiddleIndicator km = new KeltnerChannelMiddleIndicator(new ClosePriceIndicator(data), 14);
    KeltnerChannelLowerIndicator kl = new KeltnerChannelLowerIndicator(km, Decimal.valueOf(2), 14);
    
    assertDecimalEquals(kl.getValue(13), 11645.2878);
    assertDecimalEquals(kl.getValue(14), 11666.9952);
    assertDecimalEquals(kl.getValue(15), 11688.7782);
    assertDecimalEquals(kl.getValue(16), 11712.5707);
    assertDecimalEquals(kl.getValue(17), 11735.3684);
    assertDecimalEquals(kl.getValue(18), 11724.4143);
    assertDecimalEquals(kl.getValue(19), 11735.5588);
    assertDecimalEquals(kl.getValue(20), 11761.7046);
    assertDecimalEquals(kl.getValue(21), 11778.7855);
    assertDecimalEquals(kl.getValue(22), 11802.0144);
    assertDecimalEquals(kl.getValue(23), 11827.1846);
    assertDecimalEquals(kl.getValue(24), 11859.4459);
    assertDecimalEquals(kl.getValue(25), 11891.4189);
    assertDecimalEquals(kl.getValue(26), 11915.3814);
    assertDecimalEquals(kl.getValue(27), 11938.7221);
    assertDecimalEquals(kl.getValue(28), 11967.3156);
    assertDecimalEquals(kl.getValue(29), 11981.9387);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:24,代码来源:KeltnerChannelLowerIndicatorTest.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: withInitialLimitUsingClosePrice

import eu.verdelhan.ta4j.Decimal; //导入方法依赖的package包/类
@Test
public void withInitialLimitUsingClosePrice() {
    ClosePriceIndicator price = new ClosePriceIndicator(data); 
    TrailingStopLossIndicator tsl = new TrailingStopLossIndicator(price,
            Decimal.valueOf(3), Decimal.valueOf(21));
    
    assertDecimalEquals(tsl.getValue(0), 21);
    assertDecimalEquals(tsl.getValue(1), 21);
    assertDecimalEquals(tsl.getValue(2), 21);

    assertDecimalEquals(tsl.getValue(8), 21);
    assertDecimalEquals(tsl.getValue(9), 22);
    assertDecimalEquals(tsl.getValue(10), 23);
    assertDecimalEquals(tsl.getValue(11), 26);
    assertDecimalEquals(tsl.getValue(12), 26);
    assertDecimalEquals(tsl.getValue(13), 26);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:18,代码来源:TrailingStopLossIndicatorTest.java

示例9: 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

示例10: 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

示例11: 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

示例12: buildStrategy

import eu.verdelhan.ta4j.Decimal; //导入方法依赖的package包/类
/**
 * Build the {@link eu.verdelhan.ta4j.Strategy Strategy} to use for
 * trading and backtesting.
 *
 * @param series
 * {@link eu.verdelhan.ta4j.TimeSeries TimeSeries} to use when building the {@link eu.verdelhan.ta4j.Strategy Strategy}
 * @return the rules to build the
 * {@link eu.verdelhan.ta4j.Strategy Strategy}.
 */
@Contract("null -> fail")
private static Tuple2<Rule, Rule> buildStrategy(TimeSeries series) {
    if (series == null) {
        throw new IllegalArgumentException("Series cannot be null");
    }

    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);

    // Chande Moving Oscillator
    CMOIndicator cmoIndicator = new CMOIndicator(series, 14);

    // Aroon indicators
    AroonUpIndicator aroonUpIndicator = new AroonUpIndicator(series, 25);
    AroonDownIndicator aroonDownIndicator = new AroonDownIndicator
            (series, 25);

    RSIIndicator rsi = new RSIIndicator(closePrice, 14);

    Rule entryRule = new OverIndicatorRule(aroonUpIndicator,
            aroonDownIndicator).and(new CrossedUpIndicatorRule(rsi,
            Decimal.valueOf(30)));

    // Protect assets on loss
    Rule stopLoss = new StopLossRule(closePrice, Decimal.valueOf(15));

    Rule exitRule = new AndRule(new OverIndicatorRule(aroonDownIndicator,
            aroonUpIndicator), new CrossedDownIndicatorRule(rsi, Decimal
            .valueOf(70))).or(stopLoss);

    return new Tuple2<>(entryRule, exitRule);
}
 
开发者ID:KosherBacon,项目名称:JavaBitcoinTrader,代码行数:41,代码来源:MomentumStrategy.java

示例13: init

import eu.verdelhan.ta4j.Decimal; //导入方法依赖的package包/类
@Override
protected void init() {
  validateThree();
  keltnerChannelMiddle = new KeltnerChannelMiddleIndicator(series, instance.getTimeframe1());
  keltnerChannelUpper = new KeltnerChannelUpperIndicator(
      keltnerChannelMiddle, Decimal.valueOf(instance.getTimeframe2()), instance.getTimeframe3());
  keltnerChannelLower = new KeltnerChannelLowerIndicator(
      keltnerChannelMiddle, Decimal.valueOf(instance.getTimeframe2()), instance.getTimeframe3());
}
 
开发者ID:the-james-burton,项目名称:the-turbine,代码行数:10,代码来源:KeltnerChannels.java

示例14: init

import eu.verdelhan.ta4j.Decimal; //导入方法依赖的package包/类
@Override
protected void init() {
  validateTwo();
  smaIndicator = new SMAIndicator(closePriceIndicator, instance.getTimeframe1());
  standardDeviationIndicator = new StandardDeviationIndicator(smaIndicator, instance.getTimeframe1());
  bollingerBandsMiddleIndicator = new BollingerBandsMiddleIndicator(
      smaIndicator);
  bollingerBandsLowerIndicator = new BollingerBandsLowerIndicator(
      bollingerBandsMiddleIndicator, standardDeviationIndicator, Decimal.valueOf(instance.getTimeframe2()));
  bollingerBandsUpperIndicator = new BollingerBandsUpperIndicator(
      bollingerBandsMiddleIndicator, standardDeviationIndicator, Decimal.valueOf(instance.getTimeframe2()));

}
 
开发者ID:the-james-burton,项目名称:the-turbine,代码行数:14,代码来源:BollingerBands.java

示例15: init

import eu.verdelhan.ta4j.Decimal; //导入方法依赖的package包/类
@Override
protected void init() {
  validateTwo();
  chandelierExitLong = new ChandelierExitLongIndicator(
      series, instance.getTimeframe1(), Decimal.valueOf(instance.getTimeframe2()));
  chandelierExitShort = new ChandelierExitShortIndicator(
      series, instance.getTimeframe1(), Decimal.valueOf(instance.getTimeframe2()));
}
 
开发者ID:the-james-burton,项目名称:the-turbine,代码行数:9,代码来源:ChandelierExit.java


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