本文整理汇总了Python中matplotlib.finance.quotes_historical_yahoo_ochl函数的典型用法代码示例。如果您正苦于以下问题:Python quotes_historical_yahoo_ochl函数的具体用法?Python quotes_historical_yahoo_ochl怎么用?Python quotes_historical_yahoo_ochl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quotes_historical_yahoo_ochl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stock_month_plot
def stock_month_plot():
'''
Show how to make date plots in matplotlib using date tick locators and formatters.
'''
date1 = datetime.date(2002, 1, 5)
date2 = datetime.date(2003, 12, 1)
# every monday
mondays = WeekdayLocator(MONDAY)
# every 3rd month
months = MonthLocator(range(1, 13), bymonthday=1, interval=3)
monthsFmt = DateFormatter("%b '%y")
quotes = quotes_historical_yahoo_ochl('INTC', date1, date2)
if len(quotes) == 0:
print('Found no quotes')
raise SystemExit
dates = [q[0] for q in quotes]
opens = [q[1] for q in quotes]
fig, ax = plt.subplots()
ax.plot_date(dates, opens, '-')
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(monthsFmt)
ax.xaxis.set_minor_locator(mondays)
ax.autoscale_view()
#ax.xaxis.grid(False, 'major')
#ax.xaxis.grid(True, 'minor')
ax.grid(True)
fig.autofmt_xdate()
plt.show()
示例2: stock_year_plot
def stock_year_plot():
'''
Show how to make date plots in matplotlib using date tick locators and formatters.
'''
date1 = datetime.date(1995, 1, 1)
date2 = datetime.date(2004, 4, 12)
years = YearLocator() # every year
months = MonthLocator() # every month
yearsFmt = DateFormatter('%Y')
quotes = quotes_historical_yahoo_ochl('INTC', date1, date2)
if len(quotes) == 0:
print('Found no quotes')
raise SystemExit
dates = [q[0] for q in quotes]
opens = [q[1] for q in quotes]
fig, ax = plt.subplots()
ax.plot_date(dates, opens, '-')
# format the ticks
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
ax.xaxis.set_minor_locator(months)
ax.autoscale_view()
# format the coords message box
def price(x):
return '$%1.2f' % x
ax.fmt_xdata = DateFormatter('%Y-%m-%d')
ax.fmt_ydata = price
ax.grid(True)
fig.autofmt_xdate()
plt.show()
示例3: symbolsToPriceDict
def symbolsToPriceDict(symbols,startDate,endDate):
"""
From a list of stock symbols and a range of dates, returns a prices by symbols numpy array
listing the opening prices for the stocks in the given date range.
"""
#add check to account for missing values in data
quotes = [list(finance.quotes_historical_yahoo_ochl(symbol, startDate, endDate,asobject = True).open) for symbol in symbols]
return dict(zip(symbols,quotes))
示例4: symbolsToPrices
def symbolsToPrices(symbols,startDate,endDate):
"""
From a list of stock symbols and a range of dates, returns a prices by symbols numpy array
listing the opening prices for the stocks in the given date range.
"""
#add check to account for missing values in data
quotes = [finance.quotes_historical_yahoo_ochl(symbol, startDate, endDate,asobject = True).open for symbol in symbols]
print "prices shape:"
print np.array(quotes).T.shape
return np.array(quotes).T
示例5: main
def main(symbols, percent, days, verbose):
if verbose:
print "Symbols: %s" % symbols
print "Percent: %s" % percent
print "Days: %d" % days
print "Verbose: %s" % verbose
print
if days > 0:
days = -days
print "Checking for a %s%% decline over the past " \
"%d days" % (percent, abs(days))
print
for ticker in symbols:
ticker = ticker.upper()
print "Stock: %s" % ticker
start_date = datetime.datetime.now() + datetime.timedelta(days)
end_date = datetime.datetime.now()
quotes_objects = quotes_historical_yahoo_ochl(ticker,
start_date,
end_date,
asobject=True)
max_value = round(float(max(quotes_objects.close)), 5)
print "- max value over %d days: %s" % (abs(days), max_value)
most_recent_close = round(float(quotes_objects.close[-1]), 5)
print "- most recent close: %s" % most_recent_close
percent_change = round(float(
rate_of_return(max_value, most_recent_close)
), 2)
print "- percent change: %s%%" % percent_change
target_price = max_value - (max_value * (percent / 100.0))
print "- target price: %s (%s%% below %s)" % (target_price, percent,
max_value)
if percent_change < -percent:
print
print "ALERT! %s has dropped %s%% " \
"over the last %s days" % (ticker,
percent_change,
abs(days))
print
示例6: symbols
def symbols(stock_symbol):
today = date.today()
start = (today.year , today.month, today.day - 1) # Here we have a bug. If report running on weekend, you will get error because we only minus one day which possible is NOT value market date.
quotes = quotes_historical_yahoo_ochl(stock_symbol, start, today)
df = pd.DataFrame(quotes)
df.columns = [u'Date', u'Open',u'Close',u'High',u'Low',u'Volume']
#####
#df.to_csv('stock_%s.csv' %stock_symbol)
#test = pd.read_csv('stock_FTNT.csv')
#print "TEST \n "
#print test
#####
sum = 0
for i in xrange(df.shape[0]):
#print "%.2f + %.2f = %.2f" %(sum,df['Close'][i],sum+df['Close'][i])
sum += df['Close'][i]
return (sum/df.shape[0])
示例7: PlotData
def PlotData(code, start, end, list):
start_date = _wxdate2pydate(start)
end_date = _wxdate2pydate(end)
print code
print start_date
print end_date
quotes = quotes_historical_yahoo_ochl(code, start_date, end_date)
fields = ['date', 'open', 'close', 'high', 'low', 'volume']
list1 = []
for i in range(0, len(quotes)):
x = date.fromordinal(int(quotes[i][0]))
y = datetime.strftime(x, '%Y-%m-%d')
list1.append(y)
print list1
quotesdf = pd.DataFrame(quotes, index=list1, columns=fields)
quotesdf = quotesdf.drop(['date'], axis=1)
quotesdftemp = pd.DataFrame()
print quotesdftemp
for i in range(0, len(list)):
quotesdftemp[list[i]] = quotesdf[list[i]]
print "ready to plot"
quotesdftemp.plot(marker='o')
示例8: quotes_historical_yahoo_ochl
"""
数据的简单处理与筛选
"""
from matplotlib.finance import quotes_historical_yahoo_ochl # 注matplotlib包里已经没有了quotes_historical_yahoo方法了,改为quotes_historical_yahoo_ochl
from datetime import date
from datetime import datetime
import pandas as pd
import numpy as np
import time
today = date.today()
start = (today.year - 5, today.month, today.day)
quotes = quotes_historical_yahoo_ochl('AXP', start, today) #美国运通公司最近一年股票代码
fields = ['date', 'open', 'close', 'high', 'low', 'volume']
list1 = []
for i in range(0,len(quotes)):
x = date.fromordinal(int(quotes[i][0]))
y = datetime.strftime(x, "%Y-%m-%d")
list1.append(y)
qutoesdf = pd.DataFrame(quotes, index=list1, columns=fields) # 利用index属性可以将索引改变。 日期为格里高利时间,用函数改变
qutoesdf = qutoesdf.drop(['date'], axis = 1)
# print qutoesdf
#求平均值
print qutoesdf.mean(columns='close')
#求开盘价大于80的成交量
示例9: print
import datetime
import numpy as np
import pylab as pl
from matplotlib.finance import quotes_historical_yahoo_ochl
from matplotlib.dates import YearLocator, MonthLocator, DateFormatter
from hmmlearn.hmm import GaussianHMM
print(__doc__)
###############################################################################
# Downloading the data
date1 = datetime.date(1995, 1, 1) # start date
date2 = datetime.date(2012, 1, 6) # end date
# get quotes from yahoo finance
quotes = quotes_historical_yahoo_ochl("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 = close_v[1:] - close_v[:-1]
dates = dates[1:]
close_v = close_v[1:]
示例10: print
symbols_all, names_all = stock_list.Symbol.values, stock_list.Name.values
print symbols_all
print(type(symbols_all))
# print 'this are the symbols'
# print symbols
# print 'this are the names'
# print names
ticker_index = 1
for symbol in symbols_all:
# print 'starting...', ticker_index
quotes = [finance.quotes_historical_yahoo_ochl(symbol, d1, d2, asobject=True)]
# print 'working...', ticker_index
# ticker_index = ticker_index + 1
# quotes = [finance.quotes_historical_yahoo_ochl(symbol, d1, d2, asobject = True) for symbol in symbols_all]
# print quotes
open = np.array([q.open for q in quotes]).astype(np.float)
# print open
close = np.array([q.close for q in quotes]).astype(np.float)
# print close
variation = close - open
# print variation
示例11: datetime
import time
from matplotlib.finance import quotes_historical_yahoo_ochl
from datetime import date
from datetime import datetime
import pandas as pd
import matplotlib.pyplot as plt
import pylab as pl
import numpy as np
start = datetime(2014, 1, 1)
end = datetime(2014, 12, 31)
quotesMS14 = quotes_historical_yahoo_ochl("MSFT", start, end)
fields = ["date", "open", "close", "high", "low", "volume"]
list1 = []
for i in range(0, len(quotesMS14)):
x = date.fromordinal(int(quotesMS14[i][0]))
y = datetime.strftime(x, "%Y-%m-%d")
list1.append(y)
# print list1
quotesdfMS14 = pd.DataFrame(quotesMS14, index=list1, columns=fields)
# print quotesMS14
listtemp1 = []
for i in range(0, len(quotesdfMS14)):
temp = time.strptime(quotesdfMS14.index[i], "%Y-%m-%d")
listtemp1.append(temp.tm_mon)
# print listtemp1
quotesdfMS14["month"] = listtemp1
# print quotesdfMS14
# closemaxINTC = quotesdfMS14.groupby('month').max().close
openMS = quotesdfMS14.groupby("month").mean().open
listopen = []
示例12: open
from matplotlib.finance import quotes_historical_yahoo_ochl
# retrieve symbol lists
markets = ['amex','nasdaq','nyse','otcbb']
symbols = []
for m in markets:
fname = 'symbols-' + m + '-unique.txt'
with open(fname, 'r') as f:
symbols += f.read().splitlines()
print len(symbols), 'symbols listed'
exit
# set date range
date1 = date(1984, 1, 1)
date2 = date(2014, 12, 31)
# date2 = date.today()
# date1 = date2 - timedelta(days=14)
# retrieve all data
for symbol in symbols:
try:
data = quotes_historical_yahoo_ochl(symbol, date1, date2)
if None != data and len(data) > 0:
print symbol, len(data)
with open('csv/' + symbol + '.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(data)
except:
True
示例13: DayLocator
from matplotlib.dates import MonthLocator
from matplotlib.finance import quotes_historical_yahoo_ochl
from matplotlib.finance import candlestick_ochl
import sys
from datetime import date
today = date.today()
start = (today.year - 1, today.month, today.day)
alldays = DayLocator()
months = MonthLocator()
month_formatter = DateFormatter("%b %Y")
# 从财经频道下载股价数据
symbol = 'BIDU' # 百度的股票代码
quotes = quotes_historical_yahoo_ochl(symbol, start, today)
# 创建figure对象,这是绘图组件的顶层容器
fig = plt.figure()
# 增加一个子图
ax = fig.add_subplot(111)
# x轴上的主定位器设置为月定位器,该定位器负责x轴上较粗的刻度
ax.xaxis.set_major_locator(months)
# x轴上的次定位器设置为日定位器,该定位器负责x轴上较细的刻度
ax.xaxis.set_minor_locator(alldays)
# x轴上的主格式化器设置为月格式化器,该格式化器负责x轴上较粗刻度的标签
ax.xaxis.set_major_formatter(month_formatter)
# 使用matplotlib.finance包的candlestick函数绘制k线图
candlestick_ochl(ax, quotes)
# 将x轴上的标签格式化为日期
示例14: timedelta
"""
get google's stock exchange data using matplotlib
"""
from matplotlib.finance import quotes_historical_yahoo_ochl
from datetime import date, datetime, timedelta
import pandas as pd
today = date.today()
start = today - timedelta(days=365)
quotes = quotes_historical_yahoo_ochl("GOOG", start, today)
fields = ["date", "open", "close", "high", "low", "volume"]
# convert date format
dates = []
for i in range(0, len(quotes)):
x = date.fromordinal(int(quotes[i][0]))
y = datetime.strftime(x, "%Y-%m-%d")
dates.append(y)
# set dates to index
quotesdf = pd.DataFrame(quotes, index=dates, columns=fields)
quotesdf = quotesdf.drop(["date"], axis=1)
# print
# print quotesdf
# print quotesdf[u'2014-12-02' : u'2014-12-09']
# print quotesdf.loc[1:5, ] # [row, col]
# print quotesdf.loc[:, ['low', 'volume']]
print quotesdf[(quotesdf.index >= u"2015-01-30") & (quotesdf.close > 600)]
# group (example)
# g = tempdf.groupby('month')
# gvolume = g['volume']
# print gvolume.sum()
示例15: quotes_historical_yahoo_ochl
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
from matplotlib.finance import quotes_historical_yahoo_ochl
from datetime import date
from datetime import datetime
import pandas as pd
import matplotlib.pyplot as plt
__author__ = 'wangjj'
__mtime__ = '20161022下午 11:39'
today = date.today()
start = (today.year - 1, today.month, today.day)
quotes = quotes_historical_yahoo_ochl('KO', start, today)
fields = ['date', 'open', 'close', 'high', 'low', 'volume']
list1 = []
for i in range(0, len(quotes)):
x = date.fromordinal(int(quotes[i][0]))
y = datetime.strftime(x, '%Y-%m-%d')
list1.append(y)
# print(list1)
quoteskodf = pd.DataFrame(quotes, index=list1, columns=fields)
quoteskodf = quoteskodf.drop(['date'], axis=1)
# print(quotesdf)
listtemp = []
for i in range(0, len(quoteskodf)):
temp = time.strptime(quoteskodf.index[i], "%Y-%m-%d")
listtemp.append(temp.tm_mon)
print(listtemp) # “print listtemp” in Python 2.x
tempkodf = quoteskodf.copy()
tempkodf['month'] = listtemp
closeMeansKO = tempkodf.groupby('month').mean().close