【问题标题】:stocks splitting api google or yahoo股票拆分 api 谷歌或雅虎
【发布时间】:2011-05-25 05:21:02
【问题描述】:

我正在寻找一种获取股票拆分信息的方法。使用雅虎股票 API,我可以获得任何符号的所有类型的信息,但我认为我无法获得拆分比率,甚至无法获得拆分。有人知道获取此信息的方法吗?

【问题讨论】:

    标签: yahoo-finance google-finance


    【解决方案1】:

    quantmod R 包就是这样做的。拆分信息在“仅股息”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

    【讨论】:

    • 您如何从“仅股息”CSV 中获取拆分信息?
    • 很好,谢谢,这正是我想要的!我在哪里可以获得有关所有不同搜索条件的信息?我在第三方网站上找到了它,但没有来自雅虎的官方信息。有什么想法吗?
    • gummy-stuff 拥有最多的信息。我想我找到了ichart.finance.yahoo.com/x? Wealth-Lab 论坛上的 URL。我不相信雅虎有任何官方文档。
    • 另外,我还能在哪里找到其他 yahoo URL's for Finance。我使用过finance.yahoo.com/d/…,现在使用ichart.finance.yahoo.com/…。还有其他的吗?我在哪里可以找到这些信息?
    • 对不起,我回复后才看到你的回复。谢谢。
    【解决方案2】:

    借助 pandas datareader 包,您可以在 python 3 中轻松完成。 开始定义一个将拆分历史记录作为数据框返回的函数:

    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
    

    现在我们可以以微软('MSFT')的拆分为例:

    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
    

    它还可以正确处理反向股票拆分:

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

    ps:可能有更好的方法来输入日期。 ps2:还有,limit_denominator 是为了避免错误的舍入。您可以在罕见的分流比情况下扩展它。

    【讨论】:

      猜你喜欢
      • 2016-12-22
      • 2012-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-21
      • 1970-01-01
      相关资源
      最近更新 更多