本文整理汇总了Python中yahoo_finance.Share.get_prev_close方法的典型用法代码示例。如果您正苦于以下问题:Python Share.get_prev_close方法的具体用法?Python Share.get_prev_close怎么用?Python Share.get_prev_close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yahoo_finance.Share
的用法示例。
在下文中一共展示了Share.get_prev_close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_stock_info
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def get_stock_info(symbols, moreInfo=False):
"""
Scrape stock info from Yahoo finance
@Param 'moreInfo': False for getting price, True for getting more information
@Return 'message': "symbol: Price-number, Open Price-number, Pre Close Price-number, High Price-number,
Low price-number"
"""
message = ''
for symbol in symbols:
try:
stock = Share(symbol)
price = stock.get_price()
except AttributeError:
price = None
if price == None: # Stock symbol not exists, replace with an alert message
message += '#' + symbol + ': ' + 'The stock symbol does not exit' + '\n'
elif moreInfo:
message += '#%s: Price-%s, Open Price-%s, Pre Close Price-%s, High Price-%s, Low price-%s\n' \
% (symbol, price, stock.get_open(), stock.get_prev_close(), stock.get_days_high(), stock.get_days_low())
else:
message += '#' + symbol + ': ' + price + '\n'
alert_message = 'Please type #1 followed by stock symbols to get more information' if moreInfo == True else \
'Please type #0 followed by stock symbols to get stock price'
return message if message != '' else alert_message
示例2: createInfos
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def createInfos():
if db.infos.count() == 0:
print("Creating Infos!!")
with open('static/sp100.json', 'rb') as f:
ls = json.load(f)
for i in ls:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
symbol = Share(i['name'])
item = {
'name': i['name'],
'price': symbol.get_price(),
'time': timestamp,
'prev_close': symbol.get_prev_close(),
'open': symbol.get_open(),
'volume': symbol.get_volume(),
'pe': symbol.get_price_earnings_ratio(),
'eps': symbol.get_earnings_share(),
'price_sales': symbol.get_price_sales(),
'ebitda': symbol.get_ebitda(),
'hotness': ms.hotness_function(i['name']),
'BS': ms.bs_function(i['name'])}
db.infos.insert_one({
"name": i['name'],
"sector": i['sector'],
"data": [item]
})
print('Collection Infos Created.')
return Response('Collection Infos Created.')
示例3: updateInfos
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def updateInfos():
print("Updating Infos!")
with open('static/sp100.json', 'rb') as f:
ls = json.load(f)
for i in ls:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print (i['name'])
symbol = Share(i['name'])
item = {
'name': i['name'],
'price': symbol.get_price(),
'time': timestamp,
'prev_close': symbol.get_prev_close(),
'open': symbol.get_open(),
'volume': symbol.get_volume(),
'pe': symbol.get_price_earnings_ratio(),
'eps': symbol.get_earnings_share(),
'price_sales': symbol.get_price_sales(),
'ebitda': symbol.get_ebitda(),
'hotness': ms.hotness_function(i['name']),
'BS': ms.bs_function(i['name'])}
db.infos.update(
{"name": i['name']},
{
"$push": {"data": item}
}
)
print('Collection Infos Updated.')
return Response('Collection Infos Updated.')
示例4: fundamentalStats
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def fundamentalStats(stock):
try:
stokOutput = Share(stock)
openPrice = stokOutput.get_open()
closePrice = stokOutput.get_prev_close()
dailyDelta = stokOutput.get_change()
earningsShare = stokOutput.get_earnings_share()
fiddyDay = stokOutput.get_50day_moving_avg()
priceBook = stokOutput.get_price_book()
peeEee = stokOutput.get_price_earnings_ratio()
pegRatio = stokOutput.get_price_earnings_growth_ratio()
if (float(priceBook) < 1.5 and float(peeEee) < 50 and float(pegRatio) < 2 and float(peeEee) > 0):
csvList = [stock, "open price:", openPrice, "previous close:", closePrice, "daily deltas:", dailyDelta, "earnings per share:", earningsShare, "50 day moving avg:", fiddyDay, "price/book:", priceBook, "price/earnings:", peeEee, "peg:", pegRatio, "\n"]
print (stock, "will be imported to Excel.")
stockPicks = open("picks.csv", "a", newline='')
writeCSV = csv.writer(stockPicks, dialect='excel')
for stock in csvList:
writeCSV.writerow([stock])
else:
print (stock, "does not meet criteria.")
except:
print(stock, "is missing a defined key statistic.")
示例5: update_stock
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def update_stock(dial, stock):
stk = Share(stock)
prev_close_price = float(stk.get_prev_close())
stk_data = json.loads(json.dumps(getQuotes(stock), indent=2))[0]
stk_price = float(stk_data['LastTradePrice'])
NIMBUS.set_dial_value(dial, percentage(stk_price, prev_close_price),
"%s:%.2f" % (stock, stk_price))
示例6: print_stats
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def print_stats(ticker,is_trading_hours):
stock = Share(ticker)
stock.refresh()
if(is_trading_hours == True):
print("Current Price: $" + stock.get_price() + "\n--------------------------------------")
else:
print("Previous Close: $" + stock.get_prev_close())
print("Opening Price: $" + stock.get_open())
print("Current Price: $" + stock.get_price() + "\n--------------------------------------")
示例7: stock_summary
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def stock_summary(request, symbol=None):
if symbol == None:
symbol = request.POST['symbol']
current_stock = Stock()
stock = Share(symbol)
current_stock.symbol = symbol.upper()
current_stock.price = stock.get_price()
current_stock.change = stock.get_change()
current_stock.volume = stock.get_volume()
current_stock.prev_close = stock.get_prev_close()
current_stock.stock_open = stock.get_open()
current_stock.avg_daily_volume = stock.get_avg_daily_volume()
current_stock.stock_exchange = stock.get_stock_exchange()
current_stock.market_cap = stock.get_market_cap()
current_stock.book_value = stock.get_book_value()
current_stock.ebitda = stock.get_ebitda()
current_stock.dividend_share = stock.get_dividend_share()
current_stock.dividend_yield = stock.get_dividend_yield()
current_stock.earnings_share = stock.get_earnings_share()
current_stock.days_high = stock.get_days_high()
current_stock.days_low = stock.get_days_low()
current_stock.year_high = stock.get_year_high()
current_stock.year_low = stock.get_year_low()
current_stock.fifty_day_moving_avg = stock.get_50day_moving_avg()
current_stock.two_hundred_day_moving_avg = stock.get_200day_moving_avg()
current_stock.price_earnings_ratio = stock.get_price_earnings_ratio()
current_stock.price_earnings_growth_ratio = stock.get_price_earnings_growth_ratio()
current_stock.price_sales = stock.get_price_sales()
current_stock.price_book = stock.get_price_book()
current_stock.short_ratio = stock.get_short_ratio()
date_metrics = []
url = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+symbol+'/chartdata;type=quote;range=1y/csv'
page = urllib2.urlopen(url).read()
pagebreaks = page.split('\n')
for line in pagebreaks:
items = line.split(',')
if 'Company-Name:' in line:
current_stock.company_name = line[13:len(line)]
current_stock.save()
if 'values' not in items:
if len(items)==6:
hd = HistoricalData(
stock_id = Stock.objects.get(id=int(current_stock.id)).id,
date = items[0][4:6]+'/'+items[0][6:9]+'/'+items[0][0:4],
close = items[1][0:(len(items[1])-2)],
high = items[2][0:(len(items[2])-2)],
price_open = items[3][0:(len(items[3])-2)],
low = items[4][0:(len(items[4])-2)],
volume = items[5][0:-6]+","+items[5][-6:-3]+","+items[5][-3:len(items[5])])
hd.save()
date_metrics.append(hd)
del date_metrics[0]
return render(request, "stock_summary.html", {'current_stock': current_stock, 'date_metrics': date_metrics})
示例8: get_close_ticker
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def get_close_ticker(self):
date = datetime.datetime.now()
weekday = date.weekday()
if (datetime.time(16,00,30) < date.time() < datetime.time(16,01,30)) and (weekday != 5 or weekday != 6) and (self.posted_close == None or self.posted_close < date.date()):
stock_prices = []
all_stocks = self.get_all_stocks()
if all_stocks:
for stock in all_stocks:
stock_info = Share(stock)
stock_prices.append('%s: $%s [%s]' % (stock_info.symbol.upper(), stock_info.get_prev_close(), stock_info.get_change()))
self.posted_close = date.date()
return ' - '.join(stock_prices)
示例9: get_stock_prices
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def get_stock_prices(stocks):
data = []
for s in stocks:
stock_data = {}
share = Share(s)
percent_change = round(float(share.get_change()) / float(share.get_prev_close()) * 100, 2)
stock_data['symbol'] = s
stock_data['price'] = round(float(share.get_price()), 2)
stock_data['change_percent'] = percent_change
data.append(stock_data)
return data
示例10: getStockInfoNow
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def getStockInfoNow(request):
if request.method == 'GET':
sid = request.GET['sid']
try:
s = Share(sid+'.TW')
p = float(s.get_price())
c = float(s.get_change())
v = float(s.get_volume())/1000
pc = float(s.get_prev_close())
except:
return JsonResponse({"success": 'false', 'error': 'wrong sid'})
return JsonResponse({'price': p, 'change': c, 'volume': v, 'prev_close': pc})
else:
return JsonResponse({"success": 'false', 'error': 'wrong method'})
示例11: post
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def post():
## Update stock info
try:
stock_list = Stock.objects.all()
for stock in stock_list:
try:
s = Share(stock.symbol)
stock.price = s.get_price()
stock.open_price = s.get_open()
stock.pre_close_price = s.get_prev_close()
stock.high_price = s.get_days_high()
stock.low_price = s.get_days_low()
stock.save()
except Exception, e:
pass
except Exception, e:
pass
示例12: get_today_stock_data
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def get_today_stock_data(ticker):
try:
s = Share(ticker)
data = {
'Open': float(s.get_open()),
'Close': float(s.get_prev_close()),
'High': float(s.get_days_high()),
'Low': float(s.get_days_low()),
'Volume': int(s.get_volume()),
'Date': datetime.date.today(),
}
return data
except YQLQueryError:
logger.error("Daily data not found for {}".format(ticker))
except Exception as e:
logger.error("Unexpected error occurred: {}".format(e))
return {}
示例13: rec
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def rec(p):
yahoo = Share(p)
a=yahoo.get_prev_close()
b=yahoo.get_year_high()
c=yahoo.get_year_low()
d=yahoo.get_open()
e=yahoo.get_ebitda()
f=yahoo.get_market_cap()
g=yahoo.get_avg_daily_volume()
h=yahoo.get_dividend_yield()
i=yahoo.get_earnings_share()
j=yahoo.get_days_low()
k=yahoo.get_days_high()
l=yahoo.get_50day_moving_avg()
m=yahoo.get_200day_moving_avg()
n=yahoo.get_price_earnings_ratio()
o=yahoo.get_price_earnings_growth_ratio()
print p
print "Previous Close: ",a
print "Year High",b
print "Year Low",c
print "Open:",d
print "EBIDTA",e
print "Market Cap",f
print "Average Daily Volume",g
print "Dividend Yield",h
print "Earnings per share",i
print "Days Range:", j ,"-",k
print "50 Days Moving Average",l
print "200 Days Moving Average",m
print"Price Earnings Ratio", n
print"Price Earnings Growth Ratio",o
import MySQLdb
db = MySQLdb.connect(host="127.0.0.1", user="root",passwd="1111", db="stocks",local_infile = 1)
cur=db.cursor()
cur.execute ("""
INSERT INTO stockapp_info (symbol, prev_close, year_high, year_low, open_price , ebidta, market_cap, avg_daily_vol , dividend_yield, eps , days_low ,days_high, moving_avg_50, moving_avg_200, price_earnings_ratio, price_earnings_growth_ratio)
VALUES
(%s, %s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
""", (p,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o))
db.commit()
cur.close()
示例14: __init__
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
class YahooFinanceData:
"""Get data from Yahoo Finance."""
def __init__(self, symbol):
"""Initialize the data object."""
from yahoo_finance import Share
self._symbol = symbol
self.state = None
self.price_change = None
self.price_open = None
self.prev_close = None
self.stock = Share(self._symbol)
def update(self):
"""Get the latest data and updates the states."""
self.stock.refresh()
self.state = self.stock.get_price()
self.price_change = self.stock.get_change()
self.price_open = self.stock.get_open()
self.prev_close = self.stock.get_prev_close()
示例15: moreInfo
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_prev_close [as 别名]
def moreInfo(from_number):
#query to find the stock the user last looked up
conn = mysql.connect()
cur = conn.cursor()
q = '''SELECT * FROM last_lookup WHERE phone = %s'''
cur.execute(q,[from_number])
rv = cur.fetchone()
#get stock information
quote = Share(str(rv[1]))
prevClose = quote.get_prev_close()
openPrice = quote.get_open()
volume = quote.get_volume()
#if we get all the information back respond back with more info
if prevClose and openPrice and volume:
retStr = "PrevClose: "+prevClose+" OpenPrice: "+openPrice+" Volume: "+ volume
#else the user has not looked up a stock yet
else:
retStr = "ticker still not found"
return retStr