Ejemplo n.º 1
0
def eval_stock(ticker):
    result = "Summary: "
    score = 0
    momentum = False
    if ystockquote.get_50_sma(ticker) > ystockquote.get_200_sma(ticker):
        result+="stock has momentum, 50 day moving avg is %s and 200 day is %s" % (ystockquote.get_50_sma(ticker),
        ystockquote.get_200_sma(ticker))
        score+=1
        momentum=True
    else:
        result+="Stock has no momentum, 50 day moving avg is %s and 200 day is %s" % (ystockquote.get_50_sma(ticker),
        ystockquote.get_200_sma(ticker))

    if float(ystockquote.get_1_year_target(ticker)) > (1.2 * float(ystockquote.get_todays_high(ticker))):
        result+=" 20% away from price target"
        score += 1

    #Short ratio of 5 or higher with positive momentum means investors may likely buy to cover soon
    if momentum==True and float(ystockquote.get_short_ratio(ticker)) > 3.0:
        score+=2

    result+= " \n short ratio is " + ystockquote.get_short_ratio(ticker)

    if float(ystockquote.get_eps(ticker))>.02*float(ystockquote.get_todays_high(ticker)):
        score+=1.5

    result += " \n EPS: " + ystockquote.get_eps(ticker) + " today's high is " + ystockquote.get_todays_high(ticker)

    result+= " \n , notes (if applicable)" + ystockquote.get_notes(ticker)
    return result, "Score is " + str(score)
Ejemplo n.º 2
0
 def test_get_short_ratio(self):
     value = ystockquote.get_short_ratio(self.symbol)
     self.assertIsInstance(value, str)
Ejemplo n.º 3
0
 def test_get_short_ratio(self):
     value = ystockquote.get_short_ratio(self.symbol)
     self.assertIsInstance(value, str)
Ejemplo n.º 4
0
    for line in lines:
        #get rid of the new line syntax
        line=line.strip("',/\n[]")
        tickers.append(line)

    return tickers

print(store_tickers("tickers.csv"))



print (eval_stock('CSG'))

print (type(float(ystockquote.get_todays_high('GOOG'))))

print(ystockquote.get_short_ratio('LQMT'))


print(ystockquote.get_eps_estimate_current_year('GOOG'))
#trailing 12 months number
print(ystockquote.get_eps('GOOG'))
print(ystockquote.get_price_eps_estimate_current_year('GOOG'))



##Some of the methods available
name = ystockquote.get_company_name('GOOG')

mktcap = ystockquote.get_market_cap('GOOG')

