当前位置: 首页>>代码示例>>Python>>正文


Python Timeseries.from_url方法代码示例

本文整理汇总了Python中orangecontrib.timeseries.Timeseries.from_url方法的典型用法代码示例。如果您正苦于以下问题:Python Timeseries.from_url方法的具体用法?Python Timeseries.from_url怎么用?Python Timeseries.from_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在orangecontrib.timeseries.Timeseries的用法示例。


在下文中一共展示了Timeseries.from_url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: quandl_data

# 需要导入模块: from orangecontrib.timeseries import Timeseries [as 别名]
# 或者: from orangecontrib.timeseries.Timeseries import from_url [as 别名]
def quandl_data(symbol,
                since=None,
                until=None,
                *,
                collapse='daily',
                api_key=''):
    """

    Parameters
    ----------
    symbol
    since
    until
    collapse: none|daily|weekly|monthly|quarterly|annual
    api_key

    Returns
    -------

    """
    if since is None:
        since = date(1900, 1, 1).isoformat()
    if until is None:
        until = date.today().isoformat()

    QUANDL_URL = ('https://www.quandl.com/api/v3/datasets/WIKI/{SYMBOL}/data.csv?'
                  'start_date={START_DATE}&end_date={END_DATE}&order=asc&'
                  'collapse={COLLAPSE}&transform=rdiff&api_key={API_KEY}')
    url = QUANDL_URL.format(SYMBOL=symbol,
                            START_DATE=since,
                            END_DATE=until,
                            COLLAPSE=collapse,
                            API_KEY=api_key)
    ts = Timeseries.from_url(url)
    return ts
开发者ID:ajdapretnar,项目名称:orange3-timeseries,代码行数:37,代码来源:datasources.py

示例2: finance_data

# 需要导入模块: from orangecontrib.timeseries import Timeseries [as 别名]
# 或者: from orangecontrib.timeseries.Timeseries import from_url [as 别名]
def finance_data(symbol,
                 since=None,
                 until=None,
                 granularity='d'):
    """Fetch Yahoo Finance data for stock or index `symbol` within the period
    after `since` and before `until` (both inclusive).

    Parameters
    ----------
    symbol: str
        A stock or index symbol, as supported by Yahoo Finance.
    since: date
        A start date (default: 1900-01-01).
    until: date
        An end date (default: today).
    granularity: 'd' or 'w' or 'm' or 'v'
        What data to get: daily, weekly, monthly, or dividends.

    Returns
    -------
    data : Timeseries
    """
    if since is None:
        since = date(1900, 1, 1)
    if until is None:
        until = date.today()

    YAHOO_URL = ('http://chart.finance.yahoo.com/table.csv?'
                 's={SYMBOL}&d={TO_MONTH}&e={TO_DAY}&f={TO_YEAR}&'
                 'g={GRANULARITY}&a={FROM_MONTH}&b={FROM_DAY}&c={FROM_YEAR}&ignore=.csv')
    url = YAHOO_URL.format(SYMBOL=symbol,
                           GRANULARITY=granularity,
                           TO_MONTH=until.month - 1,
                           TO_DAY=until.day,
                           TO_YEAR=until.year,
                           FROM_MONTH=since.month - 1,
                           FROM_DAY=since.day,
                           FROM_YEAR=since.year)

    data = Timeseries.from_url(url)[::-1]

    # Make Adjusted Close a class variable
    attrs = [var.name for var in data.domain.attributes]
    attrs.remove('Adj Close')
    data = Timeseries(Domain(attrs, [data.domain['Adj Close']], None, source=data.domain), data)

    data.name = symbol
    data.time_variable = data.domain['Date']
    return data
开发者ID:ajdapretnar,项目名称:orange3-timeseries,代码行数:51,代码来源:datasources.py


注:本文中的orangecontrib.timeseries.Timeseries.from_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。