예제 #1
0
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
예제 #2
0
from yahoo_finance import Share
from pprint import pprint

yahoo = Share('YHOO')

print(yahoo.get_open())
print(yahoo.get_trade_datetime())
print(yahoo.get_last_trade_with_time())


print(yahoo.get_historical('2017-03-03', '2017-03-07'))
#### the two dates specified above are "start date" and "end date". so you'll get all the historical data in btwn
#### returned data will be in dictionary format (more like JSON data format)

# use a more readable output format
pprint(yahoo.get_historical('2017-03-03', '2017-03-07'))

/Users/yisilala/PycharmProjects/stock/DataRetrievingYahoo.py
예제 #3
0
print "get_percent_change_from_year_low:", tesla.get_percent_change_from_year_low(
)
print "get_change_from_year_low:", tesla.get_change_from_year_low()
print "get_change_from_year_high:", tesla.get_change_from_year_high()
print "get_percent_change_from_200_day_moving_average:", tesla.get_percent_change_from_200_day_moving_average(
)
print "get_change_from_200_day_moving_average:", tesla.get_change_from_200_day_moving_average(
)
print "get_percent_change_from_50_day_moving_average:", tesla.get_percent_change_from_50_day_moving_average(
)
print "get_change_from_50_day_moving_average:", tesla.get_change_from_50_day_moving_average(
)
print "get_EPS_estimate_next_quarter:", tesla.get_EPS_estimate_next_quarter()
print "get_EPS_estimate_next_year:", tesla.get_EPS_estimate_next_year()
print "get_ex_dividend_date:", tesla.get_ex_dividend_date()
print "get_EPS_estimate_current_year:", tesla.get_EPS_estimate_current_year()
print "get_price_EPS_estimate_next_year:", tesla.get_price_EPS_estimate_next_year(
)
print "get_price_EPS_estimate_current_year:", tesla.get_price_EPS_estimate_current_year(
)
print "get_one_yr_target_price:", tesla.get_one_yr_target_price()
print "get_change_percent_change:", tesla.get_change_percent_change()
print "get_dividend_pay_date:", tesla.get_dividend_pay_date()
print "get_currency:", tesla.get_currency()
print "get_last_trade_with_time:", tesla.get_last_trade_with_time()
print "get_days_range:", tesla.get_days_range()
print "get_year_range:", tesla.get_year_range()

# http://stackoverflow.com/questions/24233385/pulling-yahoo-finance-data-using-python
# http://chartapi.finance.yahoo.com/instrument/1.0/TSLA/chartdata;type=quote;range=1y/csv
예제 #4
0
from yahoo_finance import Share
from rtstock.stock import Stock
from googlefinance import getQuotes
import json

Stock_One = 'tsla'

# Get the Data from rtstock
rtstock_stock = Stock(Stock_One)
rtstock_latestprice = rtstock_stock.get_latest_price()
print("rtstock returns this value:", rtstock_latestprice)

# Get the stock Data from yahoo_finance VERY EXTENSIVE
yahooofinance_stock = Share(Stock_One)
yahooofinance_latestprice = yahooofinance_stock.get_price()
yahooofinance_tradetime = yahooofinance_stock.get_trade_datetime()
yahooofinance_anotherfunction = yahooofinance_stock.get_last_trade_with_time()
print('Yahoo finance retuns:', yahooofinance_latestprice, 'on the time:',
      yahooofinance_tradetime, 'AND IT RETURNS:',
      yahooofinance_anotherfunction)

# Get the stock Data from GoogleFinance WORKS REAL TIME, THE OTHERS DONT
# print('The Google Finance module returns:', json.dumps(getQuotes(Stock_One), indent=2))