print ("Name: %s , Market Cap %s" %(name,mktcap))
Ejemplo n.º 5
0
def view_stock(request, ticker):
    if request.user.__class__.__name__ is 'CustomUser':
        c_user = get_object_or_404(CustomUser, pk=request.user.pk)
        account = Account.objects.get(user=c_user)
    else:
        account = False
    stock = get_object_or_404(Stock, ticker=ticker)

    companyName = stock.ticker
    companyName = companyName.upper()
    stock = Stock.objects.get(ticker=companyName)
    namer = "'" + companyName + "'"
    ystock = Share(companyName)
    the_price = ystock.get_price()

    regex = 'Business Summary</span></th><th align="right">&nbsp;</th></tr></table><p>(.+?)</p>'
    pattern = re.compile(regex)

    root_url = urllib.urlopen("http://finance.yahoo.com/q/pr?s=" +
                              companyName + "+Profile")
    htmltext = root_url.read()

    decoded_str = str(re.findall(pattern, htmltext)).decode("utf8")
    encoded_str = decoded_str.encode('ascii', 'ignore')
    stock.description = encoded_str
    stock.description = stock.description[:-2]
    stock.description = stock.description[2:]
    stock.book_value = ystockquote.get_book_value(companyName)
    stock.change = ystockquote.get_change(companyName)
    #stock.dividend_per_share = ystockquote.get_dividend_per_share(companyName)
    #stock.dividend_yield = ystockquote.get_dividend_yield(companyName)
    stock.ebitda = ystockquote.get_ebitda(companyName)
    stock.fifty_two_week_high = ystockquote.get_52_week_high(companyName)
    stock.fifty_two_week_low = ystockquote.get_52_week_low(companyName)
    stock.market_cap = ystockquote.get_market_cap(companyName)
    stock.short_ratio = ystockquote.get_short_ratio(companyName)
    stock.stock_exchange = ystockquote.get_stock_exchange(companyName)
    stock.volume = ystockquote.get_volume(companyName)
    stock.price = ystock.get_price()
    #yahoo_finance
    stock.average_daily_volume = ystock.get_avg_daily_volume()
    stock.earnings_per_share = ystock.get_price_earnings_ratio()
    stock.fifty_day_moving_avg = ystock.get_50day_moving_avg()
    stock.two_hundred_day_moving_avg = ystock.get_200day_moving_avg()
    stock.price_book_ratio = ystock.get_price_book()
    stock.last_sale = ystock.get_price()
    stock.price_earnings_growth_ratio = ystock.get_price_earnings_growth_ratio(
    )
    stock.price_earnings_ratio = ystock.get_price_earnings_ratio()
    stock.price_sales_ratio = ystock.get_price_sales()
    stock.save()

    vl = []
    acl = []
    hl = []
    ll = []
    cl = []
    ol = []
    days_list = []
    d = 0
    seven_days_ago = datetime.datetime.now() + datetime.timedelta(-30)
    today = datetime.datetime.now()
    days = ystockquote.get_historical_prices(
        'GOOGL', seven_days_ago.strftime("%Y-%m-%d"),
        today.strftime("%Y-%m-%d"))
    for day in days.keys():
        d += 1
        date_label = datetime.datetime.now() + datetime.timedelta(-d)
        days_list.append(date_label.strftime("%b-%d"))
        day_info = days.get(day)
        vol = int(day_info.get('Volume'))
        vl.append(vol)
        adjcl = float(day_info.get('Adj Close'))
        acl.append(adjcl)
        highs = float(day_info.get('High'))
        hl.append(highs)
        lows = float(day_info.get('Low'))
        ll.append(lows)
        closes = float(day_info.get('Close'))
        cl.append(closes)
        opens = float(day_info.get('Open'))
        ol.append(opens)

    volume = vl
    lows = ll
    opens = ol
    highs = hl
    averages = acl
    closes = cl
    days_l = days_list[::-1]
    context = RequestContext(
        request,
        dict(account=account,
             request=request,
             stock=stock,
             volume=volume,
             lows=lows,
             highs=highs,
             opens=opens,
             closes=closes,
             averages=averages,
             days_l=days_l))
    return render_to_response('scrapyr_app/stock.html', context=context)
Ejemplo n.º 6
0
def view_stock(request, ticker):
    if request.user.__class__.__name__ is "CustomUser":
        c_user = get_object_or_404(CustomUser, pk=request.user.pk)
        account = Account.objects.get(user=c_user)
    else:
        account = False
    stock = get_object_or_404(Stock, ticker=ticker)

    companyName = stock.ticker
    companyName = companyName.upper()
    stock = Stock.objects.get(ticker=companyName)
    namer = "'" + companyName + "'"
    ystock = Share(companyName)
    the_price = ystock.get_price()

    regex = 'Business Summary</span></th><th align="right">&nbsp;</th></tr></table><p>(.+?)</p>'
    pattern = re.compile(regex)

    root_url = urllib.urlopen("http://finance.yahoo.com/q/pr?s=" + companyName + "+Profile")
    htmltext = root_url.read()

    decoded_str = str(re.findall(pattern, htmltext)).decode("utf8")
    encoded_str = decoded_str.encode("ascii", "ignore")
    stock.description = encoded_str
    stock.description = stock.description[:-2]
    stock.description = stock.description[2:]
    stock.book_value = ystockquote.get_book_value(companyName)
    stock.change = ystockquote.get_change(companyName)
    # stock.dividend_per_share = ystockquote.get_dividend_per_share(companyName)
    # stock.dividend_yield = ystockquote.get_dividend_yield(companyName)
    stock.ebitda = ystockquote.get_ebitda(companyName)
    stock.fifty_two_week_high = ystockquote.get_52_week_high(companyName)
    stock.fifty_two_week_low = ystockquote.get_52_week_low(companyName)
    stock.market_cap = ystockquote.get_market_cap(companyName)
    stock.short_ratio = ystockquote.get_short_ratio(companyName)
    stock.stock_exchange = ystockquote.get_stock_exchange(companyName)
    stock.volume = ystockquote.get_volume(companyName)
    stock.price = ystock.get_price()
    # yahoo_finance
    stock.average_daily_volume = ystock.get_avg_daily_volume()
    stock.earnings_per_share = ystock.get_price_earnings_ratio()
    stock.fifty_day_moving_avg = ystock.get_50day_moving_avg()
    stock.two_hundred_day_moving_avg = ystock.get_200day_moving_avg()
    stock.price_book_ratio = ystock.get_price_book()
    stock.last_sale = ystock.get_price()
    stock.price_earnings_growth_ratio = ystock.get_price_earnings_growth_ratio()
    stock.price_earnings_ratio = ystock.get_price_earnings_ratio()
    stock.price_sales_ratio = ystock.get_price_sales()
    stock.save()

    vl = []
    acl = []
    hl = []
    ll = []
    cl = []
    ol = []
    days_list = []
    d = 0
    seven_days_ago = datetime.datetime.now() + datetime.timedelta(-30)
    today = datetime.datetime.now()
    days = ystockquote.get_historical_prices("GOOGL", seven_days_ago.strftime("%Y-%m-%d"), today.strftime("%Y-%m-%d"))
    for day in days.keys():
        d += 1
        date_label = datetime.datetime.now() + datetime.timedelta(-d)
        days_list.append(date_label.strftime("%b-%d"))
        day_info = days.get(day)
        vol = int(day_info.get("Volume"))
        vl.append(vol)
        adjcl = float(day_info.get("Adj Close"))
        acl.append(adjcl)
        highs = float(day_info.get("High"))
        hl.append(highs)
        lows = float(day_info.get("Low"))
        ll.append(lows)
        closes = float(day_info.get("Close"))
        cl.append(closes)
        opens = float(day_info.get("Open"))
        ol.append(opens)

    volume = vl
    lows = ll
    opens = ol
    highs = hl
    averages = acl
    closes = cl
    days_l = days_list[::-1]
    context = RequestContext(
        request,
        dict(
            account=account,
            request=request,
            stock=stock,
            volume=volume,
            lows=lows,
            highs=highs,
            opens=opens,
            closes=closes,
            averages=averages,
            days_l=days_l,
        ),
    )
    return render_to_response("scrapyr_app/stock.html", context=context)
Ejemplo n.º 7
-1
def data_type():
	print "From the list above, enter the data type you'd like to see"
	data = raw_input("> ")
	print "What stock would you like to see data on?"
	stock = raw_input("> ")
	if data == 'price' or data == 'Price':
		print ystockquote.get_price(stock)
	elif data == 'change' or data == 'Change':
		print ystockquote.get_change(stock)
	elif data == 'Volume' or data == 'volume':
		print ystockquote.get_avg_daily_vol(stock)
	elif data == 'exchange' or data == 'Exchange':
		print ystockquote.get_stock_exchange(stock)
	elif data == 'market cap' or data == 'Market cap' or data == 'Market Cap':
		print ystockquote.get_market_cap(stock)
	elif data == 'book value' or data == 'Book value' or data == 'Book Value':
		print ystockquote.get_book_value(stock)
	elif data == 'eps' or data == 'EPS':
		print ystockquote.get_earnings_per_share(stock)
	elif data == 'short ratio' or data == 'Short Ratio':
		print ystockquote.get_short_ratio(stock)
	elif data == 'dividend yield' or data == 'Dividend Yield' or data == 'div yield':
		print ystockquote.get_dividend_yield(stock)
	elif data == 'ebitda' or data == 'EBITDA':
		print ystockquote.get_ebitda(stock)
	else:
		print 'Sorry, we don\'t have that data type'
		quit()