• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python finance.quotes_historical_yahoo函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中matplotlib.finance.quotes_historical_yahoo函数的典型用法代码示例。如果您正苦于以下问题:Python quotes_historical_yahoo函数的具体用法?Python quotes_historical_yahoo怎么用?Python quotes_historical_yahoo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: best_fit_gaussian

def best_fit_gaussian(ticker):
    """determines the best fit gaussian for the distribution of daily
    returns for stock with ticker and makes a plot of the distribution
    and the best-fit gaussian

    =========
    ticker: string for the stock ticker

    Returns
    ======
    None

    Saves plot to 'TICKER_gaussian_fit.pdf'
    """
    # start your code here
    stock_data = finance.quotes_historical_yahoo(ticker, (1950, 1, 1), (2014, 9, 30), asobject=True, adjusted=True)
    returns = np.array([(stock_data.open[i+1] - stock_data.open[i]) / stock_data.open[i] for i in range(len(stock_data.open) - 1)])
    counts, bin_edges = np.histogram(returns, density=True, bins=200)
    bin_centers = bin_edges[:-1]+(bin_edges[1]-bin_edges[0])/2.0
    popt, pcov = curve_fit(gaussian, bin_centers, counts)
    counts_fit = gaussian(bin_centers, *popt)
    blue_dot = plt.plot(bin_centers, counts, label="Daily Returns", color = 'blue', linewidth = 0, marker = 'o', markersize=3, markeredgewidth = 0,  markeredgecolor='none')
    green_line = plt.plot(bin_centers, counts_fit, label="Gaussian", color='green')
    x_axis = plt.xticks()[0]
    text_x_pos = x_axis[math.ceil(len(x_axis) * 0.6)]
    y_axis = plt.yticks()[0]
    text_y_pos = y_axis[math.ceil(len(y_axis) * 0.4)]
    plt.legend(loc="upper right")
    plt.text(text_x_pos, text_y_pos, 'mu={0:.03f}\nsigma={1:.03f}'.format(*(popt[0], popt[1])))
    plt.xlabel('Daily Returns')
    plt.ylabel('Probability Density')
    plt.title(ticker)
    plt.savefig(ticker + '_gaussian_fit.pdf')
    return None
开发者ID:khjtony,项目名称:Proj_Python,代码行数:34,代码来源:lab_5.py


示例2: get_data_yahoo

def get_data_yahoo(start_date, end_date, fut_code="INTC", format = "candle"):
    try:
        quotes = quotes_historical_yahoo(fut_code, start_date, end_date)
    except:
        print("Unable to get quotes for %s", fut_code)
        return []
    if quotes == None:
        print("Unable to get quotes for %s", fut_code)
        return []
    if len(quotes)==0:
        print("Unable to get quotes for %s", fut_code)
        return []
    else:
        if(quotes[0][0] < float(datetime.datetime.toordinal(start_date)) or \
            quotes[len(quotes)-1][0] > float(datetime.datetime.toordinal(end_date))):
            print "unnable to get yahoo quotes for ticker %s for required dates" %fut_code
            return None
        if(format=="candle"):
            dt, op, cl, hi, lo, vol = zip(*quotes)
            dt2 = []
            for d in dt:
                dt2.append(datetime.datetime.fromordinal(int(d)))
            quotes = zip(dt2, op, cl, hi, lo, vol)
            return quotes
        else:
            dt, op, cl, hi, lo, vol = zip(*quotes)
            return zip(dt, cl)
开发者ID:richardpeter3,项目名称:robo_pleb,代码行数:27,代码来源:get_data.py


示例3: get_quotes

