def test_get_quote_comma_name(self): _yahoo_codes.update({'name': 'n'}) try: df = web.get_quote_yahoo(['RGLD']) except ConnectionError: pytest.xfail(reason=XFAIL_REASON) del _yahoo_codes['name'] assert df['name'][0] == 'Royal Gold, Inc.'
def test_get_quote_string(self): _yahoo_codes.update({'MarketCap': 'j1'}) try: df = web.get_quote_yahoo('GOOG') except ConnectionError: pytest.xfail(reason=XFAIL_REASON) assert not pd.isnull(df['MarketCap'][0])
def import_stock_market_data(): import time from datetime import datetime import pandas_datareader.data as web from pandas_datareader.yahoo.quotes import _yahoo_codes _yahoo_codes.update({'MarketCap': 'j1'}) _yahoo_codes.update({'LastTradeDate': 'd1'}) stock_queryset = Stock.objects.filter(stock_code__endswith='.asx') for stock in stock_queryset: yahoo_code = stock.stock_code[0:3].upper() + '.AX' stock_quote = web.get_quote_yahoo(yahoo_code) if not stock_quote.empty: try: last_trade_date_str = stock_quote.loc[yahoo_code, 'LastTradeDate'] if last_trade_date_str != 'N/A': stock.market_data_date = datetime.strptime( last_trade_date_str, '%m/%d/%Y') market_cap_str = stock_quote.loc[yahoo_code, 'MarketCap'] market_cap_unit = market_cap_str[-1:] if market_cap_unit == 'M': stock.market_value = float(market_cap_str[:-1]) * 1e6 elif market_cap_unit == 'B': stock.market_value = float(market_cap_str[:-1]) * 1e9 else: raise Exception( 'Unknown yahoo stock market value unit - {}'.format( market_cap_str)) stock.save() except Exception as exception: print(exception) continue # Do not do too quickly, or the Yahoo finance may block us time.sleep(0.01)
def test_get_quote_comma_name(self): _yahoo_codes.update({'name': 'n'}) df = web.get_quote_yahoo(['RGLD']) del _yahoo_codes['name'] assert df['name'][0] == 'Royal Gold, Inc.'
def test_get_quote_string(self): _yahoo_codes.update({'MarketCap': 'j1'}) df = web.get_quote_yahoo('GOOG') assert not pd.isnull(df['MarketCap'][0])
def test_get_quote_comma_name(self): _yahoo_codes.update({'name': 'n'}) df = web.get_quote_yahoo(['RGLD']) del _yahoo_codes['name'] self.assertEqual(df['name'][0], 'Royal Gold, Inc.')
def test_get_quote_string(self): _yahoo_codes.update({'MarketCap': 'j1'}) df = web.get_quote_yahoo('GOOG') self.assertFalse(pd.isnull(df['MarketCap'][0]))
- Figure out why posterior covariance is so small """ import cvxopt as opt import datetime as dt import numpy as np import pandas as pd import pandas_datareader.data as data import re import requests from cvxopt import blas, solvers from pandas_datareader.yahoo.quotes import _yahoo_codes from bs4 import BeautifulSoup # setup _yahoo_codes.update({'Market Cap': 'j1'}) np.random.seed(123) solvers.options['show_progress'] = False # Various functions def posterior_return_100_one_view(prior_returns, risk_multiplier, returns_cov, view_link_vector, view): """ """ factor1 = risk_multiplier * returns_cov @ view_link_vector factor2 = np.linalg.inv( view_link_vector.T @ (risk_multiplier * returns_cov) @ view_link_vector) factor3 = view - view_link_vector.T @ prior_returns
# -*- coding: utf-8 -*- """ Created on Fri May 12 23:54:33 2017 @author: Aniwat """ import csv import pandas_datareader.data as data from pandas_datareader.yahoo.quotes import _yahoo_codes stocklist = ['advanc.bk'] #http://www.jarloo.com/yahoo_finance/ #https://greenido.wordpress.com/2009/12/22/yahoo-finance-hidden-api/ _yahoo_codes.update({'Market Cap': 'j1'}) _yahoo_codes.update({'Div Yield': 'y'}) _yahoo_codes.update({'Bid': 'b'}) _yahoo_codes.update({'Ask': 'a'}) _yahoo_codes.update({'Prev Close': 'p'}) _yahoo_codes.update({'Open': 'o'}) _yahoo_codes.update({'1 yr Target Price': 't8'}) _yahoo_codes.update({'Earnings/Share': 'e'}) _yahoo_codes.update({"Day’s Range": 'm'}) _yahoo_codes.update({'52-week Range': 'w'}) _yahoo_codes.update({'Volume': 'v'}) _yahoo_codes.update({'Avg Daily Volume': 'a2'}) _yahoo_codes.update({'EPS Est Current Year': 'e7'}) _yahoo_codes.update({'EPS Est Next Quarter': 'e9'}) data.get_quote_yahoo(stocklist).to_csv('test.csv',