use of org.ta4j.core.TimeSeriesManager in project crypto-bot by jnidzwetzki.
the class Chart method addBuySellSignals.
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.getBar(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.getBar(trade.getExit().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
Marker sellMarker = new ValueMarker(sellSignalTickTime);
sellMarker.setPaint(Color.RED);
sellMarker.setLabel("S");
plot.addDomainMarker(sellMarker);
}
}
use of org.ta4j.core.TimeSeriesManager in project ta4j by ta4j.
the class StrategyAnalysis method main.
public static void main(String[] args) {
// Getting the time series
TimeSeries series = CsvTradesLoader.loadBitstampSeries();
// Building the trading strategy
Strategy strategy = MovingMomentumStrategy.buildStrategy(series);
// Running the strategy
TimeSeriesManager seriesManager = new TimeSeriesManager(series);
TradingRecord tradingRecord = seriesManager.run(strategy);
/*
Analysis criteria
*/
// Total profit
TotalProfitCriterion totalProfit = new TotalProfitCriterion();
System.out.println("Total profit: " + totalProfit.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 profit (per bar): " + new AverageProfitCriterion().calculate(series, tradingRecord));
// Number of trades
System.out.println("Number of trades: " + new NumberOfTradesCriterion().calculate(series, tradingRecord));
// Profitable trades ratio
System.out.println("Profitable trades ratio: " + new AverageProfitableTradesCriterion().calculate(series, tradingRecord));
// Maximum drawdown
System.out.println("Maximum drawdown: " + new MaximumDrawdownCriterion().calculate(series, tradingRecord));
// Reward-risk ratio
System.out.println("Reward-risk ratio: " + new RewardRiskRatioCriterion().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: " + new BuyAndHoldCriterion().calculate(series, tradingRecord));
// Total profit vs buy-and-hold
System.out.println("Custom strategy profit vs buy-and-hold strategy profit: " + new VersusBuyAndHoldCriterion(totalProfit).calculate(series, tradingRecord));
}
use of org.ta4j.core.TimeSeriesManager in project ta4j by ta4j.
the class StrategyExecutionLogging method main.
public static void main(String[] args) {
// Loading the Logback configuration
loadLoggerConfiguration();
// Getting the time series
TimeSeries series = CsvTradesLoader.loadBitstampSeries();
// Building the trading strategy
Strategy strategy = CCICorrectionStrategy.buildStrategy(series);
// Running the strategy
TimeSeriesManager seriesManager = new TimeSeriesManager(series);
seriesManager.run(strategy);
}
use of org.ta4j.core.TimeSeriesManager in project ta4j by ta4j.
the class AbstractAnalysisCriterionTest method bestShouldBeBuyAndHoldOnLoss.
@Test
public void bestShouldBeBuyAndHoldOnLoss() {
MockTimeSeries series = new MockTimeSeries(6.0, 3.0, 6.0, 6.0);
TimeSeriesManager manager = new TimeSeriesManager(series);
Strategy bestStrategy = new TotalProfitCriterion().chooseBest(manager, strategies);
assertEquals(buyAndHoldStrategy, bestStrategy);
}
use of org.ta4j.core.TimeSeriesManager in project ta4j by ta4j.
the class AbstractAnalysisCriterionTest method bestShouldBeAlwaysOperateOnProfit.
@Test
public void bestShouldBeAlwaysOperateOnProfit() {
MockTimeSeries series = new MockTimeSeries(6.0, 9.0, 6.0, 6.0);
TimeSeriesManager manager = new TimeSeriesManager(series);
Strategy bestStrategy = new TotalProfitCriterion().chooseBest(manager, strategies);
assertEquals(alwaysStrategy, bestStrategy);
}
Aggregations