com.tecacet.finance.service.stock.yahoo.YahooDividendParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfapi Show documentation
Show all versions of jfapi Show documentation
JFApi connects to various Web Services that provide financial data such as stock prices,
splits, dividends, and FX rates.
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