Search in sources :

Example 1 with TotalProfitCriterion

use of org.ta4j.core.analysis.criteria.TotalProfitCriterion in project ta4j by ta4j.

the class CCICorrectionStrategy method main.

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));
}
Also used : TotalProfitCriterion(org.ta4j.core.analysis.criteria.TotalProfitCriterion)

Example 2 with TotalProfitCriterion

use of org.ta4j.core.analysis.criteria.TotalProfitCriterion in project ta4j by ta4j.

the class GlobalExtremaStrategy method main.

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));
}
Also used : TotalProfitCriterion(org.ta4j.core.analysis.criteria.TotalProfitCriterion)

Example 3 with TotalProfitCriterion

use of org.ta4j.core.analysis.criteria.TotalProfitCriterion in project ta4j by ta4j.

the class MovingMomentumStrategy method main.

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));
}
Also used : TotalProfitCriterion(org.ta4j.core.analysis.criteria.TotalProfitCriterion)

Example 4 with TotalProfitCriterion

use of org.ta4j.core.analysis.criteria.TotalProfitCriterion in project ta4j by ta4j.

the class RSI2Strategy method main.

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));
}
Also used : TotalProfitCriterion(org.ta4j.core.analysis.criteria.TotalProfitCriterion)

Example 5 with TotalProfitCriterion

use of org.ta4j.core.analysis.criteria.TotalProfitCriterion in project ta4j by ta4j.

the class WalkForward method main.

public static void main(String[] args) {
    // Splitting the series into slices
    TimeSeries series = CsvTradesLoader.loadBitstampSeries();
    List<TimeSeries> subseries = splitSeries(series, Duration.ofHours(6), Duration.ofDays(7));
    // Building the map of strategies
    Map<Strategy, String> strategies = buildStrategiesMap(series);
    // The analysis criterion
    AnalysisCriterion profitCriterion = new TotalProfitCriterion();
    for (TimeSeries slice : subseries) {
        // For each sub-series...
        System.out.println("Sub-series: " + slice.getSeriesPeriodDescription());
        TimeSeriesManager sliceManager = new TimeSeriesManager(slice);
        for (Map.Entry<Strategy, String> entry : strategies.entrySet()) {
            Strategy strategy = entry.getKey();
            String name = entry.getValue();
            // For each strategy...
            TradingRecord tradingRecord = sliceManager.run(strategy);
            double profit = profitCriterion.calculate(slice, tradingRecord);
            System.out.println("\tProfit for " + name + ": " + profit);
        }
        Strategy bestStrategy = profitCriterion.chooseBest(sliceManager, new ArrayList<Strategy>(strategies.keySet()));
        System.out.println("\t\t--> Best strategy: " + strategies.get(bestStrategy) + "\n");
    }
}
Also used : TotalProfitCriterion(org.ta4j.core.analysis.criteria.TotalProfitCriterion) GlobalExtremaStrategy(ta4jexamples.strategies.GlobalExtremaStrategy) CCICorrectionStrategy(ta4jexamples.strategies.CCICorrectionStrategy) MovingMomentumStrategy(ta4jexamples.strategies.MovingMomentumStrategy) RSI2Strategy(ta4jexamples.strategies.RSI2Strategy) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TotalProfitCriterion (org.ta4j.core.analysis.criteria.TotalProfitCriterion)6 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CashFlow (org.ta4j.core.analysis.CashFlow)1 AverageProfitableTradesCriterion (org.ta4j.core.analysis.criteria.AverageProfitableTradesCriterion)1 RewardRiskRatioCriterion (org.ta4j.core.analysis.criteria.RewardRiskRatioCriterion)1 VersusBuyAndHoldCriterion (org.ta4j.core.analysis.criteria.VersusBuyAndHoldCriterion)1 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)1 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)1 CrossedDownIndicatorRule (org.ta4j.core.trading.rules.CrossedDownIndicatorRule)1 CrossedUpIndicatorRule (org.ta4j.core.trading.rules.CrossedUpIndicatorRule)1 StopGainRule (org.ta4j.core.trading.rules.StopGainRule)1 StopLossRule (org.ta4j.core.trading.rules.StopLossRule)1 CCICorrectionStrategy (ta4jexamples.strategies.CCICorrectionStrategy)1 GlobalExtremaStrategy (ta4jexamples.strategies.GlobalExtremaStrategy)1 MovingMomentumStrategy (ta4jexamples.strategies.MovingMomentumStrategy)1 RSI2Strategy (ta4jexamples.strategies.RSI2Strategy)1