• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python yahoo_finance.Share类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中yahoo_finance.Share的典型用法代码示例。如果您正苦于以下问题:Python Share类的具体用法?Python Share怎么用?Python Share使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Share类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: generateData

    def generateData(self):
        global StartingDate
        global DataSize
        i = datetime.datetime.now()
        EndingDate = '%s-%s-%s' % (i.year,i.month,i.day)
        stock = Share(Stock_name)
        data = stock.get_historical(StartingDate,EndingDate)
        file = open('stock_data', 'w')
        closes = [c['Close'] for c in data]
        opens = [o['Open'] for o in data]
        oArray = []
        cArray = []

        for c in closes:
            cArray.append(c)

        for o in opens:
            oArray.append(o)

        for x in range(len(data)-2):
            #  %Difference, Next Day %Difference, Money Made Holding for a Day
            file.write(str((float(cArray[x])-float(oArray[x+1]))/100) + ' ' + str((float(cArray[x+1]) - float(oArray[x+2]))/100) + ' ' + str((float(oArray[x]) - float(oArray[x+1]))) + '\n')

            self.dayChange.append((float(cArray[x])-float(oArray[x+1]))/100)
            self.nextDayChange.append((float(cArray[x+1]) - float(oArray[x+2]))/100)
            self.profit.append(float(oArray[x]) - float(oArray[x+1]))
        #Makes sure the population size is
        DataSize = len(self.dayChange)
        file.close()
开发者ID:jaredvu,项目名称:StocksAI,代码行数:29,代码来源:stockMarket_GenAlg.py


示例2: start_stock

def start_stock():
    # Busca as informações do pregão

    data_corrente = start_data()
    data_exec = data_corrente[0:4] + '-' + data_corrente[4:6] + '-' + data_corrente[6:8]
    lista_acoes = cria_lista()
    #lista_acoes = ['PETR3.SA', 'VALE3.SA', 'BBAS3.SA']
    nome_arq = 'pregao' + str(data_exec) + '.txt'
    arquivo = open(nome_arq, 'w')
    texto = ''
    informacao = None

    for acao in lista_acoes:
        try:
            yahoo = Share(str(acao))
            informacao = yahoo.get_historical(data_exec,data_exec)
        except:
            pass
        if informacao :
            simbolo = informacao[0]['Symbol'].split('.SA', 1)[0]
            try:
                fechamento = informacao[0]['Close']
            except KeyError:
                fechamento = ''
            try:
                volume = informacao[0]['Volume']
            except KeyError:
                volume = ''
            texto = simbolo + ';' + fechamento + ';' + volume + "\n"
            arquivo.writelines(texto)

    arquivo.close()
    return "Registros salvos no arquivo: " + nome_arq
开发者ID:marciosian,项目名称:stockexchange,代码行数:33,代码来源:stockexchange.py


示例3: report_current_from_yahoo

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)
开发者ID:sp500,项目名称:investment,代码行数:7,代码来源:download_gf_data.py


示例4: create_files

def create_files():
        for i in range(0,TIME_IN_MIN*60/TIME_BETWEEN_ITERATIONS):
	    reader=csv.DictReader(open('Yahoo_symbols.csv','rb'))
     	    for sym in reader:

			company=sym["COMPANY"]
			symbol=sym["SYMBOL"]
			while(1):
			   try:
				share_name=Share(symbol)
				if share_name:
					break
			   except:
				time.sleep(1)

			filename = "./Q4_files/"+company+".csv"
			try:
				file=open(filename,"a")
			except:
				file=open(filename,"w")
				file.write("Time,Price")

			timestamp = share_name.get_trade_datetime()
			price = share_name.get_price()
			writer = csv.DictWriter(file, fieldnames=["Time","Price"], delimiter=",", lineterminator="\n")
			writer.writerow({"Time":timestamp ,"Price":price})		
	    time.sleep(TIME_BETWEEN_ITERATIONS)	

        file.close()
开发者ID:maanitmehra,项目名称:big-data,代码行数:29,代码来源:Q4.py


