Example #1
6
  public static void main(String[] args) {
    Mediator mediator = new MediatorImpl();
    Indicator indicator1 = new Indicator(mediator, 1, 1);
    Indicator indicator2 = new Indicator(mediator, 2, 2);
    Indicator indicator3 = new Indicator(mediator, 1, 3);
    Indicator indicator4 = new Indicator(mediator, 1, 4);
    mediator.addIndicator(indicator1);
    mediator.addIndicator(indicator2);
    mediator.addIndicator(indicator3);
    mediator.addIndicator(indicator4);

    indicator1.setSOs(2);

    for (Indicator ind : mediator.getIndicators()) {
      System.out.println(ind.getSoId());
    }
  }
  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));
  }
Example #3
0
 public void setMaximized(boolean b) {
   if (indicator.isMaximized() != b) {
     indicator.setMaximized(b);
     //            if (toolbox != null)
     //                toolbox.update();
     annotationPanel.setVisible(b);
     chartFrame.validate();
     chartFrame.repaint();
   }
 }
  @Test
  public void testUpdateIndicator() throws Exception {
    IndicatorType type = new IndicatorType("IndicatorType", 100, false);

    indicatorTypeStore.save(type);

    Indicator indicatorA = createIndicator('A', type);
    int idA = indicatorStore.save(indicatorA);
    indicatorA = indicatorStore.get(idA);
    assertEq('A', indicatorA);

    indicatorA.setName("IndicatorB");
    indicatorStore.update(indicatorA);
    indicatorA = indicatorStore.get(idA);
    assertNotNull(indicatorA);
    assertEquals(indicatorA.getName(), "IndicatorB");
  }
Example #5
0
 public int getPanelHeight() {
   if (isMaximized()) {
     return indicator.getMaximizedHeight();
   } else {
     // return toolbox.getHeight();
     return 100;
   }
 }
 @Override
 public Node toNode() {
   Node node = new Node("indicator:");
   if (indicator != null) {
     node.add(indicator.toString());
   }
   addAlignment(node);
   return node;
 }
  public static IndicatorAttribute fromNode(Node node) {

    if (!node.hasTag("indicator:")) {
      throw new CoreException("Expected 'indicator:' not '" + node.tag + "'.");
    }

    Indicator indicator = Indicator.valueOf(node.getSingleLeaf());
    int[] tokens = getTokens(node);
    return tokens != null
        ? new IndicatorAttribute(indicator, tokens[0], tokens[1])
        : new IndicatorAttribute(indicator);
  }
Example #8
0
 private void renderIndicators() {
   for (Indicator i : indicators) {
     if (i.getShape() instanceof Polygon) {
       getContext().setColor(i.getColor().darker());
       getContext().drawPolygon((Polygon) i.getShape());
       getContext().setColor(i.getColor());
       getContext().fillPolygon((Polygon) i.getShape());
     }
   }
 }
 public void setSO(Integer soId) {
   for (Indicator indicator : indicators) {
     indicator.setSoId(soId);
   }
 }
 private void assertEq(char uniqueCharacter, Indicator indicator) {
   assertEquals("Indicator" + uniqueCharacter, indicator.getName());
   assertEquals("IndicatorShort" + uniqueCharacter, indicator.getShortName());
   assertEquals("IndicatorCode" + uniqueCharacter, indicator.getCode());
   assertEquals("IndicatorDescription" + uniqueCharacter, indicator.getDescription());
 }
Example #11
0
  public List<Feed> getFeeds(String url, int maxSize) {
    List<Feed> result = new ArrayList<>();

    try {
      org.jsoup.nodes.Document doc = Jsoup.connect(url).timeout(15000).get();

      Indicator titleIndicator = indicators.get(TAG_TITLE);
      Indicator linkIndicator = indicators.get(TAG_LINK);
      Indicator descriptionIndicator = indicators.get(TAG_DESCRIPTION);
      Indicator pubDateIndicator = indicators.get(TAG_PUB_DATE);
      Indicator authorIndicator = indicators.get(TAG_AUTOR);

      Elements links = null;

      if (linkIndicator != null && !linkIndicator.equals("")) {
        links = doc.select(linkIndicator.indicator);
      }

      int size =
          links == null
              ? 0
              : (links.size()
                      - linkIndicator.frontSkipCount
                      - linkIndicator.rearSkipCount
                      + linkIndicator.middleSkipCount)
                  / (linkIndicator.middleSkipCount + 1);
      if (maxSize != 0) {
        size = size > maxSize ? maxSize : size;
      }
      for (int i = 0; i < size; i++) {
        Feed feed = new Feed();

        try {
          Element e =
              links.get(i * (linkIndicator.middleSkipCount + 1) + linkIndicator.frontSkipCount);
          feed.link = e.attr("href");
          if (feed.link == null || feed.link.equals("")) {
            feed.link = e.text();
          }
          if (feed.link == null) {
            feed.link = url;
          }
          if (feed.link != null && feed.link.startsWith("/")) {
            URL u = new URL(url);
            feed.link = u.getProtocol() + "://" + u.getHost() + feed.link;
          }
          feed.link = convertLink(feed.link);
        } catch (Exception ignore) {
        }

        org.jsoup.nodes.Document doc2 = Jsoup.connect(feed.link).timeout(15000).get();

        try {
          feed.title =
              doc2.select(titleIndicator.indicator).get(titleIndicator.frontSkipCount).text();
        } catch (Exception ignore) {
        }
        if (descriptionIndicator != null) {
          try {
            feed.description =
                doc2.select(descriptionIndicator.indicator)
                    .get(descriptionIndicator.frontSkipCount)
                    .text();
          } catch (Exception ignore) {
          }
        }
        if (pubDateIndicator != null) {
          try {
            feed.pubDate =
                doc2.select(pubDateIndicator.indicator).get(pubDateIndicator.frontSkipCount).text();
          } catch (Exception ignore) {
          }
        }
        if (authorIndicator != null) {
          try {
            feed.author =
                doc2.select(authorIndicator.indicator).get(authorIndicator.frontSkipCount).text();
          } catch (Exception ignore) {
          }
        }

        result.add(feed);
      }
    } catch (IOException e) {
    }

    return result;
  }
Example #12
0
 public boolean isMaximized() {
   if (indicator != null) return indicator.isMaximized();
   return true;
 }