def get_quotes():
    import urllib2
    from socket import error as SocketError
    import errno

    fi = open('china.txt')
    lines = fi.readlines()
    symbol_dict={}
    for mar, idx in Markets.iteritems():
        for k, v in gen_symbols(lines, mar,idx):
            symbol_dict[k] = v
    quotes=[]
    symbols = []
    #symbol e.g.: u'603099.ss',u'002281.sz'
    
    for symbol in symbol_dict.keys():
        try:
            q = finance.quotes_historical_yahoo(symbol, d1, d2, asobject=True)
            #q.readlines(), return format: Date,Open,High,Low,Close,Volume,Adj Close
        except Exception, e:
            print symbol, e
            symbol_dict.pop(symbol)
        if None != q:
            quotes.append(q)
            symbols.append(symbol)
开发者ID:freephys,项目名称:mylab,代码行数:25,代码来源:fetchdata.py


示例4: __init__

    def __init__(self, ticker):
        gtk.VBox.__init__(self)

        startdate = datetime.date(2001, 1, 1)
        today = enddate = datetime.date.today()

        date1 = datetime.date(2011, 1, 1)
        date2 = datetime.date.today()

        mondays = WeekdayLocator(MONDAY)  # major ticks on the mondays
        alldays = DayLocator()  # minor ticks on the days
        weekFormatter = DateFormatter("%b %d")  # Eg, Jan 12
        dayFormatter = DateFormatter("%d")  # Eg, 12

        quotes = quotes_historical_yahoo(ticker, date1, date2)
        if len(quotes) == 0:
            raise SystemExit

        fig = Figure(facecolor="white", figsize=(5, 4), dpi=100)
        fig.subplots_adjust(bottom=0.2)
        ax = fig.add_subplot(111)
        ax.xaxis.set_major_locator(mondays)
        ax.xaxis.set_minor_locator(alldays)
        ax.xaxis.set_major_formatter(weekFormatter)
        candlestick(ax, quotes, width=0.6)

        ax.xaxis_date()
        ax.autoscale_view()
        pylab.setp(pylab.gca().get_xticklabels(), rotation=45, horizontalalignment="right")

        canvas = FigureCanvas(fig)  # a gtk.DrawingArea
        self.pack_start(canvas)
        toolbar = NavigationToolbar(canvas, win)
        self.pack_start(toolbar, False, False)
开发者ID:nicolasmarti,项目名称:misc-dev-2,代码行数:34,代码来源:yhstckcancas.py


示例5: get_close

def get_close(ticker):
   today = date.today()
   start = (today.year - 1, today.month, today.day)

   quotes = quotes_historical_yahoo(ticker, start, today)

   return numpy.array([q[4] for q in quotes])
开发者ID:hellios78,项目名称:numpy-cookbook-code-sample,代码行数:7,代码来源:masked_funcs.py


示例6: candlestickExample

