當前位置: 首頁>>代碼示例>>Python>>正文


Python Stock.get_time_series方法代碼示例

本文整理匯總了Python中models.Stock.get_time_series方法的典型用法代碼示例。如果您正苦於以下問題:Python Stock.get_time_series方法的具體用法?Python Stock.get_time_series怎麽用?Python Stock.get_time_series使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Stock的用法示例。


在下文中一共展示了Stock.get_time_series方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: stock

# 需要導入模塊: from models import Stock [as 別名]
# 或者: from models.Stock import get_time_series [as 別名]
def stock():
    if not account.user_is_logged_in():
        return redirect(url_for("login"))
    ticker = request.args.get("ticker", "AAPL") # TODO: no ticker is error...

    # Find the stock.
    stock = Stock.get_stock_from_db(ticker)

    # Check for errors.
    if stock == -1:
        N_STOCKS = 20 # number of stocks to retrieve
        tickers = Stock.get_all_tickers()
        stocks = Stock.get_stocks(N_STOCKS, True) # default: list of stocks by alpha order

        return render_template("home.html",
                               error="No ticker matching that name could be found.",
                               tickers = tickers, stocks = stocks,
                               metric = "alpha", order = True,
                               has_recs = account.user_has_recommendations())

    # Get the prices with corresponding dates.
    # Produce formatted date strings to paste into HTML.
    price_time_series = Stock.get_time_series(ticker, 7)
    price_dates = price_time_series.keys()
    price_dates.sort()
    price_dates_str = []
    price_values = []
    for curr_date in price_dates:
        price_values.append(price_time_series[curr_date])
        price_dates_str.append(curr_date.strftime("%m-%d"))

    # Compute price change now-- consistent with time series data!
    price_change = price_values[-1] - price_values[-2]

    # Put a blurb in the stock page if it is recommended.
    stock_is_recommended = False
    if account.user_has_recommendations():
        if stock.ticker in Stock.recommended_tickers:
            stock_is_recommended = True

    return render_template("stock.html", ticker = stock.ticker,
                           name = stock.name, latest_price = stock.cur_price,
                           pe_ratio = stock.pe, market_cap = stock.cap,
                           dividends = stock.dividends,
                           beta = stock.beta,
                           sustainability = stock.sustainability,
                           socialgood = stock.socialgood,
                           american = stock.american,
                           price_change = price_change,
                           price_series_dates = price_dates_str,
                           price_series_values = price_values,
                           recommended = stock_is_recommended)
開發者ID:damlaren,項目名稱:investorscope-app,代碼行數:54,代碼來源:views.py


注:本文中的models.Stock.get_time_series方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。