本文整理汇总了Java中eu.verdelhan.ta4j.TimeSeries类的典型用法代码示例。如果您正苦于以下问题:Java TimeSeries类的具体用法?Java TimeSeries怎么用?Java TimeSeries使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TimeSeries类属于eu.verdelhan.ta4j包,在下文中一共展示了TimeSeries类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: testLinearRegressionIndicator
import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
@Test
public void testLinearRegressionIndicator() {
/*
* Example adapted from: http://onlinestatbook.com/2/regression/intro.html
*/
List<Tick> ticks = Arrays.asList(
new Tick(DateTime.parse("2001-01-01"), 0,0,0,1,0),
new Tick(DateTime.parse("2001-01-02"), 0,0,0,2,0),
new Tick(DateTime.parse("2001-01-03"), 0,0,0,1.3,0),
new Tick(DateTime.parse("2001-01-04"), 0,0,0,3.75,0),
new Tick(DateTime.parse("2001-01-05"), 0,0,0,2.25,0)
);
TimeSeries timeSeries = new TimeSeries(ticks);
LinearRegressionIndicator linearRegressionIndicator = new LinearRegressionIndicator(new ClosePriceIndicator(timeSeries), timeSeries.getEnd());
assertDecimalEquals(linearRegressionIndicator.getValue(0), 1.21);
assertDecimalEquals(linearRegressionIndicator.getValue(1), 1.635);
assertDecimalEquals(linearRegressionIndicator.getValue(2), 2.06);
assertDecimalEquals(linearRegressionIndicator.getValue(3), 2.485);
assertDecimalEquals(linearRegressionIndicator.getValue(4), 2.91);
}
开发者ID:woodberry,项目名称:ta-toolbox,代码行数:22,代码来源:LinearRegressionIndicatorTest.java
示例17: buildStrategy
import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
/**
* @param series a time series
* @return a dummy strategy
*/
private static Strategy buildStrategy(TimeSeries series) {
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
SMAIndicator sma = new SMAIndicator(closePrice, 12);
// Signals
// Buy when SMA goes over close price
// Sell when close price goes over SMA
Strategy buySellSignals = new BaseStrategy(
new OverIndicatorRule(sma, closePrice),
new UnderIndicatorRule(sma, closePrice)
);
return buySellSignals;
}
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:22,代码来源:TradingBotOnMovingTimeSeries.java
示例18: 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 BaseStrategy(entryRule, exitRule);
strategy.setUnstablePeriod(5);
return strategy;
}
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:25,代码来源:CCICorrectionStrategy.java
示例19: main
import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
public static void main(String[] args) {
// Getting the time series
TimeSeries series = CsvTradesLoader.loadBitstampSeries();
// Building the trading strategy
Strategy strategy = buildStrategy(series);
// Running the strategy
TimeSeriesManager seriesManager = new TimeSeriesManager(series);
TradingRecord tradingRecord = seriesManager.run(strategy);
System.out.println("Number of trades for the strategy: " + tradingRecord.getTradeCount());
// Analysis
System.out.println("Total profit for the strategy: " + new TotalProfitCriterion().calculate(series, tradingRecord));
}
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:17,代码来源:MovingMomentumStrategy.java
示例20: addBuySellSignals
import eu.verdelhan.ta4j.TimeSeries; //导入依赖的package包/类
/**
* Runs a strategy over a time series and adds the value markers
* corresponding to buy/sell signals to the plot.
* @param series a time series
* @param strategy a trading strategy
* @param plot the plot
*/
private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) {
// Running the strategy
TimeSeriesManager seriesManager = new TimeSeriesManager(series);
List<Trade> trades = seriesManager.run(strategy).getTrades();
// Adding markers to plot
for (Trade trade : trades) {
// Buy signal
double buySignalTickTime = new Minute(Date.from(series.getTick(trade.getEntry().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
Marker buyMarker = new ValueMarker(buySignalTickTime);
buyMarker.setPaint(Color.GREEN);
buyMarker.setLabel("B");
plot.addDomainMarker(buyMarker);
// Sell signal
double sellSignalTickTime = new Minute(Date.from(series.getTick(trade.getExit().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
Marker sellMarker = new ValueMarker(sellSignalTickTime);
sellMarker.setPaint(Color.RED);
sellMarker.setLabel("S");
plot.addDomainMarker(sellMarker);
}
}
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:28,代码来源:BuyAndSellSignalsToChart.java
注:本文中的eu.verdelhan.ta4j.TimeSeries类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论