gpt4 book ai didi

jgnash.net.security.YahooEventParser类的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 15:51:31 26 4
gpt4 key购买 nike

本文整理了Java中jgnash.net.security.YahooEventParser类的一些代码示例,展示了YahooEventParser类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YahooEventParser类的具体详情如下:
包路径:jgnash.net.security.YahooEventParser
类名称:YahooEventParser

YahooEventParser介绍

[英]Retrieves historical stock dividend and split information from Yahoo.
[中]从雅虎检索历史股票股息和拆分信息。

代码示例

代码示例来源:origin: ccavanaugh/jgnash

public static List<SecurityHistoryNode> downloadHistory(final SecurityNode securityNode, final LocalDate startDate,
                            final LocalDate endDate) {
  final List<SecurityHistoryNode> newSecurityNodes = YahooEventParser.retrieveHistoricalPrice(securityNode,
      startDate, endDate);
  if (!newSecurityNodes.isEmpty()) {
    logger.info(ResourceUtils.getString("Message.UpdatedPrice", securityNode.getSymbol()));
  }
  return newSecurityNodes;
}

代码示例来源:origin: ccavanaugh/jgnash

static Set<SecurityHistoryEvent> retrieveNew(final SecurityNode securityNode) {
  return retrieveNew(securityNode, LocalDate.now());
}

代码示例来源:origin: ccavanaugh/jgnash

private static List<SecurityHistoryEvent> retrieveNewSplits(@NotNull final SecurityNode securityNode,
                              final LocalDate startDate, final LocalDate endDate) {
   /*
  Date,Stock Splits
  1973-05-29,5/4
  1964-05-18,5/4
  1997-05-28,2/1
  */
  return parseStream(securityNode, startDate, endDate,
      SecurityHistoryEventType.SPLIT, SPLIT_RESPONSE_HEADER::equals,
      line -> {
        final String[] fields = COMMA_DELIMITER_PATTERN.split(line);
        if (fields.length == 2) {   // if fields are != 2, then it's not valid data
          try {
            final String[] fraction = fields[1].split("/");
            final BigDecimal value = new BigDecimal(fraction[0])
                .divide(new BigDecimal(fraction[1]), MathContext.DECIMAL32);
            return new SecurityHistoryEvent(SecurityHistoryEventType.SPLIT, parseYahooDate(fields[0]),
                value);
          } catch (final DateTimeException | NumberFormatException ex) {
            Logger.getLogger(YahooEventParser.class.getName()).log(Level.INFO, line);
            LogUtil.logSevere(YahooEventParser.class, ex);
          }
        }
        return null;
      });
}

代码示例来源:origin: ccavanaugh/jgnash

public static Set<SecurityHistoryEvent> retrieveNew(@NotNull final SecurityNode securityNode,
                          final LocalDate endDate) {
  final Set<SecurityHistoryEvent> events = new HashSet<>();
  // Ensure we have a valid cookie and crumb
  if (!YahooCrumbManager.authorize(securityNode.getSymbol())) {
    return events;
  }
  LocalDate startDate = LocalDate.now().minusDays(1);
  final List<SecurityHistoryNode> historyNodeList = securityNode.getHistoryNodes();
  if (!historyNodeList.isEmpty()) {
    startDate = historyNodeList.get(0).getLocalDate();
  }
  events.addAll(retrieveNewDividends(securityNode, startDate, endDate));
  events.addAll(retrieveNewSplits(securityNode, startDate, endDate));
  return events;
}

代码示例来源:origin: ccavanaugh/jgnash

final String url = buildYahooQuery(securityNode, startDate, endDate, type);

代码示例来源:origin: ccavanaugh/jgnash

@Override
  public Boolean call() {
    boolean result = false;
    final Engine e = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(e);
    // check for thread interruption
    if (securityNode.getQuoteSource() != QuoteSource.NONE && !Thread.currentThread().isInterrupted()) {
      final List<SecurityHistoryNode> nodes = YahooEventParser.retrieveHistoricalPrice(securityNode,
          LocalDate.now().minusDays(1), LocalDate.now());
      for (final SecurityHistoryNode node : nodes) {
        if (!Thread.currentThread().isInterrupted()) { // check for thread interruption
          result = e.addSecurityHistory(securityNode, node);
          if (result) {
            logger.info(ResourceUtils.getString("Message.UpdatedPrice", securityNode.getSymbol()));
          }
        }
      }
    }
    return result;
  }
}

代码示例来源:origin: ccavanaugh/jgnash

