Skip to content

Download historical stock market data from Yahoo Finance. Exposes stock, commodity, futures, currency (FX), mutual fund, and ETF prices, stock fundamental, summary data , and options data.

License

Notifications You must be signed in to change notification settings

eohne/YFinance.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YFinance.jl

codecov Build Status Package Downloads

Download price, fundamental, option, currency, futures, ETF, mutual fund, and various other data from Yahoo Finance

*** LEGAL DISCLAIMER ***

Yahoo!, Y!Finance, and Yahoo! finance are registered trademarks of Yahoo, Inc.

YFinance.jl is not endorsed or in anyway affiliated with Yahoo, Inc. The data retreived can only be used for personal use. Please see Yahoo's terms of use to ensure that you can use the data:

*** No decryption issues ***

The implementation of YFinance.jl is similar to the python package yahooquery in that it accesses data through API endpoints. Therefore, YFinance.jl does not experience the same decryption issues that python’s yfinance faces at the moment.

Installation

The package is registered in the General registry and so can be installed at the REPL with ] add YFinance or by running:

    using Pkg 
    Pkg.add("YFinance")

Precompilation

Version 0.1.8

Precompilation of the get_prices function. This has caused precompilation hangs for Julia 1.10 and 1.11 - package typically still precompiles but takes long and gives warnings. Note precompilation also does not work if you require to set a proxy to access the internet.

To Install this version enter the package mode by entering ] in the REPL and run the following command:

(@v1.10) pkg> add YFinance @v0.1.8

Version 0.1.9

Does not precompile.
To Install this version enter the package mode by entering ] in the REPL and run the following command:

  (@v1.10) pkg> add YFinance @v0.1.9

Version 0.1.10

Precompiles only the response processing part of the get_prices and not the HTTP request. Most of the compilation time lies unfortunately with the request itself.
To Install this version enter the package mode by entering ] in the REPL and run the following command:

  (@v1.10) pkg> add YFinance

Examples:

There are more examples in the Docs.

Get Prices:

Apple monthly stock price over the past 5 years, with dividend and stock split information in local user time.

using YFinance