def candlestickExample():
    # (Year, month, day) tuples suffice as args for quotes_historical_yahoo
    date1 = ( 2004, 2, 1)
    date2 = ( 2004, 4, 12 )
    
    
    mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
    alldays    = DayLocator()              # minor ticks on the days
    weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
    dayFormatter = DateFormatter('%d')      # e.g., 12
    
    quotes = quotes_historical_yahoo('INTC', date1, date2)
    if len(quotes) == 0:
        raise SystemExit
    
    fig, ax = plt.subplots()
    fig.subplots_adjust(bottom=0.2)
    ax.xaxis.set_major_locator(mondays)
    ax.xaxis.set_minor_locator(alldays)
    ax.xaxis.set_major_formatter(weekFormatter)
    #ax.xaxis.set_minor_formatter(dayFormatter)
    
    #plot_day_summary(ax, quotes, ticksize=3)
    candlestick(ax, quotes, width=0.6)
    
    ax.xaxis_date()
    ax.autoscale_view()
    plt.setp( plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
    
    print quotes
    plt.show()
开发者ID:justinoliver51,项目名称:WebExtensions,代码行数:31,代码来源:GraphExample.py


示例7: initialize1

    def initialize1( self,stockTicker, date1, date2, interval, resolution, dataFeedType):

        self.stockTicker = stockTicker;
        if(dataFeedType =="yahoo"):
            self.quotes = quotes_historical_yahoo(self.stockTicker, date1, date2)
            self.N          = self.quotes.__len__();
            self.vDateInt   = zeros(self.N)
            self.vDate      = empty(self.N, dtype=object);
            self.vOpen      = zeros(self.N)
            self.vClose     = zeros(self.N)
            self.vHigh      = zeros(self.N)
            self.vLow       = zeros(self.N)
            self.vVolume    = zeros(self.N)

            index = 0;
            for line in self.quotes:
                self.vDateInt[index]= line [0];
                self.vDate[index]   = date.fromordinal( int( line [0] ) )
                self.vOpen[index]   = line [1];
                self.vClose[index]  = line [2];
                self.vHigh[index]   = line [3];
                self.vLow[index]    = line [4];
                self.vVolume[index] = line [5];
                index =  index +1;
        elif (dataFeedType == "google"):
            self.vDateInt, self.vOpen, self.vHigh, self.vLow, self.vClose, self.vVolume = quotes_historical_google.getData(symbol=self.stockTicker, startDate=date1, endDate=date2, resolution=resolution);
            self.N = size(self.vDateInt);
            self.vDate      = empty(self.N, dtype=object);
            index = 0;
            for d in self.vDateInt:
                self.vDate[index] = date.fromordinal( int( d) );
                index = index + 1;
开发者ID:547872495,项目名称:finance-py,代码行数:32,代码来源:historical_data_obj.py


示例8: test

    def test(self):
        
        #1. Get close prices.
        today = datetime.date.today()
        start = (today.year - 1, today.month, today.day)

        quotes = quotes_historical_yahoo('AAPL', start, today)
        close =  numpy.array([q[4] for q in quotes])

        #2. Get positive log returns.
        logreturns = numpy.diff(numpy.log(close))
        pos = logreturns[logreturns > 0]

        #3. Get frequencies of returns.
        counts, values = numpy.histogram(pos,bins=5)
        values = values[:-1] + (values[1] - values[0])/2
        freqs = 1.0/counts
        freqs =  numpy.log(freqs)

        #4. Fit the frequencies and returns to a line.
        p = numpy.polyfit(values,freqs, 1)

        #5. Plot the results.
        matplotlib.pyplot.plot(values, freqs, 'o')
        matplotlib.pyplot.plot(values, p[0] * values + p[1])
开发者ID:wrightm,项目名称:NumpyCookbook,代码行数:25,代码来源:test_power_law.py


示例9: plot_opening_closing_prices

 def plot_opening_closing_prices(self):
     if len(self.ticker_symbol_input_line.text()) == 0 or len(self.start_date_input_line.text()) == 0 or len(self.end_date_input_line.text()) == 0:
         return
     start_date = date(*[int(x) for x in self.start_date_input_line.text().split('-')])
     end_date = date(*[int(x) for x in self.end_date_input_line.text().split('-')])
     quotes = quotes_historical_yahoo(str(self.ticker_symbol_input_line.text()), start_date, end_date)
     if len(quotes) == 0:
         return
     dates, opening_prices, closing_prices = zip(*[[q[0], q[1], q[2]] for q in quotes])
     self.axes.cla()
     self.axes.grid(b=True, which='both')
     self.axes.set_title('Historical Opening/Closing Prices')
     self.axes.set_xlabel('Date')
     self.axes.set_ylabel('Price')
     opening_plot, = self.axes.plot_date(dates, opening_prices, 'b-')
     closing_plot, = self.axes.plot_date(dates, closing_prices, 'r-')
     self.axes.legend([opening_plot, closing_plot], ['Opening Price', 'Closing Price'], title='Ticker Symbol: ' + str(self.ticker_symbol_input_line.text()).upper(), loc=2)
     years = YearLocator()
     years_format = DateFormatter('%Y')
     months = MonthLocator()
     self.axes.xaxis.set_major_locator(years)
     self.axes.xaxis.set_major_formatter(years_format)
     self.axes.xaxis.set_minor_locator(months)
     self.axes.autoscale_view()
     self.figure.autofmt_xdate()
     self.axes.fmt_xdata = DateFormatter('%Y-%m-%d')
     self.axes.fmt_ydata = lambda x: '$%1.2f' % x
     self.canvas.draw()
开发者ID:djjcast,项目名称:pyqt4-examples,代码行数:28,代码来源:6_stock_data.py


示例10: test

    def test(self):
        # 2011 to 2012
        start = datetime.datetime(2011, 01, 01)
        end = datetime.datetime(2012, 01, 01)

        symbols = ["AA", "AXP", "BA", "BAC", "CAT"]

        quotes = [finance.quotes_historical_yahoo(symbol, start, end, asobject=True)
                  for symbol in symbols]

        close = numpy.array([q.close for q in quotes]).astype(numpy.float)
        dates = numpy.array([q.date for q in quotes])

        data = {}

        for i in xrange(len(symbols)):
            data[symbols[i]] = numpy.diff(numpy.log(close[i]))

        df = pandas.DataFrame(data, index=dates[0][:-1], columns=symbols)
 
        print df
        print df.corr()
        df.plot()
        legend(symbols)
        show()
开发者ID:wrightm,项目名称:NumpyCookbook,代码行数:25,代码来源:test_correlation.py


示例11: get_data

def get_data(id, start, end):
    try:
        res = quotes_historical_yahoo(id, start, end)
    except urllib2.HTTPError:
        return None
    else:
        return res
开发者ID:lynic,项目名称:stock,代码行数:7,代码来源:usstock.py


示例12: stock_monthly_returns

def stock_monthly_returns():
    """create a plot of the monthly returns for a stock
    Arguments
    =========
    None

    Prompts the user for a stock ticker

    Returns
    ======
    None

    Saves plot to 'TICKER_monthly_returns.pdf'
    """
    # start your code here
    stock = raw_input('Input a stock ticker: ')
    now = datetime.datetime.now()
    sp = finance.quotes_historical_yahoo(stock, (1900, 1, 1), (now.year, now.month, now.day), asobject=True, adjusted=False)
    graphDate = sp.date[30:]
    graphPrice = [0] * (len(sp.date) - 30)
    for idx, val in enumerate(graphPrice):
        graphPrice[idx] = (sp.close[idx + 30] - sp.close[idx]) / sp.close[idx]
    plt.plot(graphDate, graphPrice)
    plt.xlabel('Dates')
    plt.ylabel('Returns')
    plt.title('Monthy return for stock ' + stock)
    plt.savefig(stock + '_monthly_returns.pdf')
    return None
开发者ID:khjtony,项目名称:Proj_Python,代码行数:28,代码来源:lab_4.py


示例13: calc_stats

def calc_stats(ticker):
    """calculates basic statistical quantites for the daily returns
    of the stock with ticker

    Arguments
    =========
    ticker: string containg the ticker

    Returns
    ======
    None

    Saves statistical quantities to 'TICKER_daily_returns_stats.txt'
    """
    # start your code here5
    now = datetime.datetime.now()
    sp = finance.quotes_historical_yahoo(ticker, (1900, 1, 1), (now.year, now.month, now.day), asobject=True, adjusted=False)
    returns = np.array([(sp.open[i+1] - sp.open[i]) / sp.open[i] for i in range(len(sp.open) - 1)])
    mean = np.mean(returns)
    median = np.median(returns)
    std = np.std(returns)
    skewness = stats.skew(returns)
    kurtosis = stats.kurtosis(returns)
    resultStr = "Statistical Properties of Daily Returns For: {0}\nMean = {1} Median = {2} Standard Deviation = {3} Skewness = {4} Kurtosis = {5}".format(*(ticker, mean, median, std, skewness, kurtosis))
    result = open(ticker + "_daily_returns_stats.txt", 'w')
    result.write(resultStr)
    return None
开发者ID:khjtony,项目名称:Proj_Python,代码行数:27,代码来源:lab_5.py


示例14: sample

def sample():
    ###############################################################################
    # Downloading the data
    date1 = datetime.date(2012, 1, 1)  # start date
    date2 = datetime.date(2012, 12, 1)  # end date
    # get quotes from yahoo finance
    quotes = quotes_historical_yahoo("INTC", date1, date2)
    if len(quotes) == 0:
        raise SystemExit

    # unpack quotes
    dates = np.array([q[0] for q in quotes], dtype=int)
    close_v = np.array([q[2] for q in quotes])
    # volume = np.array([q[5] for q in quotes])[1:]

    # take diff of close value
    # this makes len(diff) = len(close_t) - 1
    # therefore, others quantity also need to be shifted
    diff = 100 * (np.exp(np.log(close_v[1:]) - np.log(close_v[:-1])) - 1)
    dates = dates[1:]
    close_v = close_v[1:]
    print diff
    # pack diff and volume for training
    # X = np.column_stack([diff, volume])
    X = np.column_stack([diff])
    return X, dates, close_v
开发者ID:xingzhong,项目名称:grammar_learning,代码行数:26,代码来源:hmm.py


示例15: main

def main():

  win = gtk.Window()
  win.connect('destroy', gtk.main_quit)
  win.set_title('Cursors')

  vbox = gtk.VBox()
  win.add(vbox)

  # Get data from Yahoo Finance
  enddate = datetime.date.today()
  startdate = enddate + datetime.timedelta(days=-72)
  quotes = finance.quotes_historical_yahoo('GOOG', startdate, enddate)

  qa = array(quotes)
 
  f = create_figure(quotes)
  a = f.gca()
  vbox.pack_start(gtk.Label('No Blit'), False, False)
  vbox.pack_start(f.canvas)

  cursor1 = SnaptoCursor(a, qa[:,0], qa[:,2], useblit=False)
  f.canvas.mpl_connect('motion_notify_event', cursor1.mouse_move)
  
  f = create_figure(quotes)
  a = f.gca()
  vbox.pack_start(gtk.Label('Use Blit'), False, False)
  vbox.pack_start(f.canvas)

  cursor2 = SnaptoCursor(a, qa[:,0], qa[:,2], useblit=True)
  f.canvas.mpl_connect('motion_notify_event', cursor2.mouse_move)
  
  win.show_all()
  gtk.main()
开发者ID:JamesValero,项目名称:yjl,代码行数:34,代码来源:matplotlib_cursor.py


示例16: getQuotes

def getQuotes(symbol, start, end):
    quotes = fin.quotes_historical_yahoo(symbol, start, end)
    dates, open, close, high, low, volume = zip(*quotes)

    data = {"open": open, "close": close, "high": high, "low": low, "volume": volume}

    dates = Index([datetime.fromordinal(int(d)) for d in dates])
    return DataFrame(data, index=dates)
开发者ID:jasonzhang4628,项目名称:StockAnalysis,代码行数:8,代码来源:finance.py


示例17: download_data

def download_data(symbol, days_delta=60):
    finish_date = datetime.today()
    start_date = finish_date - timedelta(days=days_delta)

    stocks_raw = quotes_historical_yahoo(symbol, start_date, finish_date)
    stocks_df = pd.DataFrame(stocks_raw, columns=["n_date", "open", "close",
                                                  "high", "low", "volume"])
    return stocks_df
开发者ID:RaulS11,项目名称:Clusters,代码行数:8,代码来源:OPIIF_Clusters.py


示例18: get_close

def get_close(symbol):
   today = date.today()
   start = (today.year - 1, today.month, today.day)

   quotes = quotes_historical_yahoo(symbol, start, today)
   quotes = numpy.array(quotes)

   return quotes.T[4]
开发者ID:xenron,项目名称:sandbox-da-python,代码行数:8,代码来源:pair.py


示例19: download_data

def download_data(symbol, finish_date, start_date):

    stocks_raw = quotes_historical_yahoo(symbol, start_date, finish_date)
    stocks_df  = pd.DataFrame(stocks_raw, columns=["TimeStamp", "Open", "Close",
                                                  "High", "Low", "Volume"])
    stocks_df["TimeStamp"] = stocks_df["TimeStamp"].astype(np.int32)
    stocks_df["TimeStamp"] = stocks_df["TimeStamp"].apply(datetime.fromordinal)
    return stocks_df
开发者ID:ITESOIF,项目名称:OPIIF-P16,代码行数:8,代码来源:OPIIF_CLAMW_Ind.py


示例20: gpcs_trade

def gpcs_trade(series, trade):
    """Function to plot a candle graph from a given series"""
    
    """takes as input the security code, default TY"""
    from matplotlib.dates import  DateFormatter, WeekdayLocator, HourLocator, \
         DayLocator, MONDAY
    from matplotlib.finance import quotes_historical_yahoo, candlestick,\
         plot_day_summary, candlestick2
    
    
    mondays = WeekdayLocator(MONDAY)  # major ticks on the mondays
    
    alldays    = DayLocator()              # minor ticks on the days
    monthFormatter = DateFormatter('%b %d')  # Eg, Jan 12
    dayFormatter = DateFormatter('%d')      # Eg, 12


    #quotes contains a list of tuples:
    #(date, open, close, high, low, volume)
    quotes = series
    if len(quotes) == 0:
        today = datetime.datetime.now()
        
        date2 = (today.year, today.month, today.day)
        date1 = ( today.year -1, today.month, 1)
        quotes = quotes_historical_yahoo('fut_code', date1, date2)
    if len(quotes) == 0:
        raise SystemExit

    fig = figure()
    fig.subplots_adjust(bottom=0.2)
    ax = fig.add_subplot(111)
    #ax.xaxis.set_major_locator(mondays)
    #ax.xaxis.set_minor_locator(mondays)
    #ax.xaxis.set_major_formatter(monthFormatter)
    #ax.xaxis.set_minor_formatter(dayFormatter)

    #plot_day_summary(ax, quotes, ticksize=3)
    dt, o, c, h, l, v = zip(*quotes)
    dt2 = []
    for d in dt:
        dt2.append(datetime.datetime.fromordinal(int(d)))
    ser = DataFrame(data = {0:o, 1:c, 2:h, 3:l, 4:v}, index = dt2)
    tmdelta = len(ser[trade.trend.a:])
    ax.plot([trade.trend.a, max(ser.index)], [trade.trend.c_reg, (tmdelta*trade.trend.m_reg + trade.trend.c_reg)], color='r', linestyle='-', linewidth=2)
    ax.plot([trade.trend.a, max(ser.index)], [trade.trend.c_reg+trade.trend.stdev_p_reg, (trade.trend.stdev_p_reg +tmdelta*trade.trend.m_reg + trade.trend.c_reg)], color='g', linestyle='-', linewidth=2)
    ax.plot([trade.trend.a, max(ser.index)], [trade.trend.c_reg-trade.trend.stdev_p_reg, (-trade.trend.stdev_p_reg +tmdelta*trade.trend.m_reg + trade.trend.c_reg)], color='g', linestyle='-', linewidth=2)
    tmdelta = len(ser[trade.trend.a:trade.trend.e])
    ax.plot([trade.trend.a, trade.trend.e], [trade.trend.c_reg, (tmdelta*trade.trend.m_reg + trade.trend.c_reg)], color='b', linestyle='-', linewidth=2)
    
    candlestick(ax, quotes, width=0.6)

    #ax.xaxis_date()
    ax.autoscale_view()
    setp( gca().get_xticklabels(), rotation=45, horizontalalignment='right')

    show()
开发者ID:richardpeter3,项目名称:robo_pleb,代码行数:57,代码来源:gpc.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python finance.quotes_historical_yahoo_ochl函数代码示例发布时间:2022-05-27
下一篇:
Python finance.fetch_historical_yahoo函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap