1. Learn
  2. /
  3. Courses
  4. /
  5. Pythonでの時系列データ操作

Connected

Exercise

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

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

Instructions

100 XP

すでに pandas は pd、matplotlib.pyplot は plt としてインポート済みです。Google と Apple の株価データは変数 data に読み込まれています。

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