Buggy code:
public abstract class Strategy implements IBrokerListener { protected String name ; protected long dbId = - 1 ; protected String dbUrl ; protected IBroker broker ; protected BarHierarchy barData = new BarHierarchy ( ) ; protected List < Execution > executions = new ArrayList < Execution > ( ) ; private LocalDateTime tradingStart = LocalDateTime . of ( 1990 , 1 , 1 , 0 , 0 ) ; protected Account account = new Account ( ) ; protected Connection connection = null ; protected void connectIfNecessary ( ) throws SQLException { } public void initialize ( Context context ) throws Exception { } protected void setName ( String name ) { } protected void setDbUrl ( String dbUrl ) { } protected IBroker getBroker ( ) { } protected void subscribe ( String symbol ) throws Exception { } public void cleanupDb ( ) throws SQLException { } public void getDbId ( ) throws SQLException { } public void writeExecutions ( ) throws SQLException { } public void writeExecutionsAndTrades ( ) throws Exception { } public void writeTrades ( ) throws Exception { } public void writeTrades ( Instrument instrument ) throws Exception { BarHistory history = barData . getHistory ( instrument . getSymbol ( ) , Duration . ofDays ( 1 ) ) ; <START_BUG> Series pnl = account . getInstrumentPnl ( instrument ) ; <END_BUG> if ( ( pnl . size ( ) ) == 0 ) return ; connectIfNecessary ( ) ; getDbId ( ) ; long start = System . nanoTime ( ) ; String query = "<seq2seq4repair_space>INSERT<seq2seq4repair_space>INTO<seq2seq4repair_space>pnls(strategy_id,symbol,ts,pnl)<seq2seq4repair_space>VALUE<seq2seq4repair_space>(?,?,?,?)<seq2seq4repair_space>" + "<seq2seq4repair_space>ON<seq2seq4repair_space>DUPLICATE<seq2seq4repair_space>KEY<seq2seq4repair_space>UPDATE<seq2seq4repair_space>pnl=?" ; PreparedStatement stmt = connection . prepareStatement ( query ) ; stmt . setLong ( 1 , dbId ) ; stmt . setString ( 2 , instrument . getSymbol ( ) ) ; for ( int ii = 0 ; ii < ( pnl . size ( ) ) ; ++ ii ) { stmt . setTimestamp ( 3 , Timestamp . valueOf ( pnl . getTimestamp ( ii ) ) ) ; stmt . setDouble ( 4 , pnl . get ( ii ) ) ; stmt . setDouble ( 5 , pnl . get ( ii ) ) ; stmt . addBatch ( ) ; } stmt . executeBatch ( ) ; connection . commit ( ) ; stmt . close ( ) ; long elapsedTime = ( System . nanoTime ( ) ) - start ; TradingResults tr = account . getPortfolioTradingResults ( instrument ) ; if ( ( tr . stats . size ( ) ) > 0 ) { query = "<seq2seq4repair_space>INSERT<seq2seq4repair_space>INTO<seq2seq4repair_space>trades(strategy_id,symbol,start,end,initial_position,<seq2seq4repair_space>" + ( "<seq2seq4repair_space>max_position,num_transactions,pnl,pct_pnl,tick_pnl,fees)<seq2seq4repair_space>" + "<seq2seq4repair_space>VALUES(?,?,?,?,?,?,?,?,?,?,?)" ) ; stmt = connection . prepareStatement ( query ) ; stmt . setLong ( 1 , dbId ) ; stmt . setString ( 2 , instrument . getSymbol ( ) ) ; start = System . nanoTime ( ) ; int ii = 0 ; for ( Trade tradeStats : tr . stats ) { stmt . setTimestamp ( 3 , Timestamp . valueOf ( tradeStats . start ) ) ; stmt . setTimestamp ( 4 , Timestamp . valueOf ( tradeStats . end ) ) ; stmt . setLong ( 5 , tradeStats . initialPosition ) ; stmt . setLong ( 6 , tradeStats . maxPosition ) ; stmt . setLong ( 7 , tradeStats . numTransactions ) ; stmt . setDouble ( 8 , tradeStats . pnl ) ; stmt . setDouble ( 9 , tradeStats . pctPnl ) ; stmt . setDouble ( 10 , tradeStats . tickPnl ) ; stmt . setDouble ( 11 , tradeStats . fees ) ; stmt . executeUpdate ( ) ; ++ ii ; } connection . commit ( ) ; stmt . close ( ) ; elapsedTime = ( System . nanoTime ( ) ) - start ; } writeTradeSummary ( instrument , "All" , tr . all ) ; writeTradeSummary ( instrument , "Long" , tr . longs ) ; writeTradeSummary ( instrument , "Short" , tr . shorts ) ; connection . commit ( ) ; } protected void writeTradeSummary ( String symbol , String type , TradeSummary tradeSummary ) throws SQLException { } public void writeEquity ( ) throws SQLException { } private void setDoubleParam ( PreparedStatement stmt , int index , double value ) throws SQLException { } protected void writeTradeSummary ( Instrument instrument , String type , TradeSummary tradeSummary ) throws SQLException { } protected void onBarOpen ( BarHistory history , Bar bar ) throws Exception { } protected void onBarClose ( BarHistory history , Bar bar ) throws Exception { } protected void onBarClosed ( BarHistory history , Bar bar ) throws Exception { } protected void onOrderNotification ( OrderNotification on ) throws Exception { } public void barOpenHandler ( Bar bar ) throws Exception { } public void barCloseHandler ( Bar bar ) throws Exception { } public void barClosedHandler ( Bar bar ) throws Exception { } public void orderExecutedHandler ( OrderNotification on ) throws Exception { } public Series getAnnualStats ( ) throws Exception { } public Series getAnnualStatsOld ( ) throws SQLException { } public Series getPnl ( ) throws Exception { } public Series getPnl ( String symbol ) throws Exception { } public Series getEquity ( ) { } public TimeSeries < BigDecimal > getAnnualPnl ( String symbols ) throws SQLException { } class TradeTotalsBuilder { private long numTrades ; private double grossProfits ; private double grossLosses ; private double mean ; private double variance ; private AverageAndVariance dailyPnlStats ; private AverageAndVariance pnlStats ; private long nonZero ; private long positive ; private long negative ; private double maxWin ; private double maxLoss ; private Average averageWinTrade ; private Average averageLossTrade ; private TimeSeries < Double > pnl ; private int pnlId ; private double previousEquity ; private double minEquity ; private double maxEquity ; private double maxDrawdown ; TradeTotalsBuilder ( ) { } void add ( long position , double pnl ) { }

Fix:
Series pnl = account . getPnlSeries ( instrument ) ;