Code Monkey home page Code Monkey logo

java-finance-api's Introduction

Java Finance API

javadoc Maven Central

Accessing financial data can be tricky, especially of you are not willing to pay for it. The data sources exist, but they come in different formats, are poorly (or not at all) documented, and may change or disappear without warning.

Java Finance API takes a diversification approach to accessing financial data. We provide ways to access a bunch of freely available financial sources by writing very little code. You can pick the one that better suits your needs, and easily switch to another provider if you choose to.

Features

  • Stock prices from Yahoo Finance
  • Dividend and split history info from Yahoo Finance
  • Information about traded assets from Barchart
  • Currency exchange rates from Grandtrunk
  • Trading calendars from Enrico and Tradier

Yahoo Historical Prices, Dividends, and Splits

Get Historical Prices from Yahoo

    StockPriceService stockPriceService = new YahooStockPriceService();
    LocalDate fromDate = LocalDate.of(2014, 1, 2);
    LocalDate toDate = LocalDate.of(2014, 11, 1);
    List<Quote> prices = stockPriceService.getPriceHistory("AAPL", fromDate, toDate, StandardPeriodType.DAY);

Get Historical Splits from Yahoo

    SplitService splitService = new YahooSplitService();
    List<Split> splits = splitService.getSplitHistory("AAPL", LocalDate.of(2005, 1, 1), LocalDate.of(2015, 12, 31));
        

Get Historical Dividends from Yahoo

    DividendService dividendService = new YahooDividendService();
    Map<LocalDate, BigDecimal> dividends = dividendService.getHistoricalDividends("AGG", LocalDate.of(2000, 1, 1), LocalDate.of(2016, 11, 9));
    

Currency Exchange Rates

    CurrencyExchangeService exchangeService = new GrandtrunkCurrencyExchangeService();
    LocalDate date = LocalDate.of(2014, 1, 12);
    // Get Historical rate
    double rate = exchangeService.getExchangeRate("USD", "GBP", date);

    //Get current rate
    double currentRate = exchangeService.getCurrentExchangeRate("USD", "GBP");

    //Get supported currencis
    List<String> currencies = exchangeService.getSupportedCurrencies();

Holidays and Trading Days

Retrieve Market Trading Days

    TradingDayService tradingDayService = new TradierTradingDayService();
    //Get trading days in a year
    List<TradingDay> days = tradingDayService.getTradingDays(2019);
    //Extract the holidays
    Set<TradingDay> holidays = tradingDayService.getHolidays(days);
    //Extract the days when the market closes early
    Set<TradingDay> earlyCloseDays = tradingDayService.getEarlyCloseDays(days);

Alternatively, you can retrieve holidays for a date range and country

    HolidayService holidayService = new EnricoHolidayService();
    List<HolidaySupport> countries = holidayService.getSupportedCountries();
    List<Holiday> holidays = holidayService.getHolidaysForYear(2015, "usa");
    //Find where a particular date is a holiday
    Map<Country, List<Holiday>> countries =
        holidayService.whereIsPublicHoliday(LocalDate.of(2025, 7, 5));

java-finance-api's People

Contributors

algorythmist avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.