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})
def getAllStockData(ticker): '''Get a few random tickers.''' stock = Share(ticker) stock.refresh() data = { 'name': stock.get_name(), 'price': stock.get_price(), 'change': stock.get_change(), 'volume': stock.get_volume(), 'prev_close': stock.get_prev_close(), 'open': stock.get_open(), 'avg_daily_volume': stock.get_avg_daily_volume(), 'stock_exchange': stock.get_stock_exchange, 'market_cap': stock.get_market_cap(), 'book_value': stock.get_book_value(), 'ebitda': stock.get_ebitda(), 'dividend_share': stock.get_dividend_share(), 'dividend_yield': stock.get_dividend_yield(), 'earnings_share': stock.get_earnings_share(), 'days_high': stock.get_days_high(), 'days_low': stock.get_days_low(), 'year_high': stock.get_year_high(), 'year_low': stock.get_year_low(), '50day_moving_avg': stock.get_50day_moving_avg(), '200day_moving_avg': stock.get_200day_moving_avg(), 'price_earnings_ratio': stock.get_price_earnings_ratio(), 'price_earnings_growth_ratio': stock.get_price_earnings_growth_ratio(), 'get_price_sales': stock.get_price_sales(), 'get_price_book': stock.get_price_book(), 'get_short_ratio': stock.get_short_ratio(), 'trade_datetime': stock.get_trade_datetime(), 'percent_change_from_year_high': stock.get_percent_change_from_year_high(), 'percent_change_from_year_low': stock.get_percent_change_from_year_low(), 'change_from_year_low': stock.get_change_from_year_low(), 'change_from_year_high': stock.get_change_from_year_high(), 'percent_change_from_200_day_moving_average': stock.get_percent_change_from_200_day_moving_average(), 'change_from_200_day_moving_average': stock.get_change_from_200_day_moving_average(), 'percent_change_from_50_day_moving_average': stock.get_percent_change_from_50_day_moving_average(), 'change_from_50_day_moving_average': stock.get_change_from_50_day_moving_average(), 'EPS_estimate_next_quarter': stock.get_EPS_estimate_next_quarter(), 'EPS_estimate_next_year': stock.get_EPS_estimate_next_year(), 'ex_dividend_date': stock.get_ex_dividend_date(), 'EPS_estimate_current_year': stock.get_EPS_estimate_current_year(), 'price_EPS_estimate_next_year': stock.get_price_EPS_estimate_next_year(), 'price_EPS_estimate_current_year': stock.get_price_EPS_estimate_current_year(), 'one_yr_target_price': stock.get_one_yr_target_price(), 'change_percent_change': stock.get_change_percent_change(), 'divended_pay_date': stock.get_dividend_pay_date(), 'currency': stock.get_currency(), 'last_trade_with_time': stock.get_last_trade_with_time(), 'days_range': stock.get_days_range(), 'years_range': stock.get_year_range() } return data
def get_symbol_yahoo_stats_yql(symbols, exclude_name=False): """ Get the symbols' basic statistics from Yahoo Finance. Input: symbols - a list of symbol strings, e.g. ['AAPL'] Output: stats in Pandas DataFrame. This function is ported from pandas_datareader/yahoo/components.py """ sym_list = str2list(symbols) if sym_list == None: return DataFrame() # Yahoo Finance tags, refer to http://www.financialwisdomforum.org/gummy-stuff/Yahoo-data.htm tags = ['Symbol'] if not exclude_name: tags += ['Name'] tags += ['Exchange', 'MarketCap', 'Volume', 'AverageDailyVolume', 'BookValue', 'P/E', 'PEG', 'Price/Sales', 'Price/Book', 'EBITDA', 'EPS', 'EPSEstimateNextQuarter', 'EPSEstimateCurrentYear', 'EPSEstimateNextYear', 'OneyrTargetPrice', 'PriceEPSEstimateCurrentYear', 'PriceEPSEstimateNextYear', 'ShortRatio', 'Dividend/Share', 'DividendYield', 'DividendPayDate', 'ExDividendDate'] lines = [] for sym in sym_list: stock = Share(sym) line = [sym] if not exclude_name: line += [stock.get_name()] line += [stock.get_stock_exchange(), str2num(stock.get_market_cap(), m2b=True), str2num(stock.get_volume()), str2num(stock.get_avg_daily_volume()), str2num(stock.get_book_value()), str2num(stock.get_price_earnings_ratio()), str2num(stock.get_price_earnings_growth_ratio()), str2num(stock.get_price_sales()), str2num(stock.get_price_book()), str2num(stock.get_ebitda()), str2num(stock.get_earnings_share()), str2num(stock.get_EPS_estimate_next_quarter()), str2num(stock.get_EPS_estimate_current_year()), str2num(stock.get_EPS_estimate_next_year()), str2num(stock.get_one_yr_target_price()), str2num(stock.get_price_EPS_estimate_current_year()), str2num(stock.get_price_EPS_estimate_next_year()), str2num(stock.get_short_ratio()), str2num(stock.get_dividend_share()), str2num(stock.get_dividend_yield()), stock.get_dividend_pay_date(), stock.get_ex_dividend_date()] lines.append(line) stats = DataFrame(lines, columns=tags) stats = stats.drop_duplicates() stats = stats.set_index('Symbol') return stats
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() print marketcap if myargs.getopen is True: getopen = stock.get_open() print getopen if myargs.getbook is True: getbook = stock.get_book_value() print getbook if myargs.dividendshare is True: getdiv = stock.get_dividend_share() print getdiv if myargs.dividendyield is True: dividendyield = stock.get_dividend_yield() print dividendyield if myargs.eps is True: eps = stock.get_earnings_share() print eps if myargs.dayh is True:
except: pass try: russell3000.set_value(s,'Open',shy.get_open()) except: pass try: russell3000.set_value(s,'Average daily volume',shy.get_avg_daily_volume()) except: pass try: russell3000.set_value(s,'Market cap',shy.get_market_cap()) except: pass try: russell3000.set_value(s,'Book value',shy.get_book_value()) except: pass try: russell3000.set_value(s,'Ebitda',shy.get_ebitda()) except: pass try: russell3000.set_value(s,'Dividend share',shy.get_dividend_share()) except: pass #try: # russell3000.set_value(s,'Divident yield',shy.get_dividend_yield()) #except: # pass try:
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())
import glob, pandas as pd from yahoo_finance import Share res = [] for f in glob.glob('data/*.csv'): market = f.replace("data/", "").replace(".csv", "") df = pd.read_csv(f) for line in df.iterrows(): res.append((market, line[1].Symbol, line[1].Name)) for (market, symbol, name) in res: if market == 'nyse': x = Share(symbol) print x.get_book_value() print x.get_ebitda() print x.get_earnings_share() print x.get_price_sales()
from Parser.models import EtfInfo, EtfData, StockInfo, StockDetail etfResult = StockInfo.objects.values('ticker', 'name') #for etfIdx in range(0, len(etfResult)) : tickerStr = etfResult[0]['ticker'] share = Share(tickerStr) dateStr = share.get_trade_datetime()[0:11].replace('-','') ma_200Str = convert(share.get_200day_moving_avg()) ma_50Str = convert(share.get_50day_moving_avg()) book_valueStr = convert(share.get_book_value()) volume_avgStr = convert(share.get_avg_daily_volume()) ebitdaStr = convert(share.get_ebitda()) dividend_yieldStr = convert(share.get_dividend_yield()) market_capStr = convert(share.get_market_cap()) year_highStr = convert(share.get_year_high()) year_lowStr = convert(share.get_year_low()) print tickerStr, dateStr, ma_200Str, ma_50Str, book_valueStr, volume_avgStr, ebitdaStr, dividend_yieldStr, market_capStr, year_highStr, year_lowStr # print share.get_change() # print share.get_days_high() # print share.get_days_low() # print share.get_dividend_share() # print share.get_info()
# Fundamentals of stocks using yahoo finance as data source from yahoo_finance import Share tickers = [ 'KMI', 'NNA', 'CAFD', 'GE', 'F', 'MMM', 'TXN', 'BBL', 'GLW', 'STM', 'INTC', 'QCOM' ] for ticker in tickers: stockobj = Share(ticker) price = stockobj.get_price() bookvalue = stockobj.get_book_value() p_e = stockobj.get_price_earnings_ratio() market_cap = stockobj.get_market_cap() price_to_book = float(price) / float(bookvalue) print("\n%s" % ticker) print("price %.2f" % float(price)) print("bookvalue %.2f" % float(bookvalue)) print("price_to_book %.2f" % float(price_to_book)) print("P/E %.2f" % float(p_e)) print("market cap %s" % market_cap)
def loadKeyStatistics (cls, companyID = 'A'): ''' dataset df= pd.DataFrame(columns=['marketCapital','bookValue','ebitda','dividentShare','DividentYield','earningShare', 'BookPrice','SalesPrice','earningsGrowth','earningsRatio', 'symbol', 'date']) ''' yahoo = Share(companyID) yahoo.refresh() try: a = re.search('[a-zA-Z]+', yahoo.get_market_cap()) b = re.search('[a-zA-Z]+', yahoo.get_ebitda()) if a.group(0) is not None: p = re.split('[a-zA-Z]+', yahoo.get_market_cap()) if a.group(0) in 'B': marketCap = float(p[0]) * 10 ** 9 elif a.group(0) in 'M': marketCap = float(p[0]) * 10 ** 6 else: marketCap = -1 print ('Market cap: ' + yahoo.get_market_cap()) else: marketCap = yahoo.get_market_cap() if b.group(0) is not None: p = re.split('[a-zA-Z]+', yahoo.get_ebitda()) if b.group(0) in 'B': ebitda = float(p[0]) * 10 ** 9 elif b.group(0) in 'M': ebitda = float(p[0]) * 10 ** 6 else: ebitda = -1 print ('Ebitda: ' +yahoo.get_ebitda()) else: ebitda = yahoo.get_ebitda() except (TypeError, AttributeError): print ('Missing :' + companyID) e = sys.exc_info()[0] print( "<p>Error: %s</p>" % e ) ebitda = -1.0 marketCap = -1.0 try: company = LoadYahooFinance(symbol = companyID, marketCap = marketCap, bookValue = float(yahoo.get_book_value()), ebitda = ebitda, dividentShare = float(yahoo.get_dividend_share()), dividentYield = float(yahoo.get_dividend_yield()), earningShare = float(yahoo.get_earnings_share()), bookPrice = float(yahoo.get_price_book()), salesPrice = float(yahoo.get_price_sales()), earningsGrowth = float(yahoo.get_price_earnings_growth_ratio()), earningRatio = float(yahoo.get_price_earnings_ratio())) return company except TypeError: print ('Missing :' + companyID) e = sys.exc_info()[0] print( "<p>Error: %s</p>" % e )
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())
# -*- coding: utf-8 -*- """ Created on Fri Jun 10 17:01:18 2016 @author: SMALLON """ IBB = ['AMGN','GILD','CELG','BIIB','REGN','MYL','ILMN','VRTX','ALXN','INCY','BMRN','MDVN','JAZZ', 'ALKS','SHPG','SGEN','ALNY','QGEN','UTHR','TSRO','NBIX','TECH','ENDP','ACAD','AKRX','ICPT','IONS','HZNP','JUNO','CBPO','LGND','PRAH','GRFS','MDCO','KITE','INCR','IPXL','MYGN','OPHT','NKTR','RARE','NVAX','EXEL','PRTA','IRWD','RDUS','BLUE','ONCE','AGIO','LXRX','ARIA','GWPH','PCRX','SAGE','PTLA','MCRB','ALDR','FPRX','INVA','XLRN','HALO','ACOR','ACHN','DEPO','FGEN','DERM','INSY','TBPH','CXRX','SRPT','CHRS','SUPN','MGNX','LMNX','AMAG','GHDX','RGEN','RLYP','CEMP','ADRO','MNTA','DBVT','FMI','AMPH','FOLD','XNCR','EGRX','SGNT','MACK','PACB','INSM','SGYP','ANIP','INO','CERS','RTRX','ATRA','AMRI','EPZM','PDLI','BPMC','CLVS','SCMP','NK','ARRY','XBIT','SCLN','FLML','RPTP','VNDA','LBIO','AERI','MNKD','CLDX','SPPI','OTIC','TLGT','FLXN','ARNA','OMER','GERN','PGNX','ENTA','AMRN','SGMO','RVNC','NDRM', 'BLCM','OMED','TRVN','ARDX','ARWR','CGEN','VSAR','AKBA','ADMS','NLNK','VTAE','COLL','AGTC','NSTG','CNCE','ESPR','IMGN','KPTI','PTCT','IMMU','PETX','ITEK','CCXI','BCRX','DRRX','FOMX','FLKS','ZGNX','RIGL','CRIS','VTL','CMRX','OVAS','RGLS','OSIR','QURE','EGLT','TTPH','NEOS','CASC','IMDZ','CARA','ECYT','AQXP','ANTH','OCUL','ADVM','ADHD','TKAI','SQNM','AFMD','ZFGN','INFI','LIFE','DRNA','CHMA','DNAI','KMPH','OREX','AEGR','USD'] SMBIx = IBB = ['AMGN','GILD','CELG','BIIB','REGN','MYL','ILMN','VRTX','ALXN','INCY','BMRN','MDVN','JAZZ', 'ALKS','SHPG','SGEN','ALNY','QGEN','UTHR','TSRO','NBIX','TECH','ENDP','ACAD','AKRX','ICPT','IONS','HZNP','JUNO','CBPO','LGND','PRAH','GRFS','MDCO','KITE','INCR','IPXL','MYGN','OPHT','NKTR','RARE','NVAX','EXEL','PRTA','IRWD','RDUS','BLUE','ONCE','AGIO','LXRX','ARIA','GWPH','PCRX','SAGE','PTLA','MCRB','ALDR','FPRX','INVA','XLRN','HALO','ACOR','ACHN','DEPO','FGEN','DERM','INSY','TBPH','CXRX','SRPT','CHRS','SUPN','MGNX','LMNX','AMAG','GHDX','RGEN','RLYP','CEMP','ADRO','MNTA','DBVT','FMI','AMPH','FOLD','XNCR','EGRX','SGNT','MACK','PACB','INSM','SGYP','ANIP','INO','CERS','RTRX','ATRA','AMRI','EPZM','PDLI','BPMC','CLVS','SCMP','NK','ARRY','XBIT','SCLN','FLML','RPTP','VNDA','LBIO','AERI','MNKD','CLDX','SPPI','OTIC','TLGT','FLXN','ARNA','OMER','GERN','PGNX','ENTA','AMRN','SGMO','RVNC','NDRM', 'BLCM','OMED','TRVN','ARDX','ARWR','CGEN','VSAR','AKBA','ADMS','NLNK','VTAE','COLL','AGTC','NSTG','CNCE','ESPR','IMGN','KPTI','PTCT','IMMU','PETX','ITEK','CCXI','BCRX','DRRX','FOMX','FLKS','ZGNX','RIGL','CRIS','VTL','CMRX','OVAS','RGLS','OSIR','QURE','EGLT','TTPH','NEOS','CASC','IMDZ','CARA','ECYT','AQXP','ANTH','OCUL','ADVM','ADHD','TKAI','SQNM','AFMD','ZFGN','INFI','LIFE','DRNA','CHMA','DNAI','KMPH','OREX','AEGR','USD'] from yahoo_finance import Share for i in IBB: t = Share(i) book = float(t.get_book_value()) if (book > 5.00): print(i,book,"Book value more than 5b") from yahoo_finance import Share for i in IBB: t = Share(i) P2S = (t.get_price_sales()) print(P2S)
# Determine functionality from yahoo_finance import Share tesla = Share('TSLA') print tesla.get_price() print tesla.get_market_cap() print "get_book_value:", tesla.get_book_value() print "get_ebitda:", tesla.get_ebitda() print "get_dividend_share:", tesla.get_dividend_share() print "get_dividend_yield:", tesla.get_dividend_yield() print "get_earnings_share:", tesla.get_earnings_share() print "get_days_high:", tesla.get_days_high() print "get_days_low:", tesla.get_days_low() print "get_year_high:", tesla.get_year_high() print "get_year_low:", tesla.get_year_low() print "get_50day_moving_avg:", tesla.get_50day_moving_avg() print "get_200day_moving_avg:", tesla.get_200day_moving_avg() print "get_price_earnings_ratio:", tesla.get_price_earnings_ratio() print "get_price_earnings_growth_ratio:", tesla.get_price_earnings_growth_ratio( ) print "get_price_sales:", tesla.get_price_sales() print "get_price_book:", tesla.get_price_book() print "get_short_ratio:", tesla.get_short_ratio() print "get_trade_datetime:", tesla.get_trade_datetime() # "a:", print tesla.get_historical(start_date, end_date) # "a:", print tesla.get_info() print "get_name:", tesla.get_name() print "refresh:", tesla.refresh() print "get_percent_change_from_year_high:", tesla.get_percent_change_from_year_high( )
import glob, pandas as pd from yahoo_finance import Share res = [] for f in glob.glob('data/*.csv'): market = f.replace("data/","").replace(".csv","") df = pd.read_csv(f) for line in df.iterrows(): res.append((market, line[1].Symbol, line[1].Name)) for (market,symbol,name) in res: if market=='nyse': x = Share(symbol) print x.get_book_value() print x.get_ebitda() print x.get_earnings_share() print x.get_price_sales()
from yahoo_finance import Share #yahoo = Share('YHOO') #yahoo = Share('SPXC') yahoo = Share('TFM') #yahoo = Share('INDU') #INDEXSP #yahoo = Share('NDX') print yahoo print yahoo.get_open() #'36.60' print yahoo.get_price() print yahoo.get_price_earnings_ratio() print 'get_dividend_share: ',yahoo.get_dividend_share() print 'get_dividend_yield: ',yahoo.get_dividend_yield() print 'get_earnings_share: ',yahoo.get_earnings_share() print 'get_price_earnings_ratio: ',yahoo.get_price_earnings_ratio() print 'get_price_earnings_growth_ratio: ',yahoo.get_price_earnings_growth_ratio() print 'get_year_high: ',yahoo.get_year_high() print 'get_year_low: ',yahoo.get_year_low() print 'get_days_high: ',yahoo.get_days_high() print 'get_days_low: ',yahoo.get_days_low() print 'get_ebitda: ',yahoo.get_ebitda() print 'get_book_value: ',yahoo.get_book_value() #'36.84' #print yahoo.get_trade_datetime() #'2014-02-05 20:50:00 UTC+0000' #get_avg_daily_volume()
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' write_to_file(high_low_directory, high_low_text) write_to_file(open_close_directory, open_close_text) write_to_file(volume_directory, volume_text) ratio_text = "name\t" + "value\n" if stock.get_change() != None: name = "Change" value = str(stock.get_change()) ratio_text += name + "\t" + value + "\n" if stock.get_dividend_share() != None: name = "Dividend Share" value = str(stock.get_dividend_share()) ratio_text += name + "\t" + value + "\n" if stock.get_dividend_yield() != None: name = "Divident Yield" value = str(stock.get_dividend_yield()) ratio_text += name + "\t" + value + "\n" if stock.get_earnings_share() != None: name = "Earning Share" value = str(stock.get_earnings_share()) ratio_text += name + "\t" + value + "\n" if stock.get_price_earnings_ratio() != None: name = "Price Earning" value = str(stock.get_price_earnings_ratio()) ratio_text += name + "\t" + value + "\n" if stock.get_price_earnings_growth_ratio() != None: name = "Price Earning Growth" value = str(stock.get_price_earnings_growth_ratio()) ratio_text += name + "\t" + value + "\n" if stock.get_price_sales() != None: name = "Price Sales" value = str(stock.get_price_sales()) ratio_text += name + "\t" + value + "\n" if stock.get_price_book() != None: name = "Price Book" value = str(stock.get_price_book()) ratio_text += name + "\t" + value + "\n" if stock.get_short_ratio() != None: name = "Short" value = str(stock.get_short_ratio()) ratio_text += name + "\t" + value + "\n" ratio_directory = '/data/ratio.tsv' write_to_file(ratio_directory, ratio_text)