Search in sources :

Example 1 with TimeSeriesManager

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);
    }
}
Also used : Trade(org.ta4j.core.Trade) Minute(org.jfree.data.time.Minute) TimeSeriesManager(org.ta4j.core.TimeSeriesManager) ValueMarker(org.jfree.chart.plot.ValueMarker) Marker(org.jfree.chart.plot.Marker) ValueMarker(org.jfree.chart.plot.ValueMarker)

Example 2 with TimeSeriesManager

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));
}
Also used : TimeSeries(org.ta4j.core.TimeSeries) TradingRecord(org.ta4j.core.TradingRecord) TimeSeriesManager(org.ta4j.core.TimeSeriesManager) MovingMomentumStrategy(ta4jexamples.strategies.MovingMomentumStrategy) Strategy(org.ta4j.core.Strategy)

Example 3 with TimeSeriesManager

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);
}
Also used : TimeSeries(org.ta4j.core.TimeSeries) TimeSeriesManager(org.ta4j.core.TimeSeriesManager) Strategy(org.ta4j.core.Strategy) CCICorrectionStrategy(ta4jexamples.strategies.CCICorrectionStrategy)

Example 4 with TimeSeriesManager

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);
}
Also used : TimeSeriesManager(org.ta4j.core.TimeSeriesManager) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) BaseStrategy(org.ta4j.core.BaseStrategy) Strategy(org.ta4j.core.Strategy) Test(org.junit.Test)

Example 5 with TimeSeriesManager

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);
}
Also used : TimeSeriesManager(org.ta4j.core.TimeSeriesManager) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) BaseStrategy(org.ta4j.core.BaseStrategy) Strategy(org.ta4j.core.Strategy) Test(org.junit.Test)

Aggregations

TimeSeriesManager (org.ta4j.core.TimeSeriesManager)5 Strategy (org.ta4j.core.Strategy)4 Test (org.junit.Test)2 BaseStrategy (org.ta4j.core.BaseStrategy)2 TimeSeries (org.ta4j.core.TimeSeries)2 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)2 Marker (org.jfree.chart.plot.Marker)1 ValueMarker (org.jfree.chart.plot.ValueMarker)1 Minute (org.jfree.data.time.Minute)1 Trade (org.ta4j.core.Trade)1 TradingRecord (org.ta4j.core.TradingRecord)1 CCICorrectionStrategy (ta4jexamples.strategies.CCICorrectionStrategy)1 MovingMomentumStrategy (ta4jexamples.strategies.MovingMomentumStrategy)1