def get_rate(args_dict): amt = args_dict['amt'] b_curr = args_dict['b_curr'] d_curr = args_dict['d_curr'] c = args_dict['currency'] n = args_dict['name'] # check whether we need to find ISO 4217 codes if c or n: currency_options = (c, n) names = b_curr, d_curr b_curr, d_curr = parse_args(currency_options, names) ISO_str = b_curr + d_curr # Yahoo Finance API call currency = Currency(ISO_str) trade_time = currency.get_trade_datetime() current_rate = float(currency.get_rate()) value = amt * current_rate # modify args dictionary with data needed for display args_dict['b_curr_updated'] = b_curr args_dict['d_curr_updated'] = d_curr args_dict['value'] = value args_dict['current_rate'] = current_rate args_dict['trade_time'] = trade_time return args_dict
def _getValue(symbol): ret = {} cur = Currency(symbol) ret['rate'] = cur.get_rate() if ret['rate']: time = datetime.datetime.strptime(cur.get_trade_datetime(), '%Y-%m-%d %H:%M:%S %Z%z') ret['tradeDateTime'] = int(time.timestamp()) return ret return None
def test_eurpln_date(self): eur_pln = Currency('EURPLN') try: datetime.datetime.strptime(eur_pln.get_trade_datetime(), "%Y-%m-%d %H:%M:%S %Z%z") except ValueError as v: if "bad directive" in str(v): raise SkipTest("datetime format checking requires the %z directive.") else: raise
def test_eurpln_date(self): eur_pln = Currency('EURPLN') try: datetime.datetime.strptime(eur_pln.get_trade_datetime(), "%Y-%m-%d %H:%M:%S %Z%z") except ValueError as v: if "bad directive" in str(v): raise SkipTest( "datetime format checking requires the %z directive.") else: raise
# Fix bug: https://github.com/ranaroussi/fix-yahoo-finance (The future, I think that the bug is solved) # pip install fix_yahoo_finance --upgrade --no-cache-dir print("+++++pandas_datareader+++++") from pandas_datareader import data as pdr import fix_yahoo_finance as yf # <== that's all it takes :-) # For Stock of Thailand, the symbol must be followed with '.BK' # download dataframe ptt = pdr.get_data_yahoo("PTT.BK", start="2017-01-01", end="2017-04-30") print(ptt.tail()) print() # Forth example # How to install yahoo_finance package # Reference: https://pypi.python.org/pypi/yahoo-finance # pip install yahoo_finance from yahoo_finance import Share yahoo = Share("YHOO") print("\n++++YHOO stock++++") print (yahoo.get_open()) print (yahoo.get_price()) print (yahoo.get_trade_datetime()) from yahoo_finance import Currency eur_pln = Currency('EURPLN') print("\n++++Currency of EURPLN++++") print (eur_pln.get_bid()) print (eur_pln.get_ask()) print (eur_pln.get_rate()) print (eur_pln.get_trade_datetime())
# get_year_high() # get_year_low() # get_50day_moving_avg() # get_200day_moving_avg() # get_price_earnings_ratio() # get_price_earnings_growth_ratio() # get_price_sales() # get_price_book() # get_short_ratio() # get_trade_datetime() # get_historical(start_date, end_date) # get_info() # refresh() from yahoo_finance import Currency eur_pln = Currency('EURPLN') print eur_pln.get_bid() print eur_pln.get_ask() print eur_pln.get_rate() print eur_pln.get_trade_datetime() eur_pln.refresh() print eur_pln.get_rate() print eur_pln.get_trade_datetime() # get_bid() # get_ask() # get_rate() # get_trade_datetime() # refresh()
data = data = quandl.get(tickers,start_date=start, end_date=end) data.tail(1).T s=data[["CHRIS/SHFE_AU1 - Close","YAHOO/INDEX_HUI - Adjusted Close","CHRIS/CME_GC1 - Last"]] s.apply(lambda x: (x - np.mean(x)) / (np.max(x) - np.min(x)), axis=0).ix['2014':].plot(color=tableau20) #============================================================================== # #============================================================================== import pandas_datareader.data as web df = web.DataReader("EURUSD=x", 'yahoo', start, end) from yahoo_finance import Currency fx = Currency('EURUSD') fx.get_bid() fx.get_ask() fx.get_rate() fx.get_trade_datetime() fx.get_historical('2014-04-25', '2014-04-29') fx.data_set
from yahoo_finance import Share yahoo = Share('YHOO') yahoo.get_open() yahoo.get_price() yahoo.get_trade_datetime() yahoo.refresh() #Refresh data from market yahoo.get_historical('2014-04-25', '2014-04-29') from yahoo_finance import Currency eur_pln = Currency('EURPLN') eur_pln.get_bid() eur_pln.get_ask() eur_pln.get_rate() eur_pln.get_trade_datetime() eur_pln.refresh() #reading google finance data import pandas_datareader.data as web import datetime start = datetime.datetime(2010, 1, 1) end = datetime.datetime(2013, 1, 27) f = web.DataReader("F", 'google', start, end) f.ix['2010-01-04'] #reading yahoo finance data #not working import pandas_datareader.data as web import datetime
#!/usr/bin/env python3 # Documentation at https://pypi.python.org/pypi/yahoo-finance from yahoo_finance import Share share_apple = Share("AAPL") print(share_apple.get_name()) print(share_apple.get_price()) print(share_apple.get_trade_datetime()) print(share_apple.get_currency()) print(share_apple.get_200day_moving_avg()) share_apple.refresh() print(share_apple.get_price()) print("---") from yahoo_finance import Currency btc_in_eur = Currency("BTCEUR") print(btc_in_eur.get_rate()) print(btc_in_eur.get_trade_datetime()) btc_in_eur.refresh() print(btc_in_eur.get_rate())