use of org.ta4j.core.Strategy in project crypto-bot by jnidzwetzki.
the class EMABot method createStrategies.
/**
* Init the trading stretegies
*/
private void createStrategies() {
for (final BitfinexCurrencyPair currency : tradedCurrencies) {
TradeStrategyFactory strategyFactory = new EMAStrategy03(5, 12, 40, timeSeries.get(currency));
final Strategy strategy = strategyFactory.getStrategy();
strategies.put(currency, strategy);
}
}
use of org.ta4j.core.Strategy 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.Strategy 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.Strategy in project ta4j by ta4j.
the class AbstractAnalysisCriterionTest method setUp.
@Before
public void setUp() {
alwaysStrategy = new BaseStrategy(BooleanRule.TRUE, BooleanRule.TRUE);
buyAndHoldStrategy = new BaseStrategy(new FixedRule(0), new FixedRule(4));
strategies = new ArrayList<Strategy>();
strategies.add(alwaysStrategy);
strategies.add(buyAndHoldStrategy);
}
use of org.ta4j.core.Strategy in project ta4j by ta4j.
the class CachedIndicatorTest method strategyExecutionOnCachedIndicatorAndLimitedTimeSeries.
@Test
public void strategyExecutionOnCachedIndicatorAndLimitedTimeSeries() {
TimeSeries timeSeries = new MockTimeSeries(0, 1, 2, 3, 4, 5, 6, 7);
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(timeSeries), 2);
// Theoretical values for SMA(2) cache: 0, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5
timeSeries.setMaximumBarCount(6);
// Theoretical values for SMA(2) cache: null, null, 2, 2.5, 3.5, 4.5, 5.5, 6.5
Strategy strategy = new BaseStrategy(new OverIndicatorRule(sma, Decimal.THREE), new UnderIndicatorRule(sma, Decimal.THREE));
// Theoretical shouldEnter results: false, false, false, false, true, true, true, true
// Theoretical shouldExit results: false, false, true, true, false, false, false, false
// As we return the first bar/result found for the removed bars:
// -> Approximated values for ClosePrice cache: 2, 2, 2, 3, 4, 5, 6, 7
// -> Approximated values for SMA(2) cache: 2, 2, 2, 2.5, 3.5, 4.5, 5.5, 6.5
// Then enters/exits are also approximated:
// -> shouldEnter results: false, false, false, false, true, true, true, true
// -> shouldExit results: true, true, true, true, false, false, false, false
assertFalse(strategy.shouldEnter(0));
assertTrue(strategy.shouldExit(0));
assertFalse(strategy.shouldEnter(1));
assertTrue(strategy.shouldExit(1));
assertFalse(strategy.shouldEnter(2));
assertTrue(strategy.shouldExit(2));
assertFalse(strategy.shouldEnter(3));
assertTrue(strategy.shouldExit(3));
assertTrue(strategy.shouldEnter(4));
assertFalse(strategy.shouldExit(4));
assertTrue(strategy.shouldEnter(5));
assertFalse(strategy.shouldExit(5));
assertTrue(strategy.shouldEnter(6));
assertFalse(strategy.shouldExit(6));
assertTrue(strategy.shouldEnter(7));
assertFalse(strategy.shouldExit(7));
}
Aggregations