@Test public void test() { Quickstart.main(null); }
public static void main(String[] args) { BarSeries series = CsvTradesLoader.loadBitstampSeries(); Num firstClosePrice = series.getBar(0).getClosePrice(); System.out.println("First close price: " + firstClosePrice.doubleValue()); ClosePriceIndicator closePrice = new ClosePriceIndicator(series); System.out.println(firstClosePrice.isEqual(closePrice.getValue(0))); SMAIndicator shortSma = new SMAIndicator(closePrice, 5); System.out.println("5-bars-SMA value at the 42nd index: " + shortSma.getValue(42).doubleValue()); SMAIndicator longSma = new SMAIndicator(closePrice, 30); Rule buyingRule = new CrossedUpIndicatorRule(shortSma, longSma) .or(new CrossedDownIndicatorRule(closePrice, 800)); Rule sellingRule = new CrossedDownIndicatorRule(shortSma, longSma) .or(new StopLossRule(closePrice, series.numOf(3))).or(new StopGainRule(closePrice, series.numOf(2))); BarSeriesManager seriesManager = new BarSeriesManager(series); TradingRecord tradingRecord = seriesManager.run(new BaseStrategy(buyingRule, sellingRule)); System.out.println("Number of trades for our strategy: " + tradingRecord.getTradeCount()); AnalysisCriterion profitTradesRatio = new AverageProfitableTradesCriterion(); System.out.println("Profitable trades ratio: " + profitTradesRatio.calculate(series, tradingRecord)); AnalysisCriterion rewardRiskRatio = new RewardRiskRatioCriterion(); System.out.println("Reward-risk ratio: " + rewardRiskRatio.calculate(series, tradingRecord)); AnalysisCriterion vsBuyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion()); System.out.println("Our profit vs buy-and-hold profit: " + vsBuyAndHold.calculate(series, tradingRecord)); }
Quickstart { public static void main(String[] args) { BarSeries series = CsvTradesLoader.loadBitstampSeries(); Num firstClosePrice = series.getBar(0).getClosePrice(); System.out.println("First close price: " + firstClosePrice.doubleValue()); ClosePriceIndicator closePrice = new ClosePriceIndicator(series); System.out.println(firstClosePrice.isEqual(closePrice.getValue(0))); SMAIndicator shortSma = new SMAIndicator(closePrice, 5); System.out.println("5-bars-SMA value at the 42nd index: " + shortSma.getValue(42).doubleValue()); SMAIndicator longSma = new SMAIndicator(closePrice, 30); Rule buyingRule = new CrossedUpIndicatorRule(shortSma, longSma) .or(new CrossedDownIndicatorRule(closePrice, 800)); Rule sellingRule = new CrossedDownIndicatorRule(shortSma, longSma) .or(new StopLossRule(closePrice, series.numOf(3))).or(new StopGainRule(closePrice, series.numOf(2))); BarSeriesManager seriesManager = new BarSeriesManager(series); TradingRecord tradingRecord = seriesManager.run(new BaseStrategy(buyingRule, sellingRule)); System.out.println("Number of trades for our strategy: " + tradingRecord.getTradeCount()); AnalysisCriterion profitTradesRatio = new AverageProfitableTradesCriterion(); System.out.println("Profitable trades ratio: " + profitTradesRatio.calculate(series, tradingRecord)); AnalysisCriterion rewardRiskRatio = new RewardRiskRatioCriterion(); System.out.println("Reward-risk ratio: " + rewardRiskRatio.calculate(series, tradingRecord)); AnalysisCriterion vsBuyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion()); System.out.println("Our profit vs buy-and-hold profit: " + vsBuyAndHold.calculate(series, tradingRecord)); } }
Quickstart { public static void main(String[] args) { BarSeries series = CsvTradesLoader.loadBitstampSeries(); Num firstClosePrice = series.getBar(0).getClosePrice(); System.out.println("First close price: " + firstClosePrice.doubleValue()); ClosePriceIndicator closePrice = new ClosePriceIndicator(series); System.out.println(firstClosePrice.isEqual(closePrice.getValue(0))); SMAIndicator shortSma = new SMAIndicator(closePrice, 5); System.out.println("5-bars-SMA value at the 42nd index: " + shortSma.getValue(42).doubleValue()); SMAIndicator longSma = new SMAIndicator(closePrice, 30); Rule buyingRule = new CrossedUpIndicatorRule(shortSma, longSma) .or(new CrossedDownIndicatorRule(closePrice, 800)); Rule sellingRule = new CrossedDownIndicatorRule(shortSma, longSma) .or(new StopLossRule(closePrice, series.numOf(3))).or(new StopGainRule(closePrice, series.numOf(2))); BarSeriesManager seriesManager = new BarSeriesManager(series); TradingRecord tradingRecord = seriesManager.run(new BaseStrategy(buyingRule, sellingRule)); System.out.println("Number of trades for our strategy: " + tradingRecord.getTradeCount()); AnalysisCriterion profitTradesRatio = new AverageProfitableTradesCriterion(); System.out.println("Profitable trades ratio: " + profitTradesRatio.calculate(series, tradingRecord)); AnalysisCriterion rewardRiskRatio = new RewardRiskRatioCriterion(); System.out.println("Reward-risk ratio: " + rewardRiskRatio.calculate(series, tradingRecord)); AnalysisCriterion vsBuyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion()); System.out.println("Our profit vs buy-and-hold profit: " + vsBuyAndHold.calculate(series, tradingRecord)); }  }
Quickstart { public static void main(String[] args) { BarSeries series = CsvTradesLoader.loadBitstampSeries(); Num firstClosePrice = series.getBar(0).getClosePrice(); System.out.println("First close price: " + firstClosePrice.doubleValue()); ClosePriceIndicator closePrice = new ClosePriceIndicator(series); System.out.println(firstClosePrice.isEqual(closePrice.getValue(0))); SMAIndicator shortSma = new SMAIndicator(closePrice, 5); System.out.println("5-bars-SMA value at the 42nd index: " + shortSma.getValue(42).doubleValue()); SMAIndicator longSma = new SMAIndicator(closePrice, 30); Rule buyingRule = new CrossedUpIndicatorRule(shortSma, longSma) .or(new CrossedDownIndicatorRule(closePrice, 800)); Rule sellingRule = new CrossedDownIndicatorRule(shortSma, longSma) .or(new StopLossRule(closePrice, series.numOf(3))).or(new StopGainRule(closePrice, series.numOf(2))); BarSeriesManager seriesManager = new BarSeriesManager(series); TradingRecord tradingRecord = seriesManager.run(new BaseStrategy(buyingRule, sellingRule)); System.out.println("Number of trades for our strategy: " + tradingRecord.getTradeCount()); AnalysisCriterion profitTradesRatio = new AverageProfitableTradesCriterion(); System.out.println("Profitable trades ratio: " + profitTradesRatio.calculate(series, tradingRecord)); AnalysisCriterion rewardRiskRatio = new RewardRiskRatioCriterion(); System.out.println("Reward-risk ratio: " + rewardRiskRatio.calculate(series, tradingRecord)); AnalysisCriterion vsBuyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion()); System.out.println("Our profit vs buy-and-hold profit: " + vsBuyAndHold.calculate(series, tradingRecord)); }  static void main(String[] args); }
Quickstart { public static void main(String[] args) { BarSeries series = CsvTradesLoader.loadBitstampSeries(); Num firstClosePrice = series.getBar(0).getClosePrice(); System.out.println("First close price: " + firstClosePrice.doubleValue()); ClosePriceIndicator closePrice = new ClosePriceIndicator(series); System.out.println(firstClosePrice.isEqual(closePrice.getValue(0))); SMAIndicator shortSma = new SMAIndicator(closePrice, 5); System.out.println("5-bars-SMA value at the 42nd index: " + shortSma.getValue(42).doubleValue()); SMAIndicator longSma = new SMAIndicator(closePrice, 30); Rule buyingRule = new CrossedUpIndicatorRule(shortSma, longSma) .or(new CrossedDownIndicatorRule(closePrice, 800)); Rule sellingRule = new CrossedDownIndicatorRule(shortSma, longSma) .or(new StopLossRule(closePrice, series.numOf(3))).or(new StopGainRule(closePrice, series.numOf(2))); BarSeriesManager seriesManager = new BarSeriesManager(series); TradingRecord tradingRecord = seriesManager.run(new BaseStrategy(buyingRule, sellingRule)); System.out.println("Number of trades for our strategy: " + tradingRecord.getTradeCount()); AnalysisCriterion profitTradesRatio = new AverageProfitableTradesCriterion(); System.out.println("Profitable trades ratio: " + profitTradesRatio.calculate(series, tradingRecord)); AnalysisCriterion rewardRiskRatio = new RewardRiskRatioCriterion(); System.out.println("Reward-risk ratio: " + rewardRiskRatio.calculate(series, tradingRecord)); AnalysisCriterion vsBuyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion()); System.out.println("Our profit vs buy-and-hold profit: " + vsBuyAndHold.calculate(series, tradingRecord)); }  static void main(String[] args);  }