示例#1
0
  /** 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;
  }
示例#2
0
 /** Write [DATE] Buy/Sell [SYMBOL] [NUMBER]sh @[PRICE] CANCELLED (no price on date) * */
 public void orderCancelled(
     TradeOrder order, Date date, StockPosition position, TradingAccount account) {
   String priceString;
   switch (order.getPriceTiming()) {
     case OPEN:
     case CLOSE:
     default:
       priceString = DOLLAR_FORMAT.format(order.projectedPrice);
       break;
     case LIMIT_OR_BELOW:
       priceString = "<=" + DOLLAR_FORMAT.format(order.limit);
       break;
     case LIMIT_OR_ABOVE:
       priceString = ">=" + DOLLAR_FORMAT.format(order.limit);
       break;
   }
   // ATR removed "cancelled order" log. Doesn't make sense when
   // using lots of stop and limit orders that don't fill.
 }