本文整理汇总了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函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:JoshuaMichaelKing,项目名称:MyLearning,代码行数:32,代码来源:plot_demos.py
示例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()
开发者ID:JoshuaMichaelKing,项目名称:MyLearning,代码行数:34,代码来源:plot_demos.py
示例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))
开发者ID:ericwayman,项目名称:SparseIndex,代码行数:8,代码来源:createReturnDatabase.py
示例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
开发者ID:ericwayman,项目名称:SparseIndex,代码行数:10,代码来源:sparseIndex.py
示例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
开发者ID:bruceljyang,项目名称:stock-price-decline-checker,代码行数:52,代码来源:stock-price-decline-checker.py
示例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])
开发者ID:soyolee,项目名称:someLer,代码行数:19,代码来源:traffic_light.py
示例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')
开发者ID:ilikesongdandan,项目名称:python-data,代码行数:24,代码来源:quotespd.py
示例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的成交量
开发者ID:2015E8007361074,项目名称:load2python,代码行数:29,代码来源:4.1-5.py
示例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:]
开发者ID:rickyk9487,项目名称:hmmlearn,代码行数:30,代码来源:plot_hmm_stock_analysis.py
示例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
开发者ID:bsuhagia,项目名称:ML-4641-Project,代码行数:30,代码来源:clustering.py
示例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 = []
开发者ID:Yifan-DU,项目名称:Python,代码行数:31,代码来源:exam.py
示例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
开发者ID:Yasboti,项目名称:Stocker,代码行数:30,代码来源:acquire.py
示例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轴上的标签格式化为日期
开发者ID:AlexGKing,项目名称:pyDataScienceToolkits_Base,代码行数:31,代码来源:baidu_stock_price.py
示例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()
开发者ID:Yifan-DU,项目名称:Python,代码行数:30,代码来源:data_analysis_google_2.py
示例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
开发者ID:ilikesongdandan,项目名称:python-data,代码行数:31,代码来源:closeMeansKo.py
示例16: print
'AMZN': 'Amazon',
'KO': 'Coca Cola',
'PEP': 'Pepsi',
'MCD': 'Mc Donalds',
'YUM': 'Taco Bell',
'CMG': 'Chipotle Mexican Grill',
'WMT': 'Wal-Mart',
'HD': 'Home Depot',
'CVS': 'CVS'
}
symbols, names = np.array(list(symbol_dict.items())).T
print('_'*140 + "\n>>> quotes:")
for symbol in symbols:
try:
quote = finance.quotes_historical_yahoo_ochl(symbol, d1, d2, asobject=True)
print("\n%s %s:\n%s" % (symbol, symbol_dict[symbol], quote))
except Exception as e:
# this is usually a 404 error, coz of the date range (ie a stock may not have existed),
# so we could enter a zeroed entry ???
print('_'*140 + "\n")
cls1 = datetime.datetime(2009, 1, 1)
cls2 = datetime.datetime(2015, 1, 1)
symbol = 'YUM' # Taco Bell
# symbol = 'CMG' # Chipotle Mexican Grill
quote = finance.quotes_historical_yahoo_ochl(symbol, cls1, cls2, asobject=True)
print("\n%s %s\ntype(quote)=%s=\nquote:\n%s" % (symbol, symbol_dict[symbol], type(quote), quote))
# quotes = [finance.quotes_historical_yahoo(symbol, d1, d2, asobject=True) for symbol in symbols]
开发者ID:cmohit21,项目名称:Support-Vector-Machines---Basics-and-Fundamental-Investing-Project,代码行数:31,代码来源:plot_stock_market.py
示例17: YearLocator
This example requires an active internet connection since it uses
yahoo finance to get the data for plotting
"""
import matplotlib.pyplot as plt
from matplotlib.finance import quotes_historical_yahoo_ochl
from matplotlib.dates import YearLocator, MonthLocator, DateFormatter
import datetime
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:
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()
开发者ID:AudiencePropensities,项目名称:matplotlib,代码行数:31,代码来源:date_demo1.py
示例18:
"601668": "中国建筑",
"601688": "华泰证券",
"601766": "中国中车",
"601800": "中国交建",
"601818": "光大银行",
"601857": "中国石油",
"601901": "方正证券",
"601988": "中国银行",
"601989": "中国重工",
"601998": "中信银行"}
symbols, names = np.array(list(symbol_dict.items())).T
#quotes = [ts.get_hist_data(symbol,start=d1,end=d2) for symbol in symbols]
## 一次最多30个 然后需要等待了
quotes = [pd.DataFrame(quotes_historical_yahoo_ochl(symbol+".ss", d1, d2),columns=['date','open','high','low','close','volume'])
for symbol in symbols]
for symbol in symbols:
quotes.append(pd.DataFrame(quotes_historical_yahoo_ochl(symbol+".ss", d1, d2),columns=['date','open','high','low','close','volume']))
open_price = np.array([q.open.values for q in quotes])
close_price = np.array([q.close.values for q in quotes])
# 每日价格浮动包含了重要信息!
variation = close_price - open_price
###############################################################################
# Learn a graphical structure from the correlations
edge_model = covariance.GraphLassoCV()
开发者ID:xiaofeima1990,项目名称:Project,代码行数:30,代码来源:cluster_ana.py
示例19: range
'MMM',
'MRK',
'MSFT',
'NKE',
'PFE',
'PG',
'T',
'TRV',
'UNH',
'UTX',
'V',
'VZ',
'WMT',
'XOM']
quotes = [[0 for col in range(90)] for row in range(30)]
listTemp = [[0 for col in range(90)] for row in range(30)]
for i in range(30):
quotes[i] = quotes_historical_yahoo_ochl(listDji[i], start, end)
days = len(quotes[0])
for i in range(30):
for j in range(days - 1):
if (quotes[i][j][2] and quotes[i][j + 1][2]
and (quotes[i][j + 1][2] >= quotes[i][j][2])):
listTemp[i][j] = 1.0
else:
listTemp[i][j] = -1.0
data = vstack(listTemp)
centroids, _ = kmeans(data, 4) # float or double is supported
result, _ = vq(data, centroids)
print(result)
开发者ID:ilikesongdandan,项目名称:python-data,代码行数:30,代码来源:kmeansDJI.py
示例20: 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)
quotesMSFT = quotes_historical_yahoo_ochl("MSFT", start, end)
quotesINTC = quotes_historical_yahoo_ochl("INTC", start, end)
fields = ["date", "open", "close", "high", "low", "volume"]
# quotesdf = pd.DataFrame(quotes, columns = fields)
# quotesdf = pd.DataFrame(quotes, index = range(1,len(quotes)+1),columns = fields)
list1 = []
for i in range(0, len(quotesMSFT)):
x = date.fromordinal(int(quotesMSFT[i][0]))
y = datetime.strftime(x, "%Y-%m-%d")
list1.append(y)
# print list1
list2 = []
for i in range(0, len(quotesINTC)):
x = date.fromordinal(int(quotesINTC[i][0]))
y = datetime.strftime(x, "%Y-%m-%d")
list2.append(y)
quotesmsftdf = pd.DataFrame(quotesMSFT, index=list1, columns=fields)
print "----------------", type(quotesmsftdf["open"])
quotesmsftdf = quotesmsftdf.drop(["date"], axis=1)
开发者ID:kriloc,项目名称:pythonBasic,代码行数:30,代码来源:hipython042Prac.py
注:本文中的matplotlib.finance.quotes_historical_yahoo_ochl函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论