def update(stock1): stock1.lastprice = ystockquote.get_price(stock1) stock1.volume = ystockquote.get_volume(stock1) price_change = ystockquote.get_change(stock1) market_cap = ystockquote.get_market_cap(stock1) get_high = ystockquote.get_52_week_high(stock1) get_low = ystockquote.get_52_week_low(stock1) pb_ratio = ystockquote.get_price_book_ratio(stock1) ebitda = ystockquote.get_ebitda(stock1) dividend = ystockquote.get_dividend_yield(stock1) stock1.save()
def update(stock1): stock1.lastprice = ystockquote.get_price(stock1) stock1.volume = ystockquote.get_volume(stock1) stock1.price_change = float(ystockquote.get_change(stock1)) stock1.market_cap = ystockquote.get_market_cap(stock1) stock1.get_high = ystockquote.get_52_week_high(stock1) stock1.get_low = ystockquote.get_52_week_low(stock1) stock1.pb_ratio = ystockquote.get_price_book_ratio(stock1) stock1.pe_ratio = ystockquote.get_price_earnings_ratio(stock1) stock1.dividend = ystockquote.get_dividend_yield(stock1) stock1.peg = get_peg(stock1) stock1.revenue = get_revenue(stock1) stock1.a_gain = get_annualized_gain(stock1) stock1.save()
def test_get_price_book_ratio(self): value = ystockquote.get_price_book_ratio(self.symbol) self.assertIsInstance(value, str)
def individual_stock(request, stock_id): stock1 = get_object_or_404(Stock, pk=stock_id) # Stock Information per Stock stock1.lastprice = ystockquote.get_price(stock1) stock1.volume = ystockquote.get_volume(stock1) price_change = ystockquote.get_change(stock1) market_cap = ystockquote.get_market_cap(stock1) get_high = ystockquote.get_52_week_high(stock1) get_low = ystockquote.get_52_week_low(stock1) pb_ratio = ystockquote.get_price_book_ratio(stock1) ebitda = ystockquote.get_ebitda(stock1) dividend = ystockquote.get_dividend_yield(stock1) # Graph # Last known weekday current_day = weekday().isoformat() # Retrieve live data YYYY-MM-DD historical_price = ystockquote.get_historical_prices(stock1, '2010-01-24', current_day) correct_order = sorted(historical_price) stock_prices = [] dates = [] for values in correct_order: stock_prices.append(historical_price[values]['Adj Close']) dates.append(values) # Convert to Float for p in range(len(stock_prices)): stock_prices[p] = float(stock_prices[p]) # Convert to Datetime Format dates_objects = [] for d in dates: dates_objects.append(datetime.strptime(d,'%Y-%m-%d')) source = ColumnDataSource(data=dict(x=dates_objects,y=stock_prices, time=dates)) # Tools hover = HoverTool(tooltips=[('Stock Price','@y'),('time','@time'),], mode='vline') crosshair = CrosshairTool(dimensions=['height']) TOOLS = [hover, crosshair] plot = figure(x_axis_type="datetime", responsive = True ,plot_height=250, tools = TOOLS, toolbar_location=None) plot.line('x','y',source=source) first_date = dates[0] last_date = dates[-1] callback = CustomJS(args=dict(x_range=plot.x_range), code=""" var start = cb_obj.get("value"); x_range.set("start", start); x_range.set("end", start+2); """) slider = vform(Slider(start=0, end=100, title="Start Date", callback=callback)) widget_script, widget_div = components(slider) script, div = components(plot) stock1.save() context = {'stock':stock1, 'hprice': stock_prices, 'widget_script': widget_script, 'widget_div': widget_div, 'the_script': script, 'the_div':div, 'thedate': dates_objects, 'dates':dates } return render(request, 'stocktracker/individual.html', context)
def individual_stock(request, stock_id): stock1 = get_object_or_404(Stock, pk=stock_id) # Stock Information per Stock stock1.lastprice = ystockquote.get_price(stock1) stock1.volume = ystockquote.get_volume(stock1) price_change = ystockquote.get_change(stock1) market_cap = ystockquote.get_market_cap(stock1) get_high = ystockquote.get_52_week_high(stock1) get_low = ystockquote.get_52_week_low(stock1) pb_ratio = ystockquote.get_price_book_ratio(stock1) ebitda = ystockquote.get_ebitda(stock1) dividend = ystockquote.get_dividend_yield(stock1) # Graph # Last known weekday current_day = weekday().isoformat() # Retrieve live data YYYY-MM-DD historical_price = ystockquote.get_historical_prices( stock1, '2010-01-24', current_day) correct_order = sorted(historical_price) stock_prices = [] dates = [] for values in correct_order: stock_prices.append(historical_price[values]['Adj Close']) dates.append(values) # Convert to Float for p in range(len(stock_prices)): stock_prices[p] = float(stock_prices[p]) # Convert to Datetime Format dates_objects = [] for d in dates: dates_objects.append(datetime.strptime(d, '%Y-%m-%d')) source = ColumnDataSource( data=dict(x=dates_objects, y=stock_prices, time=dates)) # Tools hover = HoverTool(tooltips=[ ('Stock Price', '@y'), ('time', '@time'), ], mode='vline') crosshair = CrosshairTool(dimensions=['height']) TOOLS = [hover, crosshair] plot = figure(x_axis_type="datetime", responsive=True, plot_height=250, tools=TOOLS, toolbar_location=None) plot.line('x', 'y', source=source) first_date = dates[0] last_date = dates[-1] callback = CustomJS(args=dict(x_range=plot.x_range), code=""" var start = cb_obj.get("value"); x_range.set("start", start); x_range.set("end", start+2); """) slider = vform( Slider(start=0, end=100, title="Start Date", callback=callback)) widget_script, widget_div = components(slider) script, div = components(plot) stock1.save() context = { 'stock': stock1, 'hprice': stock_prices, 'widget_script': widget_script, 'widget_div': widget_div, 'the_script': script, 'the_div': div, 'thedate': dates_objects, 'dates': dates } return render(request, 'stocktracker/individual.html', context)