Download Price Data

This function returns open, high, low, close, and adjusted close prices as well as volume.

For a few stocks yahoo finance will return nothing for specific timestamps in the price series.

For performance reasons and easier integration with TimeSeries.jl these nothing values are returned as NaNs. Some other packages like python's yahooquery do not return these datapoints at all. We decided to return them to indicate a break in the series and to indicate that Yahoo Finance thinks it should have price information for the specific timestamp but does not have any.

YFinance.get_pricesFunction
get_prices(symbol::AbstractString; range::AbstractString="1mo", interval::AbstractString="1d",startdt="", enddt="",prepost=false,autoadjust=true,timeout = 10,throw_error=false,exchange_local_time=false,divsplits=false)

Retrievs prices from Yahoo Finance.

Arguments

  • Smybol is 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.

  • range takes the following values: "1d","5d","1mo","3mo","6mo","1y","2y","5y","10y","ytd","max". Note: when range is selected rather than startdt or enddt the specified interval may not be observed by Yahoo! Therefore, it is recommended to use startdt and enddt instead. To get max simply set startdt = "1900-01-01"

  • startdt and enddt take the following types: ::Date,::DateTime, or a String of the following form yyyy-mm-dd

  • prepost is a boolean indicating whether pre and post periods should be included. Defaults to false

  • autoadjust defaults to true. 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::Bool defaults to false. If set to true the function errors when the ticker is not valid. Else a warning is given and an empty OrderedCollections.OrderedDict is returned.

  • exchange_local _time::Bool defaults to false. If set to true the timestamp corresponds to the exchange local time else to GMT.

  • divsplits::Bool defaults to false. If set to true dividends and stock split data is also returned. Split data contains the numerator, denominator, and split ratio. The interval needs to be set to "1d" for this to work.

Examples

julia> get_prices("AAPL",range="1d",interval="90m")
OrderedDict{String, Any} with 7 entries:
  "ticker"    => "AAPL"
  "timestamp" => [DateTime("2022-12-29T14:30:00"), DateTime("2022-12-29T16:00:00"), DateTime("2022-12-29T17:30:00"), DateTime("2022-12-29T19:00:00"), DateTime("2022-12-29T20:30:00"), DateTime("2022-12-29T21:00:00")]   
  "open"      => [127.99, 129.96, 129.992, 130.035, 129.95, 129.61]
  "high"      => [129.98, 130.481, 130.098, 130.24, 130.22, 129.61]
  "low"       => [127.73, 129.44, 129.325, 129.7, 129.56, 129.61]
  "close"     => [129.954, 129.998, 130.035, 129.95, 129.6, 129.61]
  "vol"       => [29101646, 14058713, 9897737, 9552323, 6308537, 0]

Can be easily converted to a DataFrame

julia> using DataFrames
julia> get_prices("AAPL",range="1d",interval="90m") |> DataFrame
6×7 DataFrame
 Row │ ticker  timestamp            open     high     low      close    vol      
     │ String  DateTime             Float64  Float64  Float64  Float64  Int64    
─────┼───────────────────────────────────────────────────────────────────────────
   1 │ AAPL    2022-12-29T14:30:00  127.99   129.98   127.73   129.954  29101646 
   2 │ AAPL    2022-12-29T16:00:00  129.96   130.481  129.44   129.998  14058713 
   3 │ AAPL    2022-12-29T17:30:00  129.992  130.098  129.325  130.035   9897737 
   4 │ AAPL    2022-12-29T19:00:00  130.035  130.24   129.7    129.95    9552323 
   5 │ AAPL    2022-12-29T20:30:00  129.95   130.22   129.56   129.6     6308537 
   6 │ AAPL    2022-12-29T21:00:00  129.61   129.61   129.61   129.61          0 

Broadcasting

julia> get_prices.(["AAPL","NFLX"],range="1d",interval="90m")
OrderedDict("ticker" => "AAPL",
    "timestamp" => [DateTime("2022-12-29T14:30:00"), DateTime("2022-12-29T16:00:00"), DateTime("2022-12-29T17:30:00"), DateTime("2022-12-29T19:00:00"), DateTime("2022-12-29T20:30:00"), DateTime("2022-12-29T21:00:00")], 
    "open" => [127.98999786376953, 129.9600067138672, 129.99240112304688, 130.03500366210938, 129.9499969482422, 129.61000061035156], 
    "high" => [129.97999572753906, 130.4813995361328, 130.09829711914062, 130.24000549316406, 130.22000122070312, 129.61000061035156], 
    "low" => [127.7300033569336, 129.44000244140625, 129.3249969482422, 129.6999969482422, 129.55999755859375, 129.61000061035156], 
    "close" => [129.95419311523438, 129.99830627441406, 130.03500366210938, 129.9499969482422, 129.60000610351562, 129.61000061035156], 
    "vol" => [29101646, 14058713, 9897737, 9552323, 6308537, 0])
OrderedDict("ticker" => "NFLX",
    "timestamp" => [DateTime("2022-12-29T14:30:00"), DateTime("2022-12-29T16:00:00"), DateTime("2022-12-29T17:30:00"), DateTime("2022-12-29T19:00:00"), DateTime("2022-12-29T20:30:00"), DateTime("2022-12-29T21:00:00")],
    "open" => [283.17999267578125, 289.5199890136719, 293.4200134277344, 290.05499267578125, 290.760009765625, 291.1199951171875],
    "high" => [291.8699951171875, 295.4999084472656, 293.5, 291.32000732421875, 292.3299865722656, 291.1199951171875],
    "low" => [281.010009765625, 289.489990234375, 289.5400085449219, 288.7699890136719, 290.5400085449219, 291.1199951171875],
    "close" => [289.5199890136719, 293.46990966796875, 290.04998779296875, 290.82000732421875, 291.1199951171875, 291.1199951171875],
    "vol" => [2950791, 2458057, 1362915, 1212217, 1121821, 0]) 

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]...)
12×7 DataFrame
 Row │ ticker  timestamp            open     high     low      close    vol      
     │ String  DateTime             Float64  Float64  Float64  Float64  Int64    
─────┼───────────────────────────────────────────────────────────────────────────
   1 │ AAPL    2022-12-29T14:30:00  127.99   129.98   127.73   129.954  29101646
   2 │ AAPL    2022-12-29T16:00:00  129.96   130.481  129.44   129.998  14058713
   3 │ AAPL    2022-12-29T17:30:00  129.992  130.098  129.325  130.035   9897737
   4 │ AAPL    2022-12-29T19:00:00  130.035  130.24   129.7    129.95    9552323
   5 │ AAPL    2022-12-29T20:30:00  129.95   130.22   129.56   129.6     6308537
   6 │ AAPL    2022-12-29T21:00:00  129.61   129.61   129.61   129.61          0
   7 │ NFLX    2022-12-29T14:30:00  283.18   291.87   281.01   289.52    2950791
   8 │ NFLX    2022-12-29T16:00:00  289.52   295.5    289.49   293.47    2458057
   9 │ NFLX    2022-12-29T17:30:00  293.42   293.5    289.54   290.05    1362915
  10 │ NFLX    2022-12-29T19:00:00  290.055  291.32   288.77   290.82    1212217
  11 │ NFLX    2022-12-29T20:30:00  290.76   292.33   290.54   291.12    1121821
  12 │ NFLX    2022-12-29T21:00:00  291.12   291.12   291.12   291.12          0
source