YFinance.jl
Download price, fundamental, and option data from Yahoo Finance This is a side project and my first package so do not expect too much.
*** LEGAL DISCLAIMER ***
Yahoo!, Y!Finance, and Yahoo! finance are registered trademarks of Yahoo, Inc.
YFinance.jl is not affiliated with Yahoo, Inc. in any way. The data retreived can only be used for personal use. Please see Yahoo's terms of use:
What you can download
- Price data (including intraday)
- Fundamental data
- Option Data
- ESG Data
- quoteSummary data (this is a JSON3.object that contains a multitude of different information)
Function Documentation
YFinance.get_prices — Functionget_prices(symbol::AbstractString; range::AbstractString="1mo", interval::AbstractString="1d",startdt="", enddt="",prepost=false,autoadjust=true,timeout = 10)
Retrievs prices from Yahoo Finance.
Arguments
Smybolis a ticker (e.g. AAPL for Apple Computers, or ^GSPC for the S&P500)
You can either provide a range or a startdt and an enddt.
rangetakes the following values: "1d","5d","1mo","3mo","6mo","1y","2y","5y","10y","ytd","max"
startdtandenddttake the following types:::Date,::DateTime, or aStringof the following formyyyy-mm-dd
prepostis a boolean indicating whether pre and post periods should be included. Defaults tofalse
autoadjustdefaults totrue. It adjusts open, high, low, close prices, and volume by multiplying the with the ratios between the close and the adjusted close prices - only available for intervals of 1d and up.
Examples
julia> get_prices("AAPL",range="1d",interval="90m")
Dict{String, Any} with 7 entries:
"vol" => [10452686, 0]
"ticker" => "AAPL"
"high" => [142.55, 142.045]
"open" => [142.34, 142.045]
"timestamp" => [DateTime("2022-12-09T14:30:00"), DateTime("2022-12-09T15:08:33")]
"low" => [140.9, 142.045]
"close" => [142.28, 142.045]Can be easily converted to a DataFrame
julia> get_prices("AAPL",range="1d",interval="90m") |> DataFrame
2×7 DataFrame
Row │ close timestamp high low open ticker vol
│ Float64 DateTime Float64 Float64 Float64 String Int64
────┼───────────────────────────────────────────────────────────────────────────
1 │ 142.28 2022-12-09T14:30:00 142.55 140.9 142.34 AAPL 10452686
2 │ 142.19 2022-12-09T15:08:03 142.19 142.19 142.19 AAPL 0Broadcasting
julia> get_prices.(["AAPL","NFLX"],range="1d",interval="90m")
2-element Vector{Dict{String, Any}}:
Dict(
"vol" => [11085386, 0],
"ticker" => "AAPL",
"high" => [142.5500030517578, 142.2949981689453],
"open" => [142.33999633789062, 142.2949981689453],
"timestamp" => [DateTime("2022-12-09T14:30:00"), DateTime("2022-12-09T15:15:34")],
"low" => [140.89999389648438, 142.2949981689453],
"close" => [142.27000427246094, 142.2949981689453])
Dict(
"vol" => [4435651, 0],
"ticker" => "NFLX",
"high" => [326.29998779296875, 325.30999755859375],
"open" => [321.45001220703125, 325.30999755859375],
"timestamp" => [DateTime("2022-12-09T14:30:00"), DateTime("2022-12-09T15:15:35")],
"low" => [319.5199890136719, 325.30999755859375],
"close" => [325.79998779296875, 325.30999755859375])Converting it to a DataFrame:
julia> data = get_prices.(["AAPL","NFLX"],range="1d",interval="90m");
julia> vcat([DataFrame(i) for i in data]...)
4×7 DataFrame
Row │ close timestamp high low open ticker vol
│ Float64 DateTime Float64 Float64 Float64 String Int64
────┼───────────────────────────────────────────────────────────────────────────
1 │ 142.21 2022-12-09T14:30:00 142.55 140.9 142.34 AAPL 11111223
2 │ 142.16 2022-12-09T15:12:20 142.16 142.16 142.16 AAPL 0
3 │ 324.51 2022-12-09T14:30:00 326.3 319.52 321.45 NFLX 4407336
4 │ 324.65 2022-12-09T15:12:20 324.65 324.65 324.65 NFLX 0YFinance.get_quoteSummary — Functionget_quoteSummary(symbol::String; item=nothing)
Retrievs general information from Yahoo Finance stored in a JSON3 object.
Arguments
smybol
::Stringis a ticker (e.g. AAPL for Apple Computers, or ^GSPC for the S&P500)item can either be a string or multiple items as a
VectorofStrings. To see valid items call_QuoteSummary_Items(not all items are available for all types of securities)
Examples
julia> get_quoteSummary("AAPL")
JSON3.Object{Vector{UInt8}, SubArray{UInt64, 1, Vector{UInt64}, Tuple{UnitRange{Int64}}, true}} with 31 entries:
:assetProfile => {…
:recommendationTrend => {…
:cashflowStatementHistory => {…
⋮ => ⋮
julia> get_quoteSummary("AAPL",item = "quoteType")
JSON3.Object{Vector{UInt8}, SubArray{UInt64, 1, Vector{UInt64}, Tuple{UnitRange{Int64}}, true}} with 13 entries:
:exchange => "NMS"
:quoteType => "EQUITY"
:symbol => "AAPL"
⋮ => ⋮YFinance.get_Fundamental — Functionget_Fundamental(symbol::AbstractString, item::AbstractString,interval::AbstractString, startdt, enddt)
Retrievs financial statement information from Yahoo Finance stored in a Dictionary.
Arguments
smybol
::Stringis a ticker (e.g. AAPL for Apple Computers, or ^GSPC for the S&P500)item
::Stringcan either be an entire financial statement or a subitem. Entire financial statements:"incomestatement", "valuation", "cashflow", "balancesheet". To see valid sub items grouped by financial statement type in a Dictionary call `Fundamental_Types`interval
::Stringcan be one of "annual", "quarterly", "monthly"startdt
andenddttake the following types:::Date,::DateTime, or aStringof the following formyyyy-mm-dd`
Examples
julia> get_Fundamental("NFLX", "income_statement","quarterly","2000-01-01","2022-12-31")
Dict{String, Any} with 39 entries:
"NetNonOperatingInterestIncomeExpense" => Any[-94294000, -80917000, 8066000, 44771000, 88829000]
"NetInterestIncome" => Any[-94294000, -80917000, 8066000, 44771000, 88829000]
"InterestExpense" => Any[190429000, 189429000, 187579000, 175455000, 172575000]
⋮ => ⋮
julia> get_Fundamental("AAPL", "InterestExpense","quarterly","2000-01-01","2022-12-31") |> DataFrame
5×2 DataFrame
Row │ InterestExpense timestamp
│ Any DateTime
────┼──────────────────────────────────────
1 │ 672000000 2021-09-30T00:00:00
2 │ 694000000 2021-12-31T00:00:00
3 │ 691000000 2022-03-31T00:00:00
4 │ 719000000 2022-06-30T00:00:00
5 │ 827000000 2022-09-30T00:00:00YFinance.get_Options — Functionget_Options(symbol::String)
Retrievs options data from Yahoo Finance stored in a Dictionary with two items. One contains Call options the other Put options. These subitems are dictionaries themselves. The call and put options Dictionaries can readily be transformed to a DataFrame.
Arguments
- smybol
::Stringis a ticker (e.g. AAPL for Apple Computers, or ^GSPC for the S&P500)
Examples
julia> get_Options("AAPL")
Dict{String, Dict{String, Vector{Any}}} with 2 entries:
"calls" => Dict("percentChange"=>[ -2.90804 … 0], "expiration"=>[DateTime("2022-12-09T00:…
"puts" => Dict("percentChange"=>[0, … 0], "expiration"=>[DateTime("2022-12-09T00:00:00"), DateTime("20…
julia> get_Options("AAPL")["calls"] |> DataFrame
65×16 DataFrame
Row │ ask bid change contractSize contractSymbol currency exp ⋯
│ Any Any Any Any Any Any Any ⋯
────┼────────────────────────────────────────────────────────────────────────────
1 │ 94.3 94.1 0 REGULAR AAPL221209C00050000 USD 202 ⋯
2 │ 84.3 84.15 0 REGULAR AAPL221209C00060000 USD 202
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋱
64 │ 0.01 0 0 REGULAR AAPL221209C00240000 USD 202
65 │ 0 0 0 REGULAR AAPL221209C00250000 USD 202
10 columns and 61 rows omitted
julia> data = get_Options("AAPL")
julia> vcat( [DataFrame(i) for i in values(data)]...)
124×16 DataFrame
Row │ ask bid change contractSize contractSymbol cur ⋯
│ Any Any Any Any Any Any ⋯
────┼──────────────────────────────────────────────────────────────────
1 │ 94.3 94.1 0 REGULAR AAPL221209C00050000 USD ⋯
2 │ 84.55 84.35 0 REGULAR AAPL221209C00060000 USD
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋱
123 │ 75.85 75.15 0 REGULAR AAPL221209P00220000 USD
124 │ 85.85 85.15 0 REGULAR AAPL221209P00230000 USD
11 columns and 120 rows omittedYFinance.get_ESG — Functionget_ESG(symbol::String)
Retrievs ESG Scores from Yahoo Finance stored in a Dictionary with two items. One, score, contains the companies ESG scores and individal Overall, Environment, Social and Goverance Scores as well as a timestamp of type DateTime. The other, peer_score, contains the peer group's scores. The subdictionaries can be transformed to DataFrames
Arguments
- smybol
::Stringis a ticker (e.g. AAPL for Apple Computers, or ^GSPC for the S&P500)
Examples
julia> get_ESG("AAPL")
Dict{String, Dict{String, Any}} with 2 entries:
"peer_score" => Dict("governanceScore"=>Union{Missing, Float64}[63.2545, 63.454…
"score" => Dict("governanceScore"=>Union{Missing, Real}[62, 62, 62, 62, 62…
julia> get_ESG("AAPL")["score"] |> DataFrame
96×6 DataFrame
Row │ environmentScore esgScore governanceScore socialScore symbol times ⋯
│ Real? Real? Real? Real? String DateT ⋯
────┼────────────────────────────────────────────────────────────────────────────
1 │ 74 61 62 45 AAPL 2014- ⋯
2 │ 74 60 62 45 AAPL 2014-
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋱
95 │ missing missing missing missing AAPL 2022-
96 │ 0.65 16.68 9.18 6.86 AAPL 2022-
1 column and 92 rows omitted