始める無料で始める

時系列の時価総額を作成する

これまでに得た発行株数を使って、過去の株価時系列から、各構成銘柄・各取引日の時価総額(マーケットキャップ)を計算します。

この結果は、次の演習で完成させるバリュー加重株価指数を構築するための主要な入力となります。

この演習はコースの一部です

Pythonでの時系列データ操作

コースを見る

演習の手順

pandaspdmatplotlib.pyplotplt としてすでにインポート済みです。前の演習で使用した変数 componentsstock_prices も用意されています。

  • components から 'Number of Shares' を選択して no_shares に代入し、結果をデフォルト(昇順)でソートして表示します。
  • stock_pricesno_shares を掛け合わせて、ティッカーごとの時価総額の時系列を作成し、market_cap に代入します。
  • market_cap の先頭行と末尾行を選び、それぞれ first_valuelast_value に代入します。
  • pd.concat() を使って、first_valuelast_valueaxis=1 方向に連結し、結果を横向きの棒グラフとしてプロットします。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Select the number of shares
no_shares = ____
print(____)

# Create the series of market cap per ticker
market_cap = ____

# Select first and last market cap here
first_value = ____
last_value = ____


# Concatenate and plot first and last market cap here


コードを編集して実行