public TradingRecord run(Strategy strategy, OrderType orderType, Decimal amount, int startIndex, int finishIndex) {

        int runBeginIndex = Math.max(startIndex, timeSeries.getBeginIndex());
        int runEndIndex = Math.min(finishIndex, timeSeries.getEndIndex());
        
        log.trace("Running strategy (indexes: {} -> {}): {} (starting with {})", runBeginIndex, runEndIndex, strategy, orderType);
        TradingRecord tradingRecord = new BaseTradingRecord(orderType);
        for (int i = runBeginIndex; i <= runEndIndex; i++) {
            // For each tick between both indexes...       
            if (strategy.shouldOperate(i, tradingRecord)) {
                tradingRecord.operate(i, timeSeries.getTick(i).getClosePrice(), amount);
            }
        }

        if (!tradingRecord.isClosed()) {
            // If the last trade is still opened, we search out of the run end index.
            // May works if the end index for this run was inferior to the actual number of ticks
        	int seriesMaxSize = Math.max(timeSeries.getEndIndex() + 1, timeSeries.getTickData().size());
            for (int i = runEndIndex + 1; i < seriesMaxSize; i++) {
                // For each tick after the end index of this run...
                // --> Trying to close the last trade
                if (strategy.shouldOperate(i, tradingRecord)) {
                    tradingRecord.operate(i, timeSeries.getTick(i).getClosePrice(), amount);
                    break;
                }
            }
        }
        return tradingRecord;
    }
public TradingRecord run(Strategy strategy, OrderType orderType, Decimal amount, int startIndex, int finishIndex) {

        int runBeginIndex = Math.max(startIndex, timeSeries.getBeginIndex());
        int runEndIndex = Math.min(finishIndex, timeSeries.getEndIndex());
        
        log.trace("Running strategy (indexes: {} -> {}): {} (starting with {})", runBeginIndex, runEndIndex, strategy, orderType);
        TradingRecord tradingRecord = new BaseTradingRecord(orderType);
        for (int i = runBeginIndex; i <= runEndIndex; i++) {
            
            if (strategy.shouldOperate(i, tradingRecord)) {
                tradingRecord.operate(i, timeSeries.getTick(i).getClosePrice(), amount);
            }
        }

        if (!tradingRecord.isClosed()) {
            
            
        	int seriesMaxSize = Math.max(timeSeries.getEndIndex() + 1, timeSeries.getTickData().size());
            for (int i = runEndIndex + 1; i < seriesMaxSize; i++) {
                
                
                if (strategy.shouldOperate(i, tradingRecord)) {
                    tradingRecord.operate(i, timeSeries.getTick(i).getClosePrice(), amount);
                    break;
                }
            }
        }
        return tradingRecord;
    }
public TradingRecord run ( Strategy strategy , OrderType orderType , Decimal amount , int startIndex , int finishIndex ) { int runBeginIndex = Math . max ( startIndex , timeSeries . getBeginIndex ( ) ) ; int runEndIndex = Math . min ( finishIndex , timeSeries . getEndIndex ( ) ) ; log . trace ( "Running strategy (indexes: {} -> {}): {} (starting with {})" , runBeginIndex , runEndIndex , strategy , orderType ) ; TradingRecord tradingRecord = new BaseTradingRecord ( orderType ) ; for ( int i = runBeginIndex ; i <= runEndIndex ; i ++ ) { // For each tick between both indexes...        if ( strategy . shouldOperate ( i , tradingRecord ) ) { tradingRecord . operate ( i , timeSeries . getTick ( i ) . getClosePrice ( ) , amount ) ; } } if ( ! tradingRecord . isClosed ( ) ) { // If the last trade is still opened, we search out of the run end index. // May works if the end index for this run was inferior to the actual number of ticks int seriesMaxSize = Math . max ( timeSeries . getEndIndex ( ) + 1 , timeSeries . getTickData ( ) . size ( ) ) ; for ( int i = runEndIndex + 1 ; i < seriesMaxSize ; i ++ ) { // For each tick after the end index of this run... // --> Trying to close the last trade if ( strategy . shouldOperate ( i , tradingRecord ) ) { tradingRecord . operate ( i , timeSeries . getTick ( i ) . getClosePrice ( ) , amount ) ; break ; } } } return tradingRecord ; }
Runs the provided strategy over the managed series (from startIndex to finishIndex).
<p>
@param strategy the trading strategy
@param orderType the {@link OrderType} used to open the trades
@param amount the amount used to open/close the trades
@param startIndex the start index for the run (included)
@param finishIndex the finish index for the run (included)
@return the trading record coming from the run
Runs the provided strategy over the managed series ( from startIndex to finishIndex ) . <p >