始める無料で始める

Google と Apple に $1,000 を投資した場合の累積リターン I

累積リターンの計算ができるようになったので、2010 年に Google('GOOG')または Apple('AAPL')に $1,000 投資していたら、今いくらになっているかを比較してみましょう。

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

Pythonでの時系列データ操作

コースを見る

演習の手順

すでに pandaspdmatplotlib.pyplotplt としてインポート済みです。Google と Apple の株価データは変数 data に読み込まれています。

  • 変数 investment1000 で定義します。
  • data.pct_change() を適用して returns を計算します。
  • returns に 1 を加えて returns_plus_one とし、続けて .cumprod() を適用して結果を cumulative_return に代入します。
  • cumulative_returninvestment を掛け、その結果をプロットします。

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

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

# Define your investment
investment = ____

# Calculate the daily returns here
returns = ____

# Calculate the cumulative returns here
returns_plus_one = ____
cumulative_return = ____

# Calculate and plot the investment return here 

コードを編集して実行