get_prices("AAPL",range="5y",interval="1mo",divsplits=true,exchange_local_time=false)
OrderedCollections.OrderedDict{String, Any} with 8 entries:
  "ticker"    => "AAPL"
  "timestamp" => [DateTime("2019-09-01T04:00:00"), DateTime("2019-10-01T04:00:00"), DateTime("2019-11-01T04:00:00"), DateT
  "open"      => [49.9955, 54.5099, 60.4363, 64.9247, 71.9621, 73.92, 68.7337, 60.0214, 69.7003, 77.5799    189.83, 186.6
  "high"      => [54.8369, 60.4872, 64.9072, 71.4106, 79.6407, 79.4877, 74.0224, 71.7165, 78.9507, 90.918    199.096, 195
  "low"       => [49.4603, 52.1026, 60.3443, 62.2575, 71.1143, 62.2769, 51.7694, 57.6839, 69.6029, 77.448    186.958, 179
  "close"     => [55.9925, 62.19, 66.8125, 73.4125, 77.3775, 68.34, 63.5725, 73.45, 79.485, 91.2    192.53, 184.4, 180.75
  "adjclose"  => [54.2435, 60.2474, 64.7255, 71.3329, 75.1856, 66.4041, 61.9183, 71.5387, 77.4167, 89.0673    192.024, 18
  "vol"       => [2.10248e9, 2.35721e9, 1.73731e9, 2.32113e9, 2.85125e9, 2.93375e9, 6.11666e9, 3.18033e9, 2.73292e9, 3.167

Convert to DataFrame

Bitcoin USD, 5 minute data points for an entire day.

DataFrame(get_prices("BTC-USD",range="1d",interval="5m",exchange_local_time=true))
147×7 DataFrame
 Row │ ticker   timestamp            open     high     low      close    vol       
     │ String   DateTime             Float64  Float64  Float64  Float64  Float64
─────┼─────────────────────────────────────────────────────────────────────────────
   1 │ BTC-USD  2024-08-08T00:00:00  55139.5  55254.3  55139.5  55254.3  7.3769e6
   2 │ BTC-USD  2024-08-08T00:05:00  55229.6  55355.9  55229.6  55355.9  0.0
   3 │ BTC-USD  2024-08-08T00:10:00  55273.2  55273.2  55121.3  55121.3  1.9198e7
   4 │ BTC-USD  2024-08-08T00:15:00  55099.8  55272.9  55099.8  55232.8  0.0
                                                               
 145 │ BTC-USD  2024-08-08T12:00:00  57346.1  57406.9  57346.1  57406.9  0.0
 146 │ BTC-USD  2024-08-08T12:05:00  57384.4  57384.4  57364.8  57364.8  0.0
 147 │ BTC-USD  2024-08-08T12:08:00  57330.2  57330.2  57330.2  57330.2  0.0
                                                                   140 rows omitted

Sink to TimeArray

Rolls-Royce daily stock price between 2020-01-01 and 2020-05-30

using TimeSeries
get_prices(TimeArray,"RR.L",startdt="2020-01-01",enddt="2020-05-30")
103×6 TimeArray{Float64, 2, DateTime, Matrix{Float64}} 2020-01-02T08:00:00 to 2020-05-29T07:00:00
┌─────────────────────┬─────────┬─────────┬─────────┬─────────┬──────────┬───────────┐
│                     │ open    │ high    │ low     │ close   │ adjclose │ vol       │
├─────────────────────┼─────────┼─────────┼─────────┼─────────┼──────────┼───────────┤
│ 2020-01-02T08:00:00236.374238.845232.874233.766233.7661.12197e7 │
│ 2020-01-03T08:00:00232.668233.629229.03232.599232.5991.2363e7 │
│ 2020-01-06T08:00:00231.295233.766228.932232.325232.3251.13855e7 │
│ 2020-01-07T08:00:00234.041234.26227.658229.305229.3059.56679e6 │
│               │
│ 2020-05-27T07:00:00110.5126.904110.06118.771118.7717.7212e7 │
│ 2020-05-28T07:00:00109.814114.035104.049109.471109.4711.33343e8 │
│ 2020-05-29T07:00:00103.294103.94693.204493.204493.20441.60135e8 │
└─────────────────────┴─────────┴─────────┴─────────┴─────────┴──────────┴───────────┘
                                                                       96 rows omitted

Sink to TSFrame

EURO-USD (EURUSD=X) daily price since start of data

using TSFrames
tsf = get_prices(TSFrame,"EURUSD=X",startdt=Date(1900,1,1),enddt=today())
5399×7 TSFrame with DateTime Index
 Index                open     high     low      close    adjclose  vol      ticker   
 DateTime             Float64  Float64  Float64  Float64  Float64   Float64  String
──────────────────────────────────────────────────────────────────────────────────────
 2003-12-01T00:00:00  1.2034   1.20401  1.1944   1.1965    1.1965       0.0  EURUSD=X
 2003-12-02T00:00:00  1.1961   1.2109   1.1946   1.2089    1.2089       0.0  EURUSD=X
 2003-12-03T00:00:00  1.209    1.213    1.2077   1.2123    1.2123       0.0  EURUSD=X
 2003-12-04T00:00:00  1.212    1.2144   1.2044   1.20809   1.20809      0.0  EURUSD=X
                                                                         
 2024-08-05T23:00:00  1.0951   1.09631  1.09046  1.0951    1.0951       0.0  EURUSD=X
 2024-08-06T23:00:00  1.09262  1.09364  1.09069  1.09262   1.09262      0.0  EURUSD=X
 2024-08-08T12:41:04  1.09266  1.09481  1.09039  1.09039   1.09039      0.0  EURUSD=X
                                                                     5392 rows omitted

Plot this:

using Plots
plot(tsf[:,[:Index,:adjclose]])

EURUSD

Other Data:

ESG

get_ESG("NFLX")["score"] |> DataFrame |> dropmissing
79×6 DataFrame
 Row │ symbol  timestamp            esgScore  governanceScore  environmentScore  socialScore 
     │ String  DateTime             Real      Real             Real              Real
─────┼───────────────────────────────────────────────────────────────────────────────────────
   1 │ NFLX    2014-09-01T00:00:00     43               57                37           39
   2 │ NFLX    2014-10-01T00:00:00     43               57                37           39
   3 │ NFLX    2014-11-01T00:00:00     43               57                37           39
   4 │ NFLX    2014-12-01T00:00:00     43               57                37           39
                                                                          
  77 │ NFLX    2022-05-01T00:00:00     15.78             8.87              0.09         6.83
  78 │ NFLX    2022-08-01T00:00:00     16.25             9.34              0.09         6.83
  79 │ NFLX    2023-09-01T00:00:00     16.41             9.01              0.09         7.31
                                                                              72 rows omitted

Get Valuations of NFLX

get_Fundamental("NFLX", "valuation","annual",today()-Year(3) , today()) |> DataFrame
3×10 DataFrame
 Row │ timestamp            PegRatio  ForwardPeRatio  MarketCap     PeRatio  EnterprisesValueRevenueRatio  PbRatio  EnterprisesValueEBITDARatio  PsRatio  EnterpriseValue 
     │ DateTime             Any       Any             Any           Any      Any                           Any      Any                          Any      Any
─────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   12021-12-31T00:00:00  1.4751    46.5116         267461134181  54.3228  9.6192                        17.4644  14.914                       9.57841  275427617181
   22022-12-31T00:00:00  2.1982    27.027          131227643270  26.3993  4.4166                        6.39726  6.7377                       4.238    139002027270
   32023-12-31T00:00:00  1.951     30.6748         213097477242  48.5908  6.7047                        9.53074  10.686                       6.71235  219530399242

Get Income Statement:

is=get_Fundamental("AMD", "income_statement","annual",today()-Year(1) , today()) |> DataFrame 
stack(is, Not(:timestamp))
49×3 DataFrame
 Row │ timestamp            variable                           value       
     │ DateTime             String                             Any
─────┼─────────────────────────────────────────────────────────────────────
   12023-12-31T00:00:00  InterestExpenseNonOperating        106000000
   22023-12-31T00:00:00  CostOfRevenue                      12220000000
   32023-12-31T00:00:00  TotalRevenue                       22680000000
   42023-12-31T00:00:00  EarningsFromEquityInterestNetOfT  16000000
                                                    
  472023-12-31T00:00:00  NormalizedIncome                   854000000
  482023-12-31T00:00:00  EBIT                               598000000
  492023-12-31T00:00:00  TotalUnusualItems                  0
                                                            42 rows omitted

Options

op = get_Options("AMD")
OrderedCollections.OrderedDict{String, OrderedCollections.OrderedDict{String, Vector{Any}}} with 2 entries:
  "calls" => OrderedDict("contractSymbol"=>["AMD240809C00075000", "AMD240809C00080000", "AMD240809C00085000", "AMD240809C0…
  "puts"  => OrderedDict("contractSymbol"=>["AMD240809P00075000", "AMD240809P00080000", "AMD240809P00085000", "AMD240809P0
DataFrame(op["calls"])
65×16 DataFrame
 Row │ contractSymbol      strike  currency  lastPrice  change  percentChange  volume  openInterest  bid  ask  contractSi 
     │ Any                 Any     Any       Any        Any     Any            Any     Any           Any  Any  Any        
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 │ AMD240809C00075000  75      USD       59.65      0       0              1       26            0    0    REGULAR    
   2 │ AMD240809C00080000  80      USD       52.61      0       0              1       11            0    0    REGULAR     
   3 │ AMD240809C00085000  85      USD       49.69      0       0              2       0             0    0    REGULAR     
   4 │ AMD240809C00090000  90      USD       44.54      0       0              3       12            0    0    REGULAR     
                                                                                                  
  63 │ AMD240809C00285000  285     USD       0.01       0       0              15      16            0    0    REGULAR    
  64 │ AMD240809C00290000  290     USD       0.08       0       0              7       10            0    0    REGULAR     
  65 │ AMD240809C00295000  295     USD       0.01       0       0              1       19            0    0    REGULAR     
                                                                                              6 columns and 58 rows omitted

*** This is only a small subset of functions and data items for a full set please see the documentation. ***