use of org.ta4j.core.BarSeriesManager in project ta4j by ta4j.
the class CompareNumTypes method test.
public static Num test(BarSeries series) {
ClosePriceIndicator closePriceIndicator = new ClosePriceIndicator(series);
RSIIndicator rsi = new RSIIndicator(closePriceIndicator, 100);
MACDIndicator macdIndicator = new MACDIndicator(rsi);
EMAIndicator ema = new EMAIndicator(rsi, 12);
EMAIndicator emaLong = new EMAIndicator(rsi, 26);
DifferenceIndicator macdIndicator2 = new DifferenceIndicator(ema, emaLong);
Rule entry = new IsEqualRule(macdIndicator, macdIndicator2);
Rule exit = new UnderIndicatorRule(new LowPriceIndicator(series), new HighPriceIndicator(series));
// enter/exit every tick
Strategy strategy1 = new BaseStrategy(entry, exit);
long start = System.currentTimeMillis();
BarSeriesManager manager = new BarSeriesManager(series);
TradingRecord record1 = manager.run(strategy1);
GrossReturnCriterion totalReturn1 = new GrossReturnCriterion();
Num returnResult1 = totalReturn1.calculate(series, record1);
long end = System.currentTimeMillis();
System.out.printf("[%s]\n" + " -Time: %s ms.\n" + " -Profit: %s \n" + " -Bars: %s\n \n", series.getName(), (end - start), returnResult1, series.getBarCount());
return returnResult1;
}
use of org.ta4j.core.BarSeriesManager in project ta4j by ta4j.
the class CCICorrectionStrategy method main.
public static void main(String[] args) {
// Getting the bar series
BarSeries series = CsvTradesLoader.loadBitstampSeries();
// Building the trading strategy
Strategy strategy = buildStrategy(series);
// Running the strategy
BarSeriesManager seriesManager = new BarSeriesManager(series);
TradingRecord tradingRecord = seriesManager.run(strategy);
System.out.println("Number of positions for the strategy: " + tradingRecord.getPositionCount());
// Analysis
System.out.println("Total return for the strategy: " + new GrossReturnCriterion().calculate(series, tradingRecord));
}
use of org.ta4j.core.BarSeriesManager in project ta4j by ta4j.
the class StrategyExecutionLogging method main.
public static void main(String[] args) {
// Loading the Logback configuration
loadLoggerConfiguration();
// Getting the bar series
BarSeries series = CsvTradesLoader.loadBitstampSeries();
// Building the trading strategy
Strategy strategy = CCICorrectionStrategy.buildStrategy(series);
// Running the strategy
BarSeriesManager seriesManager = new BarSeriesManager(series);
seriesManager.run(strategy);
// Unload the Logback configuration
unloadLoggerConfiguration();
}
use of org.ta4j.core.BarSeriesManager in project ta4j by ta4j.
the class UnstableIndicatorStrategy method test.
public static void test(String name, Stream<Double> closePrices) {
// Getting the bar series
BarSeries series = new BaseBarSeriesBuilder().withBars(closePrices.map(close -> new BaseBar(MINUTE, TIME, 0, 0, 0, close, 0)).collect(Collectors.toList())).build();
// Building the trading strategy
Strategy strategy = buildStrategy(series);
// Running the strategy
BarSeriesManager seriesManager = new BarSeriesManager(series);
TradingRecord tradingRecord = seriesManager.run(strategy);
System.out.println(name + " " + tradingRecord.getPositions());
}
use of org.ta4j.core.BarSeriesManager in project ta4j by ta4j.
the class StrategyAnalysis method main.
public static void main(String[] args) {
// Getting the bar series
BarSeries series = CsvTradesLoader.loadBitstampSeries();
// Building the trading strategy
Strategy strategy = MovingMomentumStrategy.buildStrategy(series);
// Running the strategy
BarSeriesManager seriesManager = new BarSeriesManager(series);
TradingRecord tradingRecord = seriesManager.run(strategy);
/*
* Analysis criteria
*/
// Total profit
GrossReturnCriterion totalReturn = new GrossReturnCriterion();
System.out.println("Total return: " + totalReturn.calculate(series, tradingRecord));
// Number of bars
System.out.println("Number of bars: " + new NumberOfBarsCriterion().calculate(series, tradingRecord));
// Average profit (per bar)
System.out.println("Average return (per bar): " + new AverageReturnPerBarCriterion().calculate(series, tradingRecord));
// Number of positions
System.out.println("Number of positions: " + new NumberOfPositionsCriterion().calculate(series, tradingRecord));
// Profitable position ratio
System.out.println("Winning positions ratio: " + new WinningPositionsRatioCriterion().calculate(series, tradingRecord));
// Maximum drawdown
System.out.println("Maximum drawdown: " + new MaximumDrawdownCriterion().calculate(series, tradingRecord));
// Reward-risk ratio
System.out.println("Return over maximum drawdown: " + new ReturnOverMaxDrawdownCriterion().calculate(series, tradingRecord));
// Total transaction cost
System.out.println("Total transaction cost (from $1000): " + new LinearTransactionCostCriterion(1000, 0.005).calculate(series, tradingRecord));
// Buy-and-hold
System.out.println("Buy-and-hold return: " + new BuyAndHoldReturnCriterion().calculate(series, tradingRecord));
// Total profit vs buy-and-hold
System.out.println("Custom strategy return vs buy-and-hold strategy return: " + new VersusBuyAndHoldCriterion(totalReturn).calculate(series, tradingRecord));
}
Aggregations