Download Price Data
YFinance.get_prices — Functionget_prices(symbol::AbstractString; range::AbstractString="1mo", interval::AbstractString="1d",startdt="", enddt="",prepost=false,autoadjust=true,timeout = 10,throw_error=false)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-ddprepostis a boolean indicating whether pre and post periods should be included. Defaults tofalseautoadjustdefaults totrue. It adjusts open, high, low, close prices, and volume by multiplying by the ratio between the close and the adjusted close prices - only available for intervals of 1d and up.throw_error
::Booldefaults tofalse. If set to true the function errors when the ticker is not valid. Else a warning is given and an empty dictionary is returned.exchangelocaltime
::Booldefaults tofalse. If set to true the timestamp corresponds to the exchange local time else to GMT.
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> using DataFrames
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> using DataFrames
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 0