本文整理汇总了Python中yahoo_finance.Share.get_price_earnings_ratio方法的典型用法代码示例。如果您正苦于以下问题:Python Share.get_price_earnings_ratio方法的具体用法?Python Share.get_price_earnings_ratio怎么用?Python Share.get_price_earnings_ratio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yahoo_finance.Share
的用法示例。
在下文中一共展示了Share.get_price_earnings_ratio方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fundamentalStats
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [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: createInfos
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [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: get_quote
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [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 '-'
}
示例4: report_current_from_yahoo
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [as 别名]
def report_current_from_yahoo(symbol):
yahoo = Share(symbol)
price_cur = yahoo.get_price()
eps = yahoo.get_earnings_share()
pe = yahoo.get_price_earnings_ratio()
print 'yahoo: price=%s eps=%s, pe=%s'%(price_cur, eps, pe)
示例5: updateInfos
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [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.')
示例6: get_quote
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [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 '-'
}
示例7: stock_summary
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [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_company_info
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [as 别名]
def get_company_info(ticker):
try:
s = Share(ticker)
data = {
'Market_cap': s.get_market_cap(),
'Average_volume': s.get_avg_daily_volume(),
'EPS': s.get_earnings_share(),
'Short_ratio': s.get_short_ratio(),
'PE': s.get_price_earnings_ratio(),
'PEG': s.get_price_earnings_growth_ratio(),
}
return DataFetcher._extract_company_info(data)
except YQLQueryError:
logger.error("Company info not found for {}".format(ticker))
except Exception as e:
logger.error("Unexpected error occured: {}".format(e))
return {}
示例9: rec
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [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()
示例10:
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [as 别名]
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
if myargs.exchange is True:
exchange = stock.get_stock_exchange()
if myargs.ma50 is True:
ma50 = stock.get_50day_moving_avg()
print ma50
if myargs.ma200 is True:
ma200 = stock.get_200day_moving_avg()
print ma200
if myargs.marketcap is True:
marketcap = stock.get_market_cap()
示例11: main
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [as 别名]
def main():
# 1. get the time
day = Time.get_utc_day()
hours_mins = Time.get_utc_hours_minutes()
# 1. Get all the list of stocks
stocks = base.managers.stock_manager.get_many()
# 2. go through stock and update the desired values
for stock in stocks:
ticker = stock.get('ticker')
try:
# 2.1 Get the info from the yahoo API
updated_stock = Share(ticker)
except:
print "-->Failed to update: %s with Yahoo API" % ticker
continue
price = updated_stock.get_price()
open = updated_stock.get_open()
days_high = updated_stock.get_days_high()
days_low = updated_stock.get_days_low()
year_high = updated_stock.get_year_high()
year_low = updated_stock.get_year_low()
volume = updated_stock.get_volume()
market_cap = updated_stock.get_market_cap()
pe_ratio = updated_stock.get_price_earnings_ratio()
div_yield = updated_stock.get_dividend_yield()
change = updated_stock.get_change()
change_percent = updated_stock.data_set.get('ChangeinPercent')
# 2.2 Get the stock body
stock_body = stock.get('body')
stock_price = {hours_mins: price}
if stock_body:
# 1. Get the stock info for the day:
stock_info = stock_body.get(day)
if stock_info:
stock_price = stock_info.get('price')
stock_price.update({hours_mins: price})
else:
stock_body = {}
# 2.2.4 update the stock info dict
stock_info = {'price': stock_price}
stock_info.update({'open': open})
stock_info.update({'days_high': days_high})
stock_info.update({'days_low': days_low})
stock_info.update({'year_high': year_high})
stock_info.update({'year_low': year_low})
stock_info.update({'volume': volume})
stock_info.update({'market_cap': market_cap})
stock_info.update({'pe_ratio': pe_ratio})
stock_info.update({'div_yield': div_yield})
stock_info.update({'change': change})
stock_info.update({'change_percent': change_percent})
# update the stock body
stock_body.update({day: stock_info})
stock.body = stock_body
# 3. update the stock in the DB
try:
base.managers.stock_manager.update_one(stock)
except:
print "-->Failed to update: %s in DB" % ticker
continue
示例12:
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [as 别名]
except:
pass
try:
russell3000.set_value(s,'Year low',shy.get_year_low())
except:
pass
try:
russell3000.set_value(s,'50 days MA',shy.get_50day_moving_avg())
except:
pass
try:
russell3000.set_value(s,'200 days MA',shy.get_200day_moving_avg())
except:
pass
try:
russell3000.set_value(s,'Price earnings ratio',shy.get_price_earnings_ratio())
except:
pass
try:
russell3000.set_value(s,'Price earnings growth ratio',shy.get_price_earnings_growth_ratio())
except:
pass
try:
russell3000.set_value(s,'Price sales',shy.get_price_sales())
except:
pass
try:
russell3000.set_value(s,'Price book',shy.get_price_book())
except:
pass
try:
示例13: len
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [as 别名]
if len(ticker) == 0:
continue
stock = Share(ticker)
stock.refresh()
change = (float(stock.get_price()) - float(stock.get_prev_close()))/float(stock.get_prev_close())
change = round(change *100.0, 2)
if change > 0.0:
change= '+' + str(change)
else:
change =str(change)
line = ticker.ljust(7)
line += stock.get_price().ljust(9)+ change.ljust(8)+ stock.get_volume().ljust(11) + \
str(round(float(stock.get_volume())/float(stock.get_avg_daily_volume())*100.0)).ljust(8) +\
stock.get_open().ljust(10)+ \
stock.get_days_low().ljust(10)+ \
stock.get_days_high().ljust(10)+ \
stock.get_year_low().ljust(10)+ \
stock.get_year_high().ljust(10)
line = line + str(stock.get_market_cap()).ljust(11) + \
str(stock.get_price_earnings_ratio()).ljust(8)+\
stock.get_50day_moving_avg().ljust(10) +\
stock.get_200day_moving_avg().ljust(10)
print(line)
except Exception as e:
print("Exception error:", str(e))
traceback.print_exc()
i+=1
#you get get a spy.txt and then filter everything by yourself
示例14: view_stock
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [as 别名]
def view_stock(request, ticker):
if request.user.__class__.__name__ is "CustomUser":
c_user = get_object_or_404(CustomUser, pk=request.user.pk)
account = Account.objects.get(user=c_user)
else:
account = False
stock = get_object_or_404(Stock, ticker=ticker)
companyName = stock.ticker
companyName = companyName.upper()
stock = Stock.objects.get(ticker=companyName)
namer = "'" + companyName + "'"
ystock = Share(companyName)
the_price = ystock.get_price()
regex = 'Business Summary</span></th><th align="right"> </th></tr></table><p>(.+?)</p>'
pattern = re.compile(regex)
root_url = urllib.urlopen("http://finance.yahoo.com/q/pr?s=" + companyName + "+Profile")
htmltext = root_url.read()
decoded_str = str(re.findall(pattern, htmltext)).decode("utf8")
encoded_str = decoded_str.encode("ascii", "ignore")
stock.description = encoded_str
stock.description = stock.description[:-2]
stock.description = stock.description[2:]
stock.book_value = ystockquote.get_book_value(companyName)
stock.change = ystockquote.get_change(companyName)
# stock.dividend_per_share = ystockquote.get_dividend_per_share(companyName)
# stock.dividend_yield = ystockquote.get_dividend_yield(companyName)
stock.ebitda = ystockquote.get_ebitda(companyName)
stock.fifty_two_week_high = ystockquote.get_52_week_high(companyName)
stock.fifty_two_week_low = ystockquote.get_52_week_low(companyName)
stock.market_cap = ystockquote.get_market_cap(companyName)
stock.short_ratio = ystockquote.get_short_ratio(companyName)
stock.stock_exchange = ystockquote.get_stock_exchange(companyName)
stock.volume = ystockquote.get_volume(companyName)
stock.price = ystock.get_price()
# yahoo_finance
stock.average_daily_volume = ystock.get_avg_daily_volume()
stock.earnings_per_share = ystock.get_price_earnings_ratio()
stock.fifty_day_moving_avg = ystock.get_50day_moving_avg()
stock.two_hundred_day_moving_avg = ystock.get_200day_moving_avg()
stock.price_book_ratio = ystock.get_price_book()
stock.last_sale = ystock.get_price()
stock.price_earnings_growth_ratio = ystock.get_price_earnings_growth_ratio()
stock.price_earnings_ratio = ystock.get_price_earnings_ratio()
stock.price_sales_ratio = ystock.get_price_sales()
stock.save()
vl = []
acl = []
hl = []
ll = []
cl = []
ol = []
days_list = []
d = 0
seven_days_ago = datetime.datetime.now() + datetime.timedelta(-30)
today = datetime.datetime.now()
days = ystockquote.get_historical_prices("GOOGL", seven_days_ago.strftime("%Y-%m-%d"), today.strftime("%Y-%m-%d"))
for day in days.keys():
d += 1
date_label = datetime.datetime.now() + datetime.timedelta(-d)
days_list.append(date_label.strftime("%b-%d"))
day_info = days.get(day)
vol = int(day_info.get("Volume"))
vl.append(vol)
adjcl = float(day_info.get("Adj Close"))
acl.append(adjcl)
highs = float(day_info.get("High"))
hl.append(highs)
lows = float(day_info.get("Low"))
ll.append(lows)
closes = float(day_info.get("Close"))
cl.append(closes)
opens = float(day_info.get("Open"))
ol.append(opens)
volume = vl
lows = ll
opens = ol
highs = hl
averages = acl
closes = cl
days_l = days_list[::-1]
context = RequestContext(
request,
dict(
account=account,
request=request,
stock=stock,
volume=volume,
lows=lows,
highs=highs,
opens=opens,
closes=closes,
averages=averages,
days_l=days_l,
),
#.........这里部分代码省略.........
示例15: Symbol
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_price_earnings_ratio [as 别名]
class Symbol(object):
def __init__(self, symbol, s_date=None, e_date=None):
self.log=Logging()
self.name=symbol
self.created=datetime.datetime.utcnow()
self.log.info("created {}".format(self.name))
try:
self.share=Share(symbol)
except:
self.log.error("platform is offline or not connecting")
if s_date and e_date:
self.begin=s_date
self.end=e_date
try:
self.share=Share(symbol)
self.data=self.share.get_historical(self.begin, self.end)
self.log.refresh("{} data collected".format(self.name))
except:
self.log.error("platform is offline or not connecting")
def refresh_data(self, s_date=None, e_date=None):
if s_date and e_date:
try:
share=Share(self.name)
self.begin=s_date
self.end=e_date
share.get_historical(s_date, e_date)
self.log.refresh("{} data collected".format(self.name))
except:
self.log.error("platform is offline or not connecting")
def market_cap(self):
try:
self.market_cap = self.share.get_market_cap()
self.log.info("{} market cap refreshed".format(self.name))
except:
self.log.error("platform is offline or not connecting")
def earnings_per_share(self):
try:
self.eps = self.share.get_earnings_share()
self.log.info("{} eps refreshed".format(self.name))
except:
self.log.error("platform is offline or not connecting")
def moving_average_50(self):
try:
self.moving_average_50 = self.share.get_50day_moving_average()
self.log.info("{} 50 day moving ave refreshed".format(self.name))
except:
self.log.error("platform is offline or not connecting")
#implement TODO
def nday_moving_average(self, n):
try:
self.moving_average_n = None
self.log.info("{} {} day moving ave refreshed".format(self.name, n))
except:
self.log.error("platform is offline or not connecting")
def price_earnings_ratio(self):
try:
self.price_to_earnings = self.share.get_price_earnings_ratio()
self.log.info("{} price to earnings refreshed".format(self.name))
except:
self.log.error("platform is offline or not connecting")
def book_value(self):
try:
self.book = self.share.get_price_book()
self.log.info("{} book value refreshed".format(self.name))
except:
self.log.error("platform is offline or not connecting")
def year_high(self):
try:
self.year_high = self.share.get_change_from_year_high()
self.log.info("{} year high change refreshed".format(self.name))
except:
self.log.error("platform is offline or not connecting")
def year_low(self):
try:
self.year_low = self.share.get_change_from_year_low()
self.log.info("{} year low change refreshed".format(self.name))
except:
self.log.error("platform is offline or not connecting")
def target_price(self):
try:
self.year_target = self.share.get_change_from_year_high()
self.log.info("{} year target change refreshed".format(self.name))
except:
self.log.error("platform is offline or not connecting")
def year_range(self):
try:
#.........这里部分代码省略.........