All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tecacet.finance.service.stock.yahoo.YahooDividendParser Maven / Gradle / Ivy

Go to download

JFApi connects to various Web Services that provide financial data such as stock prices, splits, dividends, and FX rates.

There is a newer version: 1.1.3
Show newest version
package com.tecacet.finance.service.stock.yahoo;

import com.tecacet.jflat.CSVReader;
import com.tecacet.jflat.RowRecord;

import org.apache.commons.csv.CSVFormat;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Map;
import java.util.TreeMap;

public class YahooDividendParser {

    public Map parse(InputStream is) throws IOException {
        Map dividends = new TreeMap<>();
        CSVReader csvReader = CSVReader
                .defaultReader()
                .withFormat(CSVFormat.DEFAULT.withFirstRecordAsHeader().withSkipHeaderRecord());
        csvReader.read(is, (row, bean) -> parse(dividends, row));
        return dividends;
    }

    private void parse(Map dividends, RowRecord row) {
        LocalDate date = LocalDate.parse(row.get(0).trim());
        double value = Double.parseDouble(row.get(1).trim());
        dividends.put(date, BigDecimal.valueOf(value));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy