本文整理汇总了Python中yahoo_finance.Share.get_change方法的典型用法代码示例。如果您正苦于以下问题:Python Share.get_change方法的具体用法?Python Share.get_change怎么用?Python Share.get_change使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yahoo_finance.Share
的用法示例。
在下文中一共展示了Share.get_change方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fundamentalStats
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [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.")
示例2: get_quote
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [as 别名]
def get_quote(symbol):
share = Share(symbol)
if not share.get_price():
return {}
change_f = float(share.get_change())
change_str = '+%.02f' % change_f if change_f >= 0 else '%.02f' % change_f
change_percent_f = change_f / float(share.get_open()) * 100
change_percent = '+%.02f' % change_percent_f if change_percent_f >= 0 else '%.02f' % change_percent_f
return {
'price': share.get_price(),
'change': change_str,
'change_percent': change_percent,
'open_price': share.get_open(),
'market_cap': share.get_market_cap(),
'year_low': share.get_year_low(),
'year_high': share.get_year_high(),
'day_low': share.get_days_low(),
'day_high': share.get_days_high(),
'volume': share.get_volume(),
'pe_ratio': share.get_price_earnings_ratio() or '-'
}
示例3: stocks
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [as 别名]
def stocks(self, message, params=None, **kwargs):
"""Display current stock value for user provided symbol(s)
(ex: .stock rax,yhoo,aapl)
"""
if not params:
message.dispatch("No stock symbol provided, please provide "
"at least one symbol. Example: .stock rax or "
".stock rax,yhoo,aapl")
return
text = ""
try:
symbols = params.upper().split(',')
for s in symbols:
share = Share(s)
text = (text + "%s: %s (%s) | " %
(s, share.get_price(), share.get_change()))
text = text.rstrip(" ")
text = text.rstrip("|")
except Exception:
text = ("Unable to fetch stocks data. "
"Please ensure the symbols you've provided are valid")
message.dispatch(text)
示例4: getStockInfo
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [as 别名]
def getStockInfo(symbol):
yahoo_finance_client = Share(symbol)
stock_info = {}
stock_info["price"] = yahoo_finance_client.get_price()
stock_info["change"] = yahoo_finance_client.get_change()
return stock_info
示例5: get_quote
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [as 别名]
def get_quote(symbol):
share = Share(symbol)
return {
'open': share.get_open(),
'price': share.get_price(),
'change': share.get_change(),
'market_cap': share.get_market_cap(),
'pe': share.get_price_earnings_ratio() or '-'
}
示例6: stock_summary
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [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})
示例7: stock
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [as 别名]
def stock(message):
ticker = Share(message)
ticker.refresh()
quote = ticker.get_price()
if quote is None:
resp = str(message) + " is not a valid ticker symbol"
else:
change = ticker.get_change()
resp = message + ": " + quote + " " + change
__send_response(resp, icon_money)
quote = ""
示例8: get_stock_prices
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [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
示例9: getStockInfoNow
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [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'})
示例10: __init__
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [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()
示例11: displayStockQuotes
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [as 别名]
def displayStockQuotes(symbols, seconds):
"""
Display each symbol's price, volume and percent change for seconds
:param: symbols: List of stock symbols in Yahoo format. E.g. 'AMZN' or 'BRK-B' (NOTE: not 'BRK.B').
:param: seconds: Number of seconds to display each stock.
# The following Adafruit_CharLCD library is found here:
# https://github.com/adafruit/Adafruit_Python_CharLCD
# See this tutorial for a hello world Python/Raspberry Pi/LCD tutorial:
# https://learn.adafruit.com/drive-a-16x2-lcd-directly-with-a-raspberry-pi/python-code
"""
lcd = Adafruit_CharLCD()
while True:
for symbol in symbols:
stock = Share(symbol)
lcd.clear()
lcd.message(symbol + ": $")
lcd.message(stock.get_price() + "\n")
volume = stock.get_volume()
change = stock.get_change()
lcd.message(change + "|")
open = stock.get_open()
if type(open) is str and type(change) is str:
percentChange = float(change) / float(open)
# format percent change in human-readable format: "1%" instead of ".01"
lcd.message("{0:.00%}".format(percentChange))
else:
lcd.message("?")
if volume:
lcd.message("|" + volume)
else:
lcd.message("|?")
sleep(seconds) # Delay between each stock/symbol
示例12: YahooFinanceData
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [as 别名]
class YahooFinanceData(object):
"""Get data from Yahoo Finance."""
def __init__(self, name, symbol):
"""Initialize the data object."""
from yahoo_finance import Share
self._name = name
self._symbol = symbol
self.state = None
self.price_change = None
self.price_open = None
self.prev_close = None
self.stock = Share(symbol)
@Throttle(MIN_TIME_BETWEEN_UPDATES)
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()
示例13: get_info
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [as 别名]
def get_info(ticker):
# rjson = get_json(ticker)
info = {}
try:
stock = Share(ticker)
# 0: Get name
url = "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query={}®ion=1&lang=en".format(ticker)
print("Ticker: ", ticker)
result = requests.get(url).json()
for x in result['ResultSet']['Result']:
if x['symbol'] == ticker:
info['name'] = truncate(x['name'])
if info['name'] == "" or info['name'] == None:
raise ValueError('Did not obtain a real value!')
# 1: Get price
# info['price'] = float(rjson[0][u'l'])
info['price'] = get_price(ticker)
if info['price'] == 0 or info['price'] == None:
raise ValueError('Did not obtain a real value!')
# 2: Get datetime
# info['datetime'] = rjson[0][u'lt']
info['datetime'] = getdatetime(ticker)
if info['datetime'] == "" or info['datetime'] == None:
raise ValueError('Did not obtain a real value!')
# 3: Get gain
# change = rjson[0][u'c']
# if change is None:
# info['gain'] = 0
# c = change.split("+")
# if (len(c) > 1):
# info['gain'] = float(c[1])
# info['gain'] = float(change)
change = stock.get_change()
if change is None:
info['gain'] = 0
else:
info['gain'] = float(stock.get_change())
if info['gain'] == None:
raise ValueError('Did not obtain a real value!')
# 4: Get percent change
# info['percentchange'] = float(rjson[0][u'cp'])
try:
percentChange = stock.get_percent_change()
percentChange = percentChange.split("%")[0]
if len(percentChange.split("+")) > 1:
percentChange = percentChange.split("+")[1]
elif len(percentChange.split("-")) > 1:
percentChange = percentChange.split("-")[1]
info['percentchange'] = float(percentChange)
except:
info['percentchange'] = stock.get_percent_change()
if info['percentchange'] == None:
raise ValueError('Did not obtain a real value!')
except:
if db.session.query(Stock).filter_by(ticker = ticker).count() > 0:
found_stock = db.session.query(Stock).filter_by(ticker = ticker).first()
info['name'] = found_stock.name
info['price'] = found_stock.price
info['datetime'] = found_stock.datetime
info['gain'] = found_stock.change
info['percentchange'] = found_stock.percentChange
else:
info['name'] = "N/A"
info['price'] = 0.00
info['datetime'] = "N/A"
info['gain'] = 0.00
info['percentchange'] = 0.00
return info
示例14:
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [as 别名]
subrealtimequote = realtime.scraper(myargs.ticker)
output.append(subrealtimequote)
if myargs.price is True:
price = stock.get_price()
print price
if myargs.volume is True:
volume = stock.get_volume()
output.append(volume)
selections.append('Volume: ')
print output
if myargs.change is True:
change = stock.get_change()
output.append(change)
selections.append('Change: ')
print change
if myargs.avgvol is True:
avgvolume = stock.get_avg_daily_volume()
print avgvolume
if myargs.short is True:
short = stock.get_short_ratio()
print short
if myargs.peratio is True:
pe = stock.get_price_earnings_ratio()
print pe
示例15: print_menu
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_change [as 别名]
def print_menu(menuid, errorid):
global selected_Ticker
namesTicker = ["Stocks", "Exchanges", "Catagory", "Number Selection"]
if selected_Ticker is not None:
print("Selected:\t"+selected_Ticker.name)
print("Type:\t\t"+namesTicker[selected_Ticker.typeof])
if selected_Ticker.typeof == 0:
stock = Share(selected_Ticker.name)
stock.refresh()
print(stock.get_info())
print(stock.get_price())
print(stock.get_change())
print(stock.get_volume())
print("\n\n")
if menuid == 0:
print("------Menu------")
print(" (e) exit")
print(" (l) list")
print(" (s) stats")
error(errorid)
elif menuid == 1:
print("------Stats Menu------")
print(" (a) all")
print(" (u) uniques")
print(" (b) back")
if selected_Ticker is not None:
print(" (r) run data collector")
print(" (c) clear")
error(errorid)
elif menuid == 2:
print("------All Data Menu------")
print(" (e) exchanges")
print(" (c) catagories")
print(" (n) catagory Number")
print(" (b) back")
error(errorid)
elif menuid == 3:
print("------Unique Menu------")
print(" (s) stock")
print(" (e) exchange")
print(" (c) catagories")
print(" (n) catagory Number")
print(" (b) back")
error(errorid)
elif menuid == 4:
print("------Stock Tickers Selection------")
exchanges_display(0)
error(errorid)
elif menuid == 5:
print("------Exchanges Selection------")
exchanges_display(1)
error(errorid)
elif menuid == 6:
print("------Catagory Selection------")
exchanges_display(2)
error(errorid)
elif menuid == 7:
print("------Number Catagory Selection------")
exchanges_display(3)
error(errorid)