private void init() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setTitle("Strategy Information - " + strategy.getName());

    this.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            Dispatcher dispatcher = Dispatcher.getInstance();
            dispatcher.removeListener(StrategyInformationDialog.this);
          }
        });

    JPanel contentPanel = new JPanel(new BorderLayout());
    getContentPane().add(contentPanel, BorderLayout.CENTER);

    JTabbedPane tabbedPane = new JTabbedPane();
    contentPanel.add(tabbedPane, BorderLayout.CENTER);

    JPanel performancePanel = new JPanel(new SpringLayout());
    tabbedPane.addTab("Performance", performancePanel);

    NumberFormat nf2 = NumberFormatterFactory.getNumberFormatter(2);

    PerformanceManager pm = strategy.getPerformanceManager();
    add(performancePanel, "Position", strategy.getPositionManager().getCurrentPosition());
    add(performancePanel, "Trades", pm.getTrades());
    add(performancePanel, "% Profitable", nf2.format(pm.getPercentProfitableTrades()));
    add(performancePanel, "Average trade", nf2.format(pm.getAverageProfitPerTrade()));
    add(performancePanel, "Net Profit", nf2.format(pm.getNetProfit()));
    add(performancePanel, "Max Drawdown", nf2.format(pm.getMaxDrawdown()));
    add(performancePanel, "Profit Factor", nf2.format(pm.getProfitFactor()));
    add(performancePanel, "Kelly", nf2.format(pm.getKellyCriterion()));
    add(performancePanel, "PI", nf2.format(pm.getPerformanceIndex()));
    add(performancePanel, "CPI", nf2.format(pm.getCPI()));
    makeCompactGrid(performancePanel);

    JPanel securityPanel = new JPanel(new SpringLayout());
    tabbedPane.addTab("Instrument", securityPanel);
    add(securityPanel, "Symbol", strategy.getContract().m_symbol);
    add(securityPanel, "Security Type", strategy.getContract().m_secType);
    add(securityPanel, "Exchange", strategy.getContract().m_exchange);
    add(securityPanel, "Multiplier", strategy.getContract().m_multiplier);
    add(securityPanel, "Commission", strategy.getPerformanceManager().getCommission().toString());

    bidAskLabel = new JLabel();
    securityPanel.add(new JLabel("Best bid-ask" + ":"));
    securityPanel.add(bidAskLabel);

    cumBidAskSizesLabel = new JLabel();
    securityPanel.add(new JLabel("Book bid-ask size" + ":"));
    securityPanel.add(cumBidAskSizesLabel);

    makeCompactGrid(securityPanel);

    JPanel parametersPanel = new JPanel(new SpringLayout());
    tabbedPane.addTab("Parameters", parametersPanel);
    StrategyParams params = strategy.getParams();
    add(parametersPanel, "Schedule", strategy.getTradingSchedule().toString());
    for (StrategyParam param : params.getAll()) {
      add(parametersPanel, param.getName(), param.getValue());
    }
    makeCompactGrid(parametersPanel);

    IndicatorManager indicatorManager = strategy.getIndicatorManager();
    if (indicatorManager != null) {
      JPanel indicatorsPanel = new JPanel(new SpringLayout());
      tabbedPane.addTab("Indicators", indicatorsPanel);
      for (Indicator indicator : strategy.getIndicatorManager().getIndicators()) {
        add(indicatorsPanel, indicator.getKey(), indicator.getValue());
      }
      makeCompactGrid(indicatorsPanel);
    }

    getContentPane().setPreferredSize(new Dimension(450, 400));
  }
Пример #2
0
  public BackTestFileWriter(Strategy strategy) throws JArbitragerException {
    decimalFormat = NumberFormatterFactory.getNumberFormatter(5);
    dateFormat = new SimpleDateFormat("MMddyy,HHmmss");
    dateFormat.setTimeZone(strategy.getTradingSchedule().getTimeZone());

    File marketDataDir = new File(MARKET_DATA_DIR);
    if (!marketDataDir.exists()) {
      marketDataDir.mkdir();
    }

    String fullFileName = MARKET_DATA_DIR + FILE_SEP + strategy.getName() + ".txt";
    try {
      boolean fileExisted = new File(fullFileName).exists();
      writer = new PrintWriter(new BufferedWriter(new FileWriter(fullFileName, true)));
      if (!fileExisted) {
        StringBuilder header =
            getHeader(
                strategy.getInstrument1().getContract().m_symbol,
                strategy.getInstrument2().getContract().m_symbol);
        writer.println(header);
      }
    } catch (IOException ioe) {
      throw new JArbitragerException("Could not write to file " + strategy.getName());
    }
  }
 public void modelChanged(Event event, Object value) {
   switch (event) {
     case StrategyUpdate:
       MarketDepth marketDepth = strategy.getMarketBook().getMarketDepth();
       cumBidAskSizesLabel.setText(marketDepth.getSizes());
       bidAskLabel.setText(marketDepth.getTop());
       break;
   }
 }