@Override
  public Boolean call() {
    boolean result = true;
    final Engine e = EngineFactory.getEngine(EngineFactory.DEFAULT);
    final LocalDate oldest = securityNode.getHistoryNodes().get(0).getLocalDate();
    if (e != null && securityNode.getQuoteSource() != QuoteSource.NONE) {
      final Set<SecurityHistoryEvent> oldHistoryEvents = new HashSet<>(securityNode.getHistoryEvents());
      for (final SecurityHistoryEvent securityHistoryEvent : YahooEventParser.retrieveNew(securityNode)) {
        if (!Thread.currentThread().isInterrupted()) { // check for thread interruption
          if (securityHistoryEvent.getDate().isAfter(oldest) || securityHistoryEvent.getDate().isEqual(oldest)) {
            if (!oldHistoryEvents.contains(securityHistoryEvent)) {
              result = e.addSecurityHistoryEvent(securityNode, securityHistoryEvent);
              if (result) {
                logger.info(ResourceUtils.getString("Message.UpdatedSecurityEvent", securityNode.getSymbol()));
              }
            }
          }
        }
      }
    }
    return result;
  }
}

代码示例来源:origin: ccavanaugh/jgnash

private static List<SecurityHistoryEvent> retrieveNewDividends(@NotNull final SecurityNode securityNode,
                                final LocalDate startDate, final LocalDate endDate) {
  /*
  Date,Dividends
  1989-02-02,0.275
  1989-08-03,0.3025
  1964-02-04,0.00167
  1964-08-04,0.00208
  */
  return parseStream(securityNode, startDate, endDate,
      SecurityHistoryEventType.DIVIDEND, DIV_RESPONSE_HEADER::equals,
      line -> {
        final String[] fields = COMMA_DELIMITER_PATTERN.split(line);
        if (fields.length == 2) {   // if fields are != 2, then it's not valid data
          try {
            return new SecurityHistoryEvent(SecurityHistoryEventType.DIVIDEND,
                parseYahooDate(fields[0]), new BigDecimal(fields[1]));
          } catch (final DateTimeException | NumberFormatException ex) {
            Logger.getLogger(YahooEventParser.class.getName()).log(Level.INFO, line);
            LogUtil.logSevere(YahooEventParser.class, ex);
          }
        }
        return null;
      });
}

代码示例来源:origin: ccavanaugh/jgnash

@Test
  void testHistoricalDownload() {

    // try 3 times to pass
    for (int i = 0; i < 3; i++) {

      final SecurityNode ibm = new SecurityNode(e.getDefaultCurrency());
      ibm.setSymbol("IBM");
      ibm.setScale((byte) 2);

      e.addSecurity(ibm);

      YahooCrumbManager.clearAuthorization();     // force re-authorization to prevent failed unit test

      final List<SecurityHistoryNode> events = YahooEventParser.retrieveHistoricalPrice(ibm, LocalDate.of(2016,
          Month.JANUARY, 1), LocalDate.of(2016, Month.DECEMBER, 30));

      if (events.size() == 252) {
        assertEquals(252, events.size());
        return;
      }
    }

    fail("Failed to pass test");
  }
}

代码示例来源:origin: ccavanaugh/jgnash

@SuppressWarnings("ConstantConditions")
@Test
void testParser() {
  // try 3 times to pass
  for (int i = 0; i < 3; i++) {
    final SecurityNode ibm = new SecurityNode(e.getDefaultCurrency());
    ibm.setSymbol("IBM");
    ibm.setScale((byte) 2);
    final SecurityHistoryNode historyNode = new SecurityHistoryNode(LocalDate.of(1962, Month.JANUARY, 1),
        BigDecimal.TEN, 1000, BigDecimal.TEN, BigDecimal.TEN);
    e.addSecurity(ibm);
    e.addSecurityHistory(ibm, historyNode);
    final Set<SecurityHistoryEvent> events = YahooEventParser.retrieveNew(ibm, LocalDate.of(2015, Month.AUGUST, 22));
    assertNotNull(events);
    // size fluctuates
    if (events.size() <= 221 && events.size() >= 220) {
      assertTrue(events.size() <= 221 && events.size() >= 220);
      return;
    }
  }
  fail("Failed to pass test");
}

代码示例来源:origin: ccavanaugh/jgnash

final List<SecurityHistoryNode> events = parseStream(securityNode, startDate, endDate,
    SecurityHistoryEventType.PRICE, HISTORY_RESPONSE_HEADER::equals,
    line -> {
        try {
          final LocalDate date = parseYahooDate(fields[0]);
          final BigDecimal high = new BigDecimal(fields[2]);
          final BigDecimal low = new BigDecimal(fields[3]);

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com