示例5: update_stock

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))
开发者ID:murali44,项目名称:WinkNimbus,代码行数:7,代码来源:app.py


示例6: get_stock_df

def get_stock_df(ticker,start_date,end_date):
    """Get stock dataframe"""
    share = Share(ticker)
    share_hist = share.get_historical(start_date,end_date)
    len_share_hist = len(share_hist)
    dates = ['']*len_share_hist
    open = [0.]*len_share_hist
    close = [0.]*len_share_hist
    high = [0.]*len_share_hist
    low = [0.]*len_share_hist
    volume = [0.]*len_share_hist
    adj_close = [0.]*len_share_hist
    for i in range(len_share_hist):
        dates[i] = share_hist[i][DATE_STR]
        open[i] = float(share_hist[i][OPEN_STR])
        close[i] = float(share_hist[i][CLOSE_STR])
        adj_close[i] = float(share_hist[i][ADJ_CLOSE_STR])
        high[i] = float(share_hist[i][HIGH_STR])
        low[i] = float(share_hist[i][LOW_STR])
        volume[i] = float(share_hist[i][VOLUME_STR])
    df = pd.DataFrame(open, index = pd.to_datetime(dates), columns=[OPEN_STR])
    df[CLOSE_STR] = close
    df[ADJ_CLOSE_STR] = adj_close
    df[HIGH_STR] = high
    df[LOW_STR] = low
    df[VOLUME_STR] = volume
    df.index.name = DATE_STR
    return df.sort_index()
开发者ID:as4456,项目名称:Technical-Factor-Model,代码行数:28,代码来源:factor_model_modified_upd.py


示例7: data_frame_companies_prices

    def data_frame_companies_prices(list_companies,a,b):

        # Es una funcion que toma una lista de empresas (codificadas por yahoo.finance) y valor minimo y maximo
        # de la distribucion uniforme que sigue la diferencia entre el bid y el ask para las empresas.



        list_index=["ask5","ask4","ask3","ask2","ask1","bid1","bid2","bid3","bid4","bid5"]
        companies_prices=pd.DataFrame(index=list_index)

        for i in list_companies:

            company = Share(i)
            open_price=company.get_price()
            open_price=float(open_price)
            a=float(a)
            b=float(b)
            random1=(np.random.rand(1)+(a/b-a))/(1.0/b-a)

            first_ask_price=open_price+(round(random1,2))/2.0
            ask_array=np.array([first_ask_price+0.04,first_ask_price+0.03,first_ask_price+0.02,first_ask_price+0.01,first_ask_price])

            first_bid_price=open_price-(round(random1,2))/2.0
            bid_array=np.array([first_bid_price+0.04,first_bid_price+0.03,first_bid_price+0.02,first_bid_price+0.01,first_bid_price])

            ask_bid_array=np.concatenate((ask_array,bid_array))

            companies_prices[i]=ask_bid_array

        return companies_prices
开发者ID:romcra,项目名称:settings_package,代码行数:30,代码来源:init.py


示例8: fetch_data

def fetch_data(dt_from, dt_to, sym):
    min_dt_from = dt.datetime(2014, 1, 1)
    assert(dt_from >= min_dt_from)
    r = TStockHistory.find_one(
        {'Symbol': sym}, projection={'Date': 1}, sort=[('Date', pymongo.DESCENDING)])
    if not r:
        fetch_dt_from = min_dt_from
    elif r['Date'] < dt_to:
        fetch_dt_from = r['Date'] + dt.timedelta(days=1)
        if fetch_dt_from > dt_to:
            fetch_dt_from = None
    else:
        fetch_dt_from = None
    if fetch_dt_from:
        f = '%d-%d-%d' % (
            fetch_dt_from.year, fetch_dt_from.month, fetch_dt_from.day)
        t = '%d-%d-%d' % (dt_to.year, dt_to.month, dt_to.day)
        print('fetch %s from network...' % (sym))
        share = Share(sym)
        docs = share.get_historical(f, t)
        if docs:
            for r in docs:
                for k in ['Adj_Close', 'High', 'Low', 'Close', 'Volume']:
                    r[k] = np.float(r[k])
                r['Date'] = dateutil.parser.parse(r['Date'])
            TStockHistory.insert_many(docs)
    data = TStockHistory.find(
        {'Symbol': sym, 'Date': {'$gte': dt_from, '$lte': dt_to}})
    rs = filter(lambda x: 'placeholder' not in x, [u for u in data])
    return rs
