本文整理汇总了Python中yahoo_finance.Share.get_info方法的典型用法代码示例。如果您正苦于以下问题:Python Share.get_info方法的具体用法?Python Share.get_info怎么用?Python Share.get_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yahoo_finance.Share
的用法示例。
在下文中一共展示了Share.get_info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: debug
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
def debug():
# create character
print("Welcome, brave adventurer!")
name = input("What is your name?")
print("Ah, I see. So your name is", name, "?")
share1 = input("Pick a share.")
option1 = Share(share1)
print("Ah, so you chose", option1.get_info(), "?")
share2 = input("Pick a second share")
option2 = Share(share2)
print("Ah, so you chose", option2.get_info(), "?")
name = characters.character(name, 100, 10, 10, 100, Share1, Share2)
while(1):
a = 1
示例2: make_csv
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
def make_csv(self,name,now_time):
if os.path.exists(self.DIR_NAME+name+".csv"):
print "Already have a %s.csv"%name
return
print "making %s.csv....." %name
from yahoo_finance import Share
share=Share(name)
info=share.get_info()
if "start" not in info:
print "Cant make a %s.csv"%name
return -1
start=info["start"]
#wrong date
if re.match("\d{4}-\d{2}-\d{2}",start)== None:
print "invalid date cant make a file"
return -1
obj=share.get_historical(start,now_time)
filename=name+".csv"
fieldnames=("Date","High","Low","Volume" )
headers = dict( (n,n) for n in fieldnames )
f=open(self.DIR_NAME+filename,"w")
writer=csv.DictWriter(f,fieldnames)
writer.writerow(headers)
for o in obj:
row=""
writer.writerow({"Date":o["Date"],"High":o["High"],"Low":o["Low"],"Volume":o["Volume"]})
f.close()
示例3: lookup_by_symbol
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
def lookup_by_symbol(symbol='', service='y'):
"""
TODO : Not calling this method anywhere now; think about
this method's purpose again
"""
query_symbol = Symbol.symbol_dict.get(symbol)
if query_symbol is None:
try:
if service == 'g':
g_get_quotes(symbol)
query_symbol = Symbol(g_symbol=symbol)
elif service == 'y':
print 'creating Share instance to check whether valid symbol'
y_obj = Share(symbol)
if 'start' not in y_obj.get_info():
raise Exception('Given symbol doesn\'t exist in Yahoo finance')
query_symbol = Symbol(y_symbol=symbol)
query_symbol.yahoo_handle = y_obj
except urllib2.HTTPError:
print('{symbol} is invalid'.format(symbol=symbol))
except Exception as e:
print(e.args)
return query_symbol
示例4: history
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
def history():
# If a user goes to the display page and a session is not active
if session.get('active') != True:
sym = 'SPY'
session['active'] = True
session['sym'] = sym
else:
sym = session['sym'] # if a session is active leave the sym alone
share = Share(sym)
historical = share.get_historical('2016-03-13', '2016-04-15')
canvas_list = []
for day in historical:
canvas_list.append([int(day['Date'][:4]),
int(day['Date'][5:7]) - 1,
int(day['Date'][-2:]),
float(day['Open']),
float(day['High']),
float(day['Low']),
float(day['Close'])
])
info = share.get_info()
open = share.get_open()
high = share.get_days_high()
low = share.get_days_low()
price = share.get_price()
canvas_list.append([int(info['end'][:4]),
int(info['end'][5:7]) - 1,
int(info['end'][-2:]),
float(open),
float(high),
float(low),
float(price)
])
return render_template('history.html',
canvas_list=canvas_list,
sym=sym)
示例5: TestShare
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
class TestShare(TestCase):
def setUp(self):
self.yahoo = Share('YHOO')
def test_yhoo(self):
# assert that these are float-like
float(self.yahoo.get_open())
float(self.yahoo.get_price())
def test_get_info(self):
info = self.yahoo.get_info()
self.assertEqual(info['start'], '1996-04-12')
self.assertEqual(info['symbol'], 'YHOO')
def test_get_historical(self):
history = self.yahoo.get_historical('2014-04-25', '2014-04-29')
self.assertEqual(len(history), 3)
expected = {
'Adj_Close': '35.83',
'Close': '35.83',
'Date': '2014-04-29',
'High': '35.89',
'Low': '34.12',
'Open': '34.37',
'Symbol': 'YHOO',
'Volume': '28736000'
}
self.assertDictEqual(history[0], expected)
def test_get_historical_longer_than_1y(self):
# issue #2
history = self.yahoo.get_historical('2012-04-25', '2014-04-29')
self.assertEqual(history[-1]['Date'], '2012-04-25')
self.assertEqual(history[0]['Date'], '2014-04-29')
self.assertEqual(len(history), 505)
示例6: Share
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
#getYahooAPIData.py
# sudo -H pip install yahoo-finance
from yahoo_finance import Share
from pprint import pprint
yahoo = Share('YHOO')
start = '2015-01-01'
end = '2015-12-31'
yahoo_prices = yahoo.get_historical(start,end)
yahoo_info = yahoo.get_info()
print type(yahoo_prices)
print yahoo_prices[0]
# Methods
# get_price()
# get_change()
# get_volume()
# get_prev_close()
# get_open()
# get_avg_daily_volume()
# get_stock_exchange()
# get_market_cap()
# get_book_value()
# get_ebitda()
示例7: TestShare
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
class TestShare(TestCase):
def setUp(self):
self.yahoo = Share('YHOO')
def test_yhoo(self):
# assert that these are float-like
float(self.yahoo.get_open())
float(self.yahoo.get_price())
def test_get_info(self):
info = self.yahoo.get_info()
self.assertEqual(info['start'], '1996-04-12')
self.assertEqual(info['symbol'], 'YHOO')
def test_get_historical(self):
history = self.yahoo.get_historical('2014-04-25', '2014-04-29')
self.assertEqual(len(history), 3)
expected = {
'Adj_Close': '35.83',
'Close': '35.83',
'Date': '2014-04-29',
'High': '35.89',
'Low': '34.12',
'Open': '34.37',
'Symbol': 'YHOO',
'Volume': '28736000'
}
self.assertDictEqual(history[0], expected)
def test_get_historical_longer_than_1y(self):
# issue #2
history = self.yahoo.get_historical('2012-04-25', '2014-04-29')
self.assertEqual(history[-1]['Date'], '2012-04-25')
self.assertEqual(history[0]['Date'], '2014-04-29')
self.assertEqual(len(history), 505)
def test_get_historical_1d(self):
# issue #7
history = self.yahoo.get_historical('2014-04-29', '2014-04-29')
self.assertEqual(len(history), 1)
expected = {
'Adj_Close': '35.83',
'Close': '35.83',
'Date': '2014-04-29',
'High': '35.89',
'Low': '34.12',
'Open': '34.37',
'Symbol': 'YHOO',
'Volume': '28736000'
}
self.assertDictEqual(history[0], expected)
def test_edt_to_utc(self):
edt = '5/26/2014 4:00pm'
utc = '2014-05-26 20:00:00 UTC+0000'
self.assertEqual(edt_to_utc(edt), utc)
def test_get_date_range(self):
result = [i for i in get_date_range('2012-04-25', '2014-04-29')]
expected = [
('2013-04-29', '2014-04-29'),
('2012-04-28', '2013-04-28'),
('2012-04-25', '2012-04-27'),
]
self.assertEqual(result, expected)
示例8: get_history
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
def get_history(symbol, exchange):
## Check if symbol is in our database
path = join(dirname(realpath(__file__)),'data', exchange, symbol + '.history')
subprocess.call("touch " + path , shell=True)
last_line = subprocess.Popen("tail -n1 "+ path, shell=True, stdout=subprocess.PIPE).stdout.read()
last_date = last_line.split('\t')[0]
if isdate(last_date):
if yesterday == last_date:
stupdate( symbol + ' already up to date.')
del path
del last_date
return True
stupdate( symbol + ' updating..')
share = Share(symbol)
else:
subprocess.call("echo \"Date\\tVolume\\tOpen\\tClose\\tHigh\\tLow\" > " + path, shell=True)
try:
share = Share(symbol)
last_date = share.get_info()['start']
except:
last_date = '2000-01-04'
dates = [last_date, '2000-01-04', '2005-01-04', '2010-01-04']
for i, date in enumerate(dates):
try:
yahoo_history = share.get_historical(date, today)
break
except:
error(sys.exc_info()[0])
error('Yahoo error, inputs => date: ' + date + ' symbol: ' + symbol)
if i == 3: return False
bad_line = 0
for day in yahoo_history[-2::-1]:
try:
echo = (
day['Date'] + '\\t' +
day['Volume'] + '\\t' +
day['Open'] + '\\t' +
day['Close'] + '\\t' +
day['High'] + '\\t' +
day['Low'])
subprocess.call( "echo \"{0}\" >> {1}".format(echo, path), shell=True)
del echo
except:
error(sys.exc_info()[0])
del day
if bad_line > 4:
error(" aborting... bad symbol data: "+ symbol)
global bad_symbols
bad_symbols.append(symbol)
del share
del dates
del exchange
del bad_line
del path
del yahoo_history
error(locals())
return False
bad_line += 1
continue
del yahoo_history
del share
return True
示例9: write_technical_files
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
def write_technical_files(stock_code, start_time, end_time):
# """ Experiment on quandl """
# print('quandl data')
# mydata = quandl.get("FRED/GDP")
# print(mydata)
# print('hello')
# data = quandl.get("WIKI/FB.11", start_date="2014-01-01", end_date="2014-12-31", collapse="monthly", transform="diff")
# print(data)
stock = Share(stock_code)
print('stock.get_info()')
print(stock.get_info())
print('get_price()')
print(stock.get_price())
print('get_change()')
print(stock.get_change())
print('get_stock_exchange()')
print(stock.get_stock_exchange())
print('get_market_cap()')
print(stock.get_market_cap())
print('get_book_value()')
print(stock.get_book_value())
print('get_ebitda()')
print(stock.get_ebitda())
print('get_dividend_share()')
print(stock.get_dividend_share())
print('get_dividend_yield()')
print(stock.get_dividend_yield())
print('get_earnings_share()')
print(stock.get_earnings_share())
print('get_50day_moving_avg()')
print(stock.get_50day_moving_avg())
print('get_200day_moving_avg()')
print(stock.get_200day_moving_avg())
print('get_price_earnings_ratio()')
print(stock.get_price_earnings_ratio())
print('get_price_earnings_growth_ratio()')
print(stock.get_price_earnings_growth_ratio())
print('get_price_sales()')
print(stock.get_price_sales())
print('get_price_book()')
print(stock.get_price_book())
print('get_short_ratio()')
print(stock.get_short_ratio())
print('historical_data')
print(stock.get_historical(start_time, end_time))
historical_data = stock.get_historical(start_time, end_time)
info_text = "Symbol\t" + "Stock Exchange\t" + "Price\t" + "Market Cap\t" + "Book Value\t" + "EBITDA\t" + "50d Moving Avg\t" + "100d Moving Avg\n"
info_text += str(stock.get_info()['symbol']) + "\t" + str(stock.get_stock_exchange()) + "\t" + str(stock.get_price()) + "\t" + str(stock.get_market_cap()) + "\t" + str(stock.get_book_value()) + "\t";
info_text += str(stock.get_ebitda()) + "\t" + str(stock.get_50day_moving_avg()) + "\t" + str(stock.get_200day_moving_avg()) + "\n";
info_directory = '/data/info.tsv'
write_to_file(info_directory, info_text)
high_low_text = "date\t" + "High\t" + "Low\n"
open_close_text = "date\t" + "Open\t" + "Close\n"
volume_text = "date\t" + "Volume\n"
for index, value in enumerate(historical_data):
date = str(historical_data[len(historical_data) - 1 - index]['Date'])
date = date.replace('-','')
stock_high = str(historical_data[len(historical_data) - 1 - index]['High'])
stock_low = str(historical_data[len(historical_data) - 1 - index]['Low'])
stock_open = str(historical_data[len(historical_data) - 1 - index]['Open'])
stock_close = str(historical_data[len(historical_data) - 1 - index]['Close'])
stock_volume = str(int(historical_data[len(historical_data) - 1 - index]['Volume']) / 1000)
high_low_text += date + "\t" + stock_high + "\t" + stock_low + "\n"
open_close_text += date + "\t" + stock_open + "\t" + stock_close + "\n"
volume_text += date + "\t" + stock_volume + "\n"
high_low_directory = '/data/highlow.tsv'
open_close_directory = '/data/openclose.tsv'
volume_directory = '/data/volume.tsv'
#.........这里部分代码省略.........
示例10: list
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
for cfound in list_founds:
name_found1 = cfound[0].replace('+', '').replace('.', '').replace(' ', '').replace('&','%26').replace('-', '') + ".MX"
name_found2 = cfound[0].replace('+', '').replace('.', '').replace(' ', '').replace('&','%26') + ".MX"
hdata_found = 0
list_nfounds = list()
list_nfounds.append(name_found1)
if name_found1 != name_found2:
list_nfounds.append(name_found2)
print '{0} ({1}): "{2}"'.format(cfound[0], cfound[1], list_nfounds)
for name_found in list_nfounds:
try:
ofound = Share(name_found) # Found object
sleep(1) # Pause time (1 segs.) to avoid server rejections
try:
info = ofound.get_info()
print info
if info.get('start') == None:
found_error.write("-Error-[{}]: No 'start' and 'end' dates for historical data. Used code: '{}'\n".format(cfound[0], name_found))
#elif not validate(info['start']):
# found_error.write("-Error-[{}]: No valid 'start' date for historical data. Used code: '{}', fault date: '{}'\n".format(cfound[0], name_found, info['start']))
else:
if not validate(info['start']):
found_error.write("Warning[{}]: No valid 'start' date for historical data. Used code: '{}', fault date: '{}', substitute date: '{}'\n".format(cfound[0], name_found, info['start'], info['start'].replace('-NaN-', '-01-')))
info['start'] = info['start'].replace('-NaN-', '-01-')
if validate(info['start']):
print " ---> 'start': '{}'".format(info['start'])
sdate = datetime.datetime.strptime(info['start'], '%Y-%m-%d')
idate = datetime.datetime.strptime(cfound[1], '%Y-%m-%d')
if idate <= sdate:
示例11: print_menu
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [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)
示例12: print
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
print(yahoo.get_ebitda())
print(yahoo.get_earnings_share())
print(yahoo.get_price_book())
print(goog.get_ebitda())
print(goog.get_earnings_share())
print(goog.get_price_book())
from yahoo_finance import Share
IBB = Share('IBB')
print(IBB.get_ebitda())
from yahoo_finance import Share
li = ['YHOO','GOOG']
yahoo = Share('YHOO')
goog = Share('GOOG')
print(yahoo.get_book_value())
for i in li:
t = Share(i)
print(i)
print(t.get_book_value())
from pprint import pprint
from yahoo_finance import Share
yahoo = Share('YHOO')
print(yahoo.get_ebitda())
pprint(yahoo.get_info())
示例13: Share
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
from yahoo_finance import Share, Currency
yahoo = Share('AAPL')
yahoo.refresh()
print yahoo.get_info()
print yahoo.get_avg_daily_volume()
print yahoo.get_stock_exchange()
print yahoo.get_book_value()
print yahoo.get_ebitda()
print yahoo.get_dividend_share()
print yahoo.get_price_earnings_ratio()
print yahoo.get_short_ratio()
print yahoo.get_price_book()
# f = open('nasdaqlisted.txt', 'r')
# print (f.readline())
# print (f.readline())
示例14: Share
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
import time
from yahoo_finance import Share
# Download price of a company
price = Share("YHOO")
# New a file to record its current price
f = open("COMPANY_NAME" + "_STOCKPRICE.txt", "wb")
f.write(str(price.get_info()) + "\n")
# Get open stock value
f.write(str(price.get_open()) + "\n")
# Get next price
f.write(str(price.get_price()) + " at " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) + "\n")
for i in range(0, 28):
# Sleep one min
time.sleep(1)
# Get next price
f.write(str(price.get_price()) + " at " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) + "\n")
f.write("Complete!")
f.close()
示例15: TestShare
# 需要导入模块: from yahoo_finance import Share [as 别名]
# 或者: from yahoo_finance.Share import get_info [as 别名]
class TestShare(TestCase):
def setUp(self):
self.yahoo = Share('YHOO')
def test_yhoo(self):
# assert that these are float-like
float(self.yahoo.get_open())
float(self.yahoo.get_price())
def test_get_info(self):
info = self.yahoo.get_info()
self.assertEqual(info['start'], '1996-04-12')
self.assertEqual(info['symbol'], 'YHOO')
def test_get_historical(self):
history = self.yahoo.get_historical('2014-04-25', '2014-04-29')
self.assertEqual(len(history), 3)
expected = {
'Adj_Close': '35.830002',
'Close': '35.830002',
'Date': '2014-04-29',
'High': '35.889999',
'Low': '34.119999',
'Open': '34.369999',
'Symbol': 'YHOO',
'Volume': '28736000'
}
self.assertDictEqual(history[0], expected)
def test_get_historical_longer_than_1y(self):
# issue #2
history = self.yahoo.get_historical('2012-04-25', '2014-04-29')
self.assertEqual(history[-1]['Date'], '2012-04-25')
self.assertEqual(history[0]['Date'], '2014-04-29')
self.assertEqual(len(history), 505)
def test_get_historical_1d(self):
# issue #7
history = self.yahoo.get_historical('2014-04-29', '2014-04-29')
self.assertEqual(len(history), 1)
expected = {
'Adj_Close': '35.830002',
'Close': '35.830002',
'Date': '2014-04-29',
'High': '35.889999',
'Low': '34.119999',
'Open': '34.369999',
'Symbol': 'YHOO',
'Volume': '28736000'
}
self.assertDictEqual(history[0], expected)
def test_edt_to_utc(self):
edt = '5/26/2014 4:00pm'
utc = '2014-05-26 20:00:00 UTC+0000'
self.assertEqual(edt_to_utc(edt), utc)
def test_edt_to_utc_issue15(self):
# date string for yahoo can contains 0 rather than 12.
# This means that it cannot be parsed with %I see GH issue #15.
edt = '4/21/2015 0:13am'
utc = '2015-04-21 04:13:00 UTC+0000'
self.assertEqual(edt_to_utc(edt), utc)
def test_get_date_range(self):
result = [i for i in get_date_range('2012-04-25', '2014-04-29')]
expected = [
('2013-04-29', '2014-04-29'),
('2012-04-28', '2013-04-28'),
('2012-04-25', '2012-04-27'),
]
self.assertEqual(result, expected)