ljupch0 / yfinance Goto Github PK
View Code? Open in Web Editor NEWTidy Financial Statement Data in R. Via the Yahoo Finance API.
Tidy Financial Statement Data in R. Via the Yahoo Finance API.
ticker <- "AA"
company_name <- yfinance::get_company_names(ticker)
summary <- yfinance::get_summaries(ticker)
yields:
Error in open.connection(con, "rb") : HTTP error 404.
I could not get the quote of a ticker
yfinance::get_price("AAPL")
and I got this return:
Warning messages:
1: replacing previous import ‘purrr::flatten’ by ‘jsonlite::flatten’ when loading ‘yfinance’
2: In safe_download(vector = ticker, proto_function = get_price_proto) :
There were ERRORS while downloading data for these items: AAPL.
Please check if you have the correct ticker. The vector of errored items and error messages can be accessed as attributes of the returned dataframe - attributes(df).
R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Has anyone else encountered similar issues?
Hi Ljupch0,
I am new to this so if this is a simple fix apologies for wasting your time. I have been following along and I could successfully run all code bar get_company_names which returns "Error in open.connection(con, "rb") : HTTP error 404." although the tickers are spelt correctly.
I left this as it wasn't essential to continue with the tutorial but when I got to Nested Data I got the following error when mutating
> biotech_balance_sheets <- tibble(
+ companies = companies
+ ) %>%
+ mutate(
+ ticker = yfinance::search_stock(search_term = companies, keep_results = "top")$symbol,
+ full_name = yfinance::search_stock(search_term = companies, keep_results = "top")$longname,
+ )
Warning: Problem with mutate()
column ticker
.
i ticker = yfinance::search_stock(search_term = companies, keep_results = "top")$symbol
.
i There were ERRORS while downloading data for these items: Alexion Pharmaceuticals Inc..
Please check if you have the correct ticker. The vector of errored items and error messages can be accessed as attributes of the returned dataframe - attributes(df).
Error: Problem with mutate()
column ticker
.
i ticker = yfinance::search_stock(search_term = companies, keep_results = "top")$symbol
.
i ticker
must be size 8 or 1, not 7.
Run rlang::last_error()
to see where the error occurred.
> biotech_balance_sheets <- tibble(
+ companies = companies
+ )
> biotech_balance_sheets <- tibble(
+ companies = companies
+ ) %>%
+ mutate(
+ ticker = yfinance::search_stock(search_term = companies, keep_results = "top")$symbol,
+ full_name = yfinance::search_stock(search_term = companies, keep_results = "top")$longname,
+ )
Warning: Problem with mutate()
column ticker
.
i ticker = yfinance::search_stock(search_term = companies, keep_results = "top")$symbol
.
i There were ERRORS while downloading data for these items: Alexion Pharmaceuticals Inc..
Please check if you have the correct ticker. The vector of errored items and error messages can be accessed as attributes of the returned dataframe - attributes(df).
Error: Problem with mutate()
column ticker
.
i ticker = yfinance::search_stock(search_term = companies, keep_results = "top")$symbol
.
i ticker
must be size 8 or 1, not 7.
Run rlang::last_error()
to see where the error occurred.
> rlang::last_error()
x
+-<error/dplyr:::mutate_error>
| Problem with mutate()
column ticker
.
| i ticker = yfinance::search_stock(search_term = companies, keep_results = "top")$symbol
.
| i ticker
must be size 8 or 1, not 7.
-<error/dplyr:::mutate_incompatible_size>
Backtrace:
1. %>%
(...)
7. dplyr:::abort_glue(character(0), list(x_size = 7L), "dplyr:::mutate_incompatible_size")
8. rlang::exec(abort, class = class, !!!data)
Run rlang::last_trace()
to see the full context.
> rlang::last_trace()
x
+-<error/dplyr:::mutate_error>
| Problem with mutate()
column ticker
.
| i ticker = yfinance::search_stock(search_term = companies, keep_results = "top")$symbol
.
| i ticker
must be size 8 or 1, not 7.
-<error/dplyr:::mutate_incompatible_size>
Backtrace:
x
1. +-%>%
(...)
2. +-dplyr::mutate(...)
3. +-dplyr:::mutate.data.frame(...)
4. | -dplyr:::mutate_cols(.data, ..., caller_env = caller_env())
5. | +-base::withCallingHandlers(...)
6. | -mask$eval_all_mutate(quo)
7. -dplyr:::abort_glue(character(0), list(x_size = 7L), "dplyr:::mutate_incompatible_size")
8. -rlang::exec(abort, class = class, !!!data)
Thanks
Hi, I'm getting this code while trying to run the package. Any ideas of the source of the issue? Thank you.
I love yfinance -- however, there is one minor nuisance.
When it runs, this type of output appears:
Downloading Prices SQ [======================>---------------] 62% ETA: 5s
Downloading Prices TTD [=======================>-------------] 65% ETA: 4s
Downloading Prices TTEK [========================>-----------] 69% ETA: 4s
Downloading Prices UNH [==========================>----------] 73% ETA: 3s
Is it possible to suppress that output?
Hello Ljupcho,
Just to report a weird situation when retrieving the Cash Flow Statement of the ticker AMD
.
The Operating Cash Flow (annual) for 2017 is not the same shown in the CF Statement in the Y! Finance web page.
I do not believe is any issue with the package, but an issue of the API.
In any case, I thought it was worth to share it.
Thanks for the package!
Daniel.
When API calls fail, it should still return all tickers that worked and a warning message listing everything that failed.
I'm experiencing what seems to be an issue with the Yahoo Finance Endpoint behind get_price()
:
> yfinance::get_price("SPY")
# A tibble: 0 x 0
Warning messages:
1: In open.connection(con, "rb") :
cannot open URL 'https://query2.finance.yahoo.com/v10/finance/quoteSummary/SPY?modules=price': HTTP status was '401 Unauthorized'
2: In safe_download(vector = ticker, proto_function = get_price_proto) :
There were ERRORS while downloading data for these items: SPY.
Please check if you have the correct ticker. The vector of errored items and error messages can be accessed as attributes of the returned dataframe - attributes(df).
It seems like quantmod
package authors have dealt with** a very similar issue in a certain way (although it is with a different endpoint and API version etc...)
**https://github.com/joshuaulrich/quantmod/pull/383/files/554af1b9f35bff83afb700f1f98281be785e56d3
As the title says this is the error I get.
It seems to me that parse_number
in the clean
function fails because the dataframe has NAs and "" (empty strings?). Maybe a solution would be to turn all NA and "" to "0" and then parse_number
, then convert 0 to NA. Or maybe use stringr::str_replace_na
to get NA_character_
.
Also as far as I can see there are some things going on in line 40: headers <- c('Items','TTM', matches[[1]][,1])
that messes the column names leaving some columns without a name. This has implications further down the code at line 62. Maybe I should've made another issue for this one.
sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux
Matrix products: default
BLAS: /usr/lib/libopenblasp-r0.3.7.so
LAPACK: /usr/lib/liblapack.so.3.9.0
locale:
[1] LC_CTYPE=mk_MK.UTF-8 LC_NUMERIC=C LC_TIME=mk_MK.UTF-8
[4] LC_COLLATE=mk_MK.UTF-8 LC_MONETARY=mk_MK.UTF-8 LC_MESSAGES=mk_MK.UTF-8
[7] LC_PAPER=mk_MK.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=mk_MK.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] equityanalysis_0.1.0
Hi Daniel, yes it's a strange issue of the api. I checked the financials and the figure on the website is the correct one. Interesting that the problem is only for 2017, the other figures are the same on the website and api.
Originally posted by @Ljupch0 in #4 (comment)
at first, really thanks to your wonderful package
do you have plan to download statistics page , like link below
this information is also very useful
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.