joshuaulrich / quantmod

Quantitative Financial Modelling Framework
http://www.quantmod.com/
GNU General Public License v3.0
810 stars 223 forks source link

Getting financial statements #254

Open joeymizrahi opened 5 years ago

joeymizrahi commented 5 years ago

Hi, I am in need of quarterly and yearly financial statements such as: Income statement, Cash Flow, Balance Sheet. this is the only library I found that offers it. but when I try to use it it returns that it is defunct. does anyone have a solution for this? ad if there isn't one, does anyone know of a different library that can help. it can be in python,C,C++,C#,Java

abeeCrombie commented 5 years ago

Try this library if u need a few company financials. I wouldn't scrape every single company every day. But it should work for many other use cases.

https://gist.github.com/hahnicity/45323026693cdde6a116

On Sun, Nov 4, 2018, 2:44 AM cs4242 <notifications@github.com wrote:

Hi, I am in need of quarterly and yearly financial statements such as: Income statement, Cash Flow, Balance Sheet. this is the only library I found that offers it. but when I try to use it it returns that it is defunct. does anyone have a solution for this? ad if there isn't one, does anyone know of a different library that can help. it can be in python,C,C++,C#,Java

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/joshuaulrich/quantmod/issues/254, or mute the thread https://github.com/notifications/unsubscribe-auth/ATeUHtMvaMhrWumf0Kuk8RnG5XOyGdqVks5urprTgaJpZM4YNL5Y .

joeymizrahi commented 5 years ago

Try this library if u need a few company financials. I wouldn't scrape every single company every day. But it should work for many other use cases. https://gist.github.com/hahnicity/45323026693cdde6a116

this doesn't seem to be a module. how would I use it to extract lets say the Income statement, Cash Flow, Balance Sheet of a specific company?

joshuaulrich commented 5 years ago

I'm not sure how to create all the URLs to send to the Yahoo servers... but I looked at the page source for Apple's financials, and it looks like the relevant URL for the quarterly balance sheet history is: https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL?modules=balanceSheetHistoryQuarterly

We should be able to find the URLs for the other statements by careful inspection of the page source. quantmod::getOptionChain.yahoo() demonstrates how to get JSON data from the Yahoo servers, and how to parse it to return the values.

joshuaulrich commented 3 years ago

I stumbled across some python code that does this using the current Yahoo Finance API. Here's an example for AAPL.

u <- "https://finance.yahoo.com/quote/AAPL/financials"
j <- readLines(u)
j <- sub("root.App.main = ", "", j[grep("root\\.App\\.main", j)])
j <- sub(";$", "", j)
x <- jsonlite::fromJSON(j)
y <- x$context$dispatcher$stores$QuoteSummaryStore

## cashflow statements
z <- y$cashflowStatementHistory$cashflowStatements

## others
## cashflowStatementHistory, cashflowStatementHistoryQuarterly
## balanceSheetHistory, balanceSheetHistoryQuarterly
## incomeStatementHistory, incomeStatementHistoryQuarterly

r <- lapply(z, function(x) { x[[1]] })
enddate <- r$endDate
r$maxAge <- r$endDate <- NULL
xd <- xts(data.frame(r), as.Date(.POSIXct(enddate, "UTC")))

I don't have time to update the functions to use this code. Hopefully someone else can give it a try.