private void calculate ( Trade trade ) { final int entryIndex = trade . getEntry ( ) . getIndex ( ) ; int begin = entryIndex + 1 ; if ( begin > values . size ( ) ) { Decimal lastValue = values . get ( values . size ( ) - 1 ) ; values . addAll ( Collections . nCopies ( begin - values . size ( ) , lastValue ) ) ; } int end = trade . getExit ( ) . getIndex ( ) ; for ( int i = Math . max ( begin , 1 ) ; i <= end ; i ++ ) { Decimal ratio ; if ( trade . getEntry ( ) . isBuy ( ) ) { ratio = timeSeries . getTick ( i ) . getClosePrice ( ) . dividedBy ( timeSeries . getTick ( entryIndex ) . getClosePrice ( ) ) ; } else { ratio = timeSeries . getTick ( entryIndex ) . getClosePrice ( ) . dividedBy ( timeSeries . getTick ( i ) . getClosePrice ( ) ) ; } values . add ( values . get ( entryIndex ) . multipliedBy ( ratio ) ) ; } }
Calculates the cash flow for a single trade .