예제 #1
0
  @Test
  public void testRequestForResult() throws Exception {

    Navigation navigation =
        Navigation.parse(
            GenerateTestData.GetNavigation.getNavigationJson(LocalDate.parse("2014-08-08")));

    Navigation.Markets markets =
        navigation.findMarkets(
            EventTypeName.SOCCER, between(now().minusDays(1), now()), "Match Odds");

    Iterable<MarketId> marketIds = limit(markets.marketsIds(), 5);

    httpAccess.listMarketBook(
        fileWriter(LIST_MARKET_BOOK_FILE),
        new ListMarketBook(marketIds, null, null, null, null, Locale.EN_US));

    MarketBook[] marketBooks =
        JsonSerialization.parse(
            readFileToString(LIST_MARKET_BOOK_FILE.toFile()), MarketBook[].class);
    for (MarketBook marketBook : marketBooks) {
      System.out.println(marketBook.prettyPrint());
    }
  }
예제 #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;
  }