### Question:
TimeSeriesManager { public TradingRecord run(Strategy strategy) { return run(strategy, OrderType.BUY); } TimeSeriesManager();  TimeSeriesManager(TimeSeries timeSeries); void setTimeSeries(TimeSeries timeSeries); TimeSeries getTimeSeries(); TradingRecord run(Strategy strategy); TradingRecord run(Strategy strategy, int startIndex, int finishIndex); TradingRecord run(Strategy strategy, OrderType orderType); TradingRecord run(Strategy strategy, OrderType orderType, int startIndex, int finishIndex); TradingRecord run(Strategy strategy, OrderType orderType, Decimal amount); TradingRecord run(Strategy strategy, OrderType orderType, Decimal amount, int startIndex, int finishIndex);  }### Answer:
@Test public void runWithOpenEntrySellLeft() { Strategy aStrategy = new BaseStrategy(new FixedRule(1), new FixedRule(3)); List<Trade> trades = manager.run(aStrategy, OrderType.SELL, 0, 3).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.sellAt(1, seriesForRun.getTick(1).getClosePrice(), Decimal.NaN), trades.get(0).getEntry()); assertEquals(Order.buyAt(3, seriesForRun.getTick(3).getClosePrice(), Decimal.NaN), trades.get(0).getExit()); }
@Test public void runBetweenIndexes() { List<Trade> trades = manager.run(strategy, 0, 3).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.buyAt(2, seriesForRun.getTick(2).getClosePrice(), Decimal.NaN), trades.get(0).getEntry()); assertEquals(Order.sellAt(4, seriesForRun.getTick(4).getClosePrice(), Decimal.NaN), trades.get(0).getExit()); trades = manager.run(strategy, 4, 4).getTrades(); assertTrue(trades.isEmpty()); trades = manager.run(strategy, 5, 8).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.buyAt(6, seriesForRun.getTick(6).getClosePrice(), Decimal.NaN), trades.get(0).getEntry()); assertEquals(Order.sellAt(7, seriesForRun.getTick(7).getClosePrice(), Decimal.NaN), trades.get(0).getExit()); }
@Test public void runOnSeries() { List<Trade> trades = manager.run(strategy).getTrades(); assertEquals(2, trades.size()); assertEquals(Order.buyAt(2, seriesForRun.getTick(2).getClosePrice(), Decimal.NaN), trades.get(0).getEntry()); assertEquals(Order.sellAt(4, seriesForRun.getTick(4).getClosePrice(), Decimal.NaN), trades.get(0).getExit()); assertEquals(Order.buyAt(6, seriesForRun.getTick(6).getClosePrice(), Decimal.NaN), trades.get(1).getEntry()); assertEquals(Order.sellAt(7, seriesForRun.getTick(7).getClosePrice(), Decimal.NaN), trades.get(1).getExit()); }
@Test public void runWithOpenEntryBuyLeft() { Strategy aStrategy = new BaseStrategy(new FixedRule(1), new FixedRule(3)); List<Trade> trades = manager.run(aStrategy, 0, 3).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.buyAt(1, seriesForRun.getTick(1).getClosePrice(), Decimal.NaN), trades.get(0).getEntry()); assertEquals(Order.sellAt(3, seriesForRun.getTick(3).getClosePrice(), Decimal.NaN), trades.get(0).getExit()); }