7

I am looking for a way to get stock splitting information. Using the yahoo stock API I can get all types of info on any symbol but I don't think I can get the split ratio or even whether it split. Does anyone know of a way of getting this info?

Kara
  • 6,115
  • 16
  • 50
  • 57
milan
  • 2,179
  • 9
  • 24
  • 34

2 Answers2

16

This is how the quantmod R package does it. The split information is in the "Dividend Only" CSV:
http://ichart.finance.yahoo.com/x?s=IBM&a=00&b=2&c=1962&d=04&e=25&f=2011&g=v&y=0&z=30000

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • How are you deriving split info from the "Dividend Only" CSV? – milan May 25 '11 at 12:41
  • Nice, thank you, this is exactly what I was looking for! Where can I get info on all the different search criteria's? I found it on third part website's but nothing official from yahoo. Any thoughts? – milan May 25 '11 at 13:10
  • 1
    [gummy-stuff](http://www.gummy-stuff.org/Yahoo-data.htm) has the most information. I think I found the http://ichart.finance.yahoo.com/x? URL on the Wealth-Lab forums. I don't believe Yahoo has any official documentation. – Joshua Ulrich May 25 '11 at 13:16
  • Also, where else I can find other yahoo URL's for finance. I've used http://finance.yahoo.com/d/quotes.csv?s=XOM+BBDb.TO+JNJ+MSFT&f=snd1l1yr and now http://ichart.finance.yahoo.com/x?s=IBM&a=00&b=2&c=1962&d=04&e=25&f=2011&g=v&y=0&z=30000. Are there other ones? Where can I find this info? – milan May 25 '11 at 13:16
  • Sorry, saw your reply after I replied. Thank you. – milan May 25 '11 at 13:17
  • is there a way to download all the recent stock splits in one go, rather than stock by stock? thanks! – Laurence_jj Jun 14 '21 at 14:21
7

You can do it easily in python 3 with the help of the pandas datareader package. Starting defining a function which will return the split history as a dataframe:

def split_history(stock, date_start, date_end, limit_denominator=1000):
    from decimal import Decimal
    from fractions import Fraction
    from pandas_datareader import data as web
    df = web.DataReader(stock, data_source='yahoo-actions', start=date_start, end=date_end)
    is_split = df['action']=='SPLIT'
    df = df[is_split]
    ratios = []
    for index, row in df.iterrows():
        # Taking the inverse of the row['value'] as it is Yahoo finance convention
        ratio = Fraction(1/Decimal(row['value'])).limit_denominator(limit_denominator)
        ratios.append("{num} for {denom}".\
                            format(num=ratio.numerator, denom=ratio.denominator))
    df['ratio'] = ratios
    return df

Now we can get the splits of Microsoft ('MSFT') as an example:

stock = 'MSFT'
date_start = '1987-01-01'
date_end = '2020-07-22'
split_history(stock, date_start, date_end)
            action  value       ratio
2003-02-18  SPLIT   0.500000    2 for 1
1999-03-29  SPLIT   0.500000    2 for 1
1998-02-23  SPLIT   0.500000    2 for 1
1996-12-09  SPLIT   0.500000    2 for 1
1994-05-23  SPLIT   0.500000    2 for 1
1992-06-15  SPLIT   0.666667    3 for 2
1991-06-27  SPLIT   0.666667    3 for 2
1990-04-16  SPLIT   0.500000    2 for 1
1987-09-21  SPLIT   0.500000    2 for 1

It handles also properly the reverse stock splits:

stock = 'PHM.MC'
split_history(stock, date_start, date_end)
                action  value   ratio
 2020-07-22     SPLIT   12.0    1 for 12

ps: probably there are better ways to input the dates. ps2: also, the limit_denominator is there to avoid wrong roundings. You can extend it in rare split ratio cases.

alelorca
  • 99
  • 1
  • 3