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 List<OptimizationResult> call() throws JBookTraderException {
    List<Strategy> strategies = new ArrayList<>();
    List<OptimizationResult> optimizationResults = new LinkedList<>();

    MarketBook marketBook = new MarketBook();
    IndicatorManager indicatorManager = new IndicatorManager();

    for (StrategyParams params : tasks) {
      Strategy strategy = optimizerRunner.getStrategyInstance(params);
      strategy.setMarketBook(marketBook);
      strategy.setIndicatorManager(indicatorManager);
      strategy.setIndicators();
      strategies.add(strategy);
    }

    TradingSchedule tradingSchedule = strategies.get(0).getTradingSchedule();
    int strategiesCount = strategies.size();

    List<MarketSnapshot> snapshots = optimizerRunner.getSnapshots();
    long snapshotsCount = snapshots.size();
    for (int count = 0; count < snapshotsCount; count++) {
      MarketSnapshot marketSnapshot = snapshots.get(count);
      marketBook.setSnapshot(marketSnapshot);
      indicatorManager.updateIndicators();
      boolean isInSchedule = tradingSchedule.contains(marketSnapshot.getTime());
      if (count < snapshotsCount - 1) {
        // ekk-needs optimization
        isInSchedule = isInSchedule && !marketBook.isGapping(snapshots.get(count + 1));
      }

      for (Strategy strategy : strategies) {
        strategy.processInstant(isInSchedule);
      }

      if (count % 5000 == 0) {
        if (optimizerRunner.isCancelled()) {
          break;
        }
        optimizerRunner.iterationsCompleted(strategiesCount * 5000);
      }
    }

    if (!optimizerRunner.isCancelled()) {
      int minTrades = optimizerRunner.getMinTrades();

      for (Strategy strategy : strategies) {
        strategy.closePosition();

        PerformanceManager performanceManager = strategy.getPerformanceManager();
        if (performanceManager.getTrades() >= minTrades) {
          if (inclusionCriteria.equals("All strategies") || performanceManager.getNetProfit() > 0) {
            OptimizationResult optimizationResult =
                new OptimizationResult(strategy.getParams(), performanceManager);
            optimizationResults.add(optimizationResult);
          }
        }
      }
    }

    return optimizationResults;
  }