なんじゃくにっき

プログラミングの話題中心。

S&P 500のグラフをGoogle ColabのAIに描かせる

最近、自然言語処理(とちょっと機械学習)絡みで遊んでいて、 Google Colaboratory使うことがあるんですが、

新規ノートブックで最初に「コーディングを開始するか、AIで生成します」 と出てくるので何かに使えないかと思った次第。(以前AIなんてついてなかったよね?)

で、新NISAもはじまったことだし(てもう2ヶ月以上経ってますが)S&P 500のグラフでも描いてくれるかな?

と思ったので試してみます。

プロンプトは"S&P 500のデータをグラフで出してください。期間は10年、y軸は対数で出してください。"

!pip install yfinance
import yfinance as yf

# Download the historical data for the S&P 500 index
data = yf.download('^GSPC', period='10y')

# Plot the closing prices on a logarithmic scale
data['Close'].plot(logy=True)

# Add a title and axis labels
plt.title('S&P 500 Index: 10-Year Historical Data')
plt.xlabel('Date')
plt.ylabel('Closing Price (Log Scale)')

# Show the plot
plt.show()

実行結果

いやー素晴らしい、タイトルも付けてくれるし今までExcel芸でやってたのが馬鹿みたいですね。