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


Java Decimal.ONE属性代码示例

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


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

示例1: getTotalReturn

/**
 * Gets the TotalReturn from the calculated results of the method 'calculate'.
 * For a timeFrame = number of trading days within a year (e. g. 251 days in the US) 
 * and "end of day"-ticks you will get the 'Annualized Total Return'.
 * Only complete timeFrames are taken into the calculation.
 * @return the total return from the calculated results of the method 'calculate'
 */
public double getTotalReturn() {

    Decimal totalProduct = Decimal.ONE;
    int completeTimeframes = (getTimeSeries().getTickCount() / timeFrame);

    for (int i = 1; i <= completeTimeframes; i++) {
        int index = i * timeFrame;
        Decimal currentReturn = getValue(index);

        // Skip NaN at the end of a series
        if (currentReturn != Decimal.NaN) {
            currentReturn = currentReturn.plus(Decimal.ONE);
            totalProduct = totalProduct.multipliedBy(currentReturn);
        }
    }

    return (Math.pow(totalProduct.toDouble(), (1.0 / completeTimeframes)));
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:25,代码来源:PeriodicalGrowthRateIndicator.java

示例2: isSatisfied

@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,代码行数:24,代码来源:StopLossRuleTest.java

示例3: isSatisfied

@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,代码行数:24,代码来源:StopGainRuleTest.java

示例4: setUp

@Before
public void setUp() {
    constantIndicator = new ConstantIndicator<Decimal>(Decimal.valueOf(6));
    mockIndicator = new FixedIndicator<Decimal>(
            Decimal.valueOf("-2.0"),
            Decimal.valueOf("0.00"),
            Decimal.valueOf("1.00"),
            Decimal.valueOf("2.53"),
            Decimal.valueOf("5.87"),
            Decimal.valueOf("6.00"),
            Decimal.valueOf("10.0")
    );
    mockIndicator2 = new FixedIndicator<Decimal>(
            Decimal.ZERO,
            Decimal.ONE,
            Decimal.TWO,
            Decimal.THREE,
            Decimal.TEN,
            Decimal.valueOf("-42"),
            Decimal.valueOf("-1337")
    );
    sumIndicator = new SumIndicator(constantIndicator, mockIndicator, mockIndicator2);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:23,代码来源:SumIndicatorTest.java

示例5: generateRandomTick

/**
 * Generates a random tick.
 * @return a random tick
 */
private static Tick generateRandomTick() {
    final Decimal maxRange = Decimal.valueOf("0.03"); // 3.0%
    Decimal openPrice = LAST_TICK_CLOSE_PRICE;
    Decimal minPrice = openPrice.minus(openPrice.multipliedBy(maxRange.multipliedBy(Decimal.valueOf(Math.random()))));
    Decimal maxPrice = openPrice.plus(openPrice.multipliedBy(maxRange.multipliedBy(Decimal.valueOf(Math.random()))));
    Decimal closePrice = randDecimal(minPrice, maxPrice);
    LAST_TICK_CLOSE_PRICE = closePrice;
    return new BaseTick(ZonedDateTime.now(), openPrice, maxPrice, minPrice, closePrice, Decimal.ONE);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:13,代码来源:TradingBotOnMovingTimeSeries.java

示例6: calculateProfit

/**
 * Calculates the profit of a trade (Buy and sell).
 * @param series a time series
 * @param trade a trade
 * @return the profit of the trade
 */
private double calculateProfit(TimeSeries series, Trade trade) {
    Decimal profit = Decimal.ONE;
    if (trade.isClosed()) {
        Decimal exitClosePrice = series.getTick(trade.getExit().getIndex()).getClosePrice();
        Decimal entryClosePrice = series.getTick(trade.getEntry().getIndex()).getClosePrice();

        if (trade.getEntry().isBuy()) {
            profit = exitClosePrice.dividedBy(entryClosePrice);
        } else {
            profit = entryClosePrice.dividedBy(exitClosePrice);
        }
    }
    return profit.toDouble();
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:20,代码来源:TotalProfitCriterion.java

示例7: calculate

@Override
protected Decimal calculate(int index) {
    if (index == 0) {
        return Decimal.ONE;
    }
    Decimal nbPeriods = Decimal.valueOf(timeFrame);
    Decimal nbPeriodsMinusOne = Decimal.valueOf(timeFrame - 1);
    return getValue(index - 1).multipliedBy(nbPeriodsMinusOne).plus(tr.getValue(index)).dividedBy(nbPeriods);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:9,代码来源:AverageTrueRangeIndicator.java

示例8: calculate

@Override
protected Decimal calculate(int index) {
    if (index == 0) {
        return Decimal.ONE;
    }
    Decimal nbPeriods = Decimal.valueOf(timeFrame);
    Decimal nbPeriodsMinusOne = Decimal.valueOf(timeFrame - 1);
    return getValue(index - 1).multipliedBy(nbPeriodsMinusOne).dividedBy(nbPeriods).plus(dmup.getValue(index).dividedBy(nbPeriods));
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:9,代码来源:AverageDirectionalMovementUpIndicator.java

示例9: calculate

@Override
protected Decimal calculate(int index) {
    if (index == 0) {
        return Decimal.ONE;
    }
    Decimal nbPeriods = Decimal.valueOf(timeFrame);
    Decimal nbPeriodsMinusOne = Decimal.valueOf(timeFrame - 1);
    return getValue(index - 1).multipliedBy(nbPeriodsMinusOne).dividedBy(nbPeriods).plus(dmdown.getValue(index).dividedBy(nbPeriods));

}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:10,代码来源:AverageDirectionalMovementDownIndicator.java

示例10: calculate

@Override
protected Decimal calculate(int index) {
    if (index == 0) {
        return Decimal.ONE;
    }
    Decimal nbPeriods = Decimal.valueOf(timeFrame);
    Decimal nbPeriodsMinusOne = Decimal.valueOf(timeFrame - 1);
    return getValue(index - 1).multipliedBy(nbPeriodsMinusOne).dividedBy(nbPeriods).plus(dm.getValue(index).dividedBy(nbPeriods));
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:9,代码来源:AverageDirectionalMovementIndicator.java


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