예제 #1
0
    @Override
    public void run() {

      ConfigThreadLocal.set(Config.EVENT_SIGNAL_NAME, configs.get(Config.EVENT_SIGNAL_NAME));
      ConfigThreadLocal.set(
          Config.INDICATOR_PARAMS_NAME, configs.get(Config.INDICATOR_PARAMS_NAME));

      SymbolEvents eventsForStock =
          EventsResources.getInstance()
              .crudReadEventsForStock(
                  selectedShare,
                  exentedStartDate,
                  chartTarget.getSlidingEndDate(),
                  true,
                  chartTarget.getChartedEvtDefsTrends(),
                  IndicatorCalculationServiceMain.UI_ANALYSIS);
      setChanged();
      notifyObservers(eventsForStock);
    }
예제 #2
0
  public TuningResDTO buildTuningRes(
      Date startDate,
      Date endDate,
      Stock stock,
      String analyseName,
      SortedMap<Date, double[]> calcOutput,
      EventInfo evtDef,
      Observer observer,
      Boolean isEventsPersisted)
      throws NotEnoughDataException {

    if (calcOutput == null) calcOutput = new TreeMap<Date, double[]>();
    if (!calcOutput.isEmpty() && calcOutput.firstKey().before(startDate))
      calcOutput = calcOutput.tailMap(startDate);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy MM dd");
    String noResMsg =
        "No estimate is available for "
            + stock.getName()
            + " between "
            + dateFormat.format(startDate)
            + " and "
            + dateFormat.format(endDate)
            + " with "
            + evtDef
            + ".\n";
    try {

      Date endCalcRes =
          (calcOutput.size() > 0 && calcOutput.lastKey().after(endDate))
              ? calcOutput.lastKey()
              : endDate;

      // Grab calculated events
      HashSet<EventInfo> eventDefinitions = new HashSet<EventInfo>();
      eventDefinitions.add(evtDef);
      SymbolEvents eventsCalculated =
          EventsResources.getInstance()
              .crudReadEventsForStock(
                  stock, startDate, endCalcRes, isEventsPersisted, eventDefinitions, analyseName);

      // Init event def list
      NavigableSet<EventValue> eventListForEvtDef =
          new TreeSet<EventValue>(
              new Comparator<EventValue>() {
                @Override
                public int compare(EventValue o1, EventValue o2) {
                  return o1.getDate().compareTo(o2.getDate());
                }
              });
      eventListForEvtDef.addAll(eventsCalculated.getDataResultMap().values());

      return buildTuningRes(
          stock,
          startDate,
          endDate,
          endCalcRes,
          analyseName,
          calcOutput,
          eventListForEvtDef,
          noResMsg,
          evtDef.info(),
          observer);

    } catch (NoQuotationsException e) {
      LOGGER.warn(noResMsg, e);
      throw new NotEnoughDataException(stock, noResMsg, e);
    } catch (NotEnoughDataException e) {
      LOGGER.warn(noResMsg, e);
      throw e;
    } catch (Exception e) {
      LOGGER.error(noResMsg, e);
      throw new NotEnoughDataException(stock, noResMsg, e);
    }
  }