/** Write [DATE] Buy [SYMBOL] [NUMBER]sh @[PRICE] = [VALUE] --> [NUMBER]sh held * */ public void orderBought( TradeOrder order, Date date, StockPosition position, TradingAccount account) { double profitOrLoss = (order.shares * (order.getExecutedPrice() - position.getCostBasis()) - account.getTradeFees(order.shares)); double percent = profitOrLoss / (position.getCostBasis() * order.shares); this.writer.println( DATE_FORMAT.format(date) + " " + (position.getShares() != 0 ? "Buy " : "Cover ") + order.symbol + " " + order.shares + "sh " + "@" + DOLLAR_FORMAT.format(order.getExecutedPrice()) + " = " + DOLLAR_FORMAT.format(order.getExecutedValue()) + " --> " + position.getShares() + "sh " + (position.getShares() <= 0 ? "left, " + DOLLAR_FORMAT.format(profitOrLoss) + (profitOrLoss > 0 ? " (" + PERCENT_FORMAT.format(percent) + " profit)" : profitOrLoss < 0 ? " (" + PERCENT_FORMAT.format(percent) + "loss)" : " (even)") : "long")); this.lastTraceDate = date; }