开发者ID:EricDoug,项目名称:tomb,代码行数:30,代码来源:util.py


示例9: main

def main():
    start_date = '2007-01-01'
    end_date = '2015-08-31'
    plotly_name = 'username'
    plotly_api_key = 'api-key'

    # get_historical is part of the yahoo-finance module
    nflx = Share('nflx')
    nflx_prices = nflx.get_historical(start_date, end_date)

    # how you can just extract the dates only
    nflx_dates = [x['Date'] for x in nflx_prices]

    # nflx_prices is currently sorted by dates because thats how the module gave them
    sorted_by_price = sorted(nflx_prices, key=lambda x: x['Adj_Close'], reverse=True)

    # say you wanted multiple stock prices
    ticker_symbols = ['hrl', 'tsn', 'gis', 'k']
    foods = {}

    if do_plot:
        plot_stock(plotly_name, plotly_api_key, nflx_prices, 'nflx')

    for symbol in ticker_symbols:
        foods[symbol] = Share(symbol).get_historical(start_date, end_date)
        foods[symbol].sort(key=lambda x: x['Date'])
        dates = [x['Date'] for x in foods[symbol]]
        prices = [x['Adj_Close'] for x in foods[symbol]]
        if do_plot:
            add_trace(dates, prices, symbol)
开发者ID:tuftsenigma,项目名称:PublicDataScraping,代码行数:30,代码来源:stock_csv_demo.py


示例10: getStockData

def getStockData(theTicker):
    global startDate
    print("Getting Data for ... " + theTicker)
    stock = Share(theTicker)
    print(startDate)
    data = stock.get_historical(startDate, DateNow)
    for d in data:
        tmp = []
        volume = int(d['Volume'])
        adjclose = float(d['Adj_Close'])
        high = float(d['High'])
        low = float(d['Low'])
        close = float(d['Close'])
        date = d['Date']
        open = float(d['Open'])
        # newDate = datetime.strptime(date, "%Y-%m-%d")
        tmp.append(date)
        tmp.append(open)
        tmp.append(high)
        tmp.append(low)
        tmp.append(close)
        tmp.append(adjclose)
        tmp.append(volume)
        givenStock.append(tmp)
    return givenStock
开发者ID:Vaibhav,项目名称:Stock-Analysis,代码行数:25,代码来源:CompareToSPY.PY


示例11: get_stock_info

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
开发者ID:HugoZhang33,项目名称:StockTicker,代码行数:26,代码来源:views.py


示例12: lookup_by_symbol

  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
开发者ID:havellay,项目名称:monitor,代码行数:25,代码来源:Symbol.py


示例13: stock_Prices

def stock_Prices():
    # exit if the output already existed
    # if os.path.isfile('./input/stockPrices.json'):
    #     sys.exit("Prices data already existed!")

    priceSet = {}
    fin = open('./input/tickerList.csv')
    for num, line in enumerate(fin):
        line = line.strip().split(',')
        ticker, name, exchange, MarketCap = line
        if 1:
            print(num, ticker)
            yahoo = Share(ticker)
            time.sleep(np.random.poisson(3))
            prices = yahoo.get_historical('2005-01-01', '2020-01-01')
            priceDt = {}
            for i in range(len(prices)):
                date = ''.join(prices[i]['Date'].split('-'))
                priceDt[date] = round(log(float(prices[i]['Close']) / float(prices[i]['Open'])), 6)
            priceSet[ticker] = priceDt
        #except:
            #continue

    with open('./input/stockPrices.json', 'w') as outfile:
        json.dump(priceSet, outfile, indent=4)
开发者ID:valeman,项目名称:Sentiment-Analysis-in-Event-Driven-Stock-Price-Movement-Prediction,代码行数:25,代码来源:crawler_stockPrices.py


示例14: SelectStock

 def SelectStock(self):
     wb = Workbook()
     ws = wb.active
     with open('export.csv',newline='') as f:
         reader = csv.reader(f)
         index = 2
         title = ["代號","名稱","股價","本益比","EPS"]
         for x in range(0,5,1):
             ws.cell(row=1,column=x+1,value=title[x])
         for row in reader:
             if row!=[]:
                 try:
                     if int(row[0]) < 10000:
                     #    print(row[2])
                         if "-" not in (row[2]) and float(row[2]) < 20:
                          #   print(row)
                             Query = Share(row[0]+'.TW')
                             #print(float(Query.get_earnings_share()))     
                             #print(float(Query.get_open()))
                             #print("******************")
                             if float(Query.get_open()) >= 20 and float(Query.get_open()) <= 90 and float(Query.get_earnings_share())>1.2:
                                 print(row)
                                 ws.cell(row=index , column=1 , value = row[0])
                                 ws.cell(row=index , column=2 , value = row[1])
                                 ws.cell(row=index , column=3 , value = Query.get_open())
                                 ws.cell(row=index , column=4 , value = row[2])
                                 ws.cell(row=index , column=5 , value = Query.get_earnings_share())
                                 index = index + 1
             
                                 
                 except:
                     pass    
         wb.save("Final.xlsx")        
开发者ID:sheettrait,项目名称:Stock_Python,代码行数:33,代码来源:Main.py


示例15: get_data

def get_data(stock,start,end):
    data = Share(stock)
    try:
        data = pd.DataFrame(data.get_historical(start_date=start,end_date=end))
    except Exception as e:
        f = open('log.txt',mode='a')
        f.write(stock+'\n')
        f.write(str(e)+'\n')
        return pd.DataFrame()

    try:
        data.index = data.Date
    except Exception as e:
        f = open('log.txt', mode='a')
        f.write(stock+'\n')
        f.write(str(e)+'\n')
        return pd.DataFrame()

    data = data.drop(['Date','Symbol'],axis=1)
    data = data.sort_index()
    for i in data.columns:
        data[i] = data[i].astype(np.float)
    #data['Adj_Open'] = 0
    #data['Adj_High'] = 0
    #data['Adj_Low'] = 0
    #for i in range(len(data)):
    #    k = data['Adj_Close'][i] / data['Close'][i]
    #    data.loc[i:i+1,'Adj_Open'] = k*data['Open'][i]
    #    data.loc[i:i + 1, 'Adj_High'] = k * data['High'][i]
    #    data.loc[i:i + 1, 'Adj_Low'] = k * data['Low'][i]
    data['Symbol'] = stock
    return data
开发者ID:999726541,项目名称:Strategy_Analysis,代码行数:32,代码来源:yahoo_pitch.py


示例16: check_buy

 def check_buy(self):
     #one-time buy
     if self.owned_shares != 0:
         return False
     share = Share(self.code)
     avg50 = self.get_short_moving_avg()
     avg200 = self.get_long_moving_avg()
     if avg50 == -1.0 or avg200 == -1.0:
         self.log('Short or Long moving average cannot be obtained due to yahoo API error')
         return 0
     
     current_price_u = share.get_price()
     if current_price_u is None:
         self.log('Current Price is None for Stock')
         return 0
     
     current_price = float(current_price_u)
     if avg50 > avg200:
         #trend change, buy
         buy_count = self.how_many_shares_to_buy(current_price)
         if buy_count != 0:
             if buy(self, buy_count, current_price) == True:
                 self.owned_shares = buy_count
                 self.bought_value = float(current_price * self.owned_shares)
         return self.owned_shares
     return 0
开发者ID:nfullersl,项目名称:Outsider,代码行数:26,代码来源:Outsider.py


示例17: retrieveQuoteFromYahoo

def retrieveQuoteFromYahoo(symbol,start,end):        
    share = Share(symbol)  
    quoteList = share.get_historical(start,end)
    quoteDict = {}
    for quote in quoteList:
        quoteDict[quote['Date']] = float(quote['Adj_Close'])        
    return quoteDict
开发者ID:chongwee83,项目名称:MultiFactorModel,代码行数:7,代码来源:MultiFactorModel.py


示例18: check_sell

    def check_sell(self):
        #UNCOMMENT WHEN USING ACTUAL DATA
        if self.owned_shares == 0:
            return False
        
        share = Share(self.code)

        current_price_u = share.get_price()
        if current_price_u is None:
            self.log('Current Price is None for Stock')
            return 0
        
        current_price = float(current_price_u)
        
        #UNCOMMENT WHEN USING ACTUAL DATA
        if self.bought_value < current_price:
            return False
        
        avg50 = self.get_short_moving_avg()
        avg200 = self.get_long_moving_avg()
        if avg50 < avg200:
            #trend change, buy
            sell(self, self.owned_shares,current_price)
            return True
        return False
开发者ID:nfullersl,项目名称:Outsider,代码行数:25,代码来源:Outsider.py


示例19: get_stock_price_and_volume

def get_stock_price_and_volume(symbol, start_date, end_date, dates):
	share = Share(symbol)
	hist_data = share.get_historical(start_date, end_date)
	hist_data.reverse()
	volume = []
	price = []
	i = 0
	for d in dates:
		if i < len(hist_data):
			if (hist_data[i]['Date'] == d):
				# Weekday
				price.append(hist_data[i]['Close'])
				volume.append(hist_data[i]['Volume'])
				i += 1
			else:
				# Weekend
				price.append(0)
				volume.append(0)
		else:
			# Get the current price and volume instead from historical data
			price.append(share.get_price())
			volume.append(share.get_volume())
	if len(dates) != len(volume) and len(dates) != len(price):
		print 'Dates and volume and/or price lists are not of same lenght!'
	return [price, volume]
开发者ID:benzemann,项目名称:TwitterStockAnalyzer,代码行数:25,代码来源:stock_data_downloader.py


示例20: getDifferencePercentage

	def getDifferencePercentage(self):
	 	closing = []
	 	shareName = Share(self.company)
	 	self.getTimeStamp()
	 	startDate=''
	 	endDate=''
	 	hist=''
	 	for t in self.times:
	 		todayTimeStamp = t
	 		yesterdayTimeStamp = t-86400
	 		startDate = str(datetime.datetime.fromtimestamp(todayTimeStamp).strftime('%Y-%m-%d'))
	 		yesterdayDate=str(datetime.datetime.fromtimestamp(yesterdayTimeStamp).strftime('%Y-%m-%d'))
	 		todayHist = shareName.get_historical(startDate, startDate)
	 		yesterdayHist = shareName.get_historical(yesterdayDate,yesterdayDate)
	 		while(len(todayHist)==0):
	 			todayTimeStamp = todayTimeStamp+86400
	 			startDate = str(datetime.datetime.fromtimestamp(todayTimeStamp).strftime('%Y-%m-%d'))
	 			todayHist = shareName.get_historical(startDate, startDate)
	 		while(len(yesterdayHist)==0):
	 			yesterdayTimeStamp= yesterdayTimeStamp-86400
				yesterdayDate=str(datetime.datetime.fromtimestamp(yesterdayTimeStamp).strftime('%Y-%m-%d'))
	 			yesterdayHist = shareName.get_historical(yesterdayDate,yesterdayDate)
	 			
	 		closingPriceToday = float(todayHist[0]['Close'])
	 		closingPriceYesterday = float(yesterdayHist[0]['Close'])
	 		difference = (float(closingPriceYesterday) - float(closingPriceToday))*100.0/float(closingPriceYesterday)
	 		diff2 = float(format(difference, '.3f'))
	 		closing.append(diff2)
	 	self.differencePercentage = closing
	 	return closing
开发者ID:ryanstrat,项目名称:stock-predictions,代码行数:30,代码来源:NewsAPI.py



注:本文中的yahoo_finance.Share类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python yahooweather.YahooWeather类代码示例发布时间:2022-05-26
下一篇:
Python base.factory函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap