2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rを学びたい Step7(日本の株価)

Posted at

はじめに

Rを学びたいStep7です。日本の株価を分析していきます。

ソースコード

# CRANミラーを設定
options(repos = c(CRAN = "https://cloud.r-project.org/"))

# 必要なパッケージをインストール
if (!require("quantmod")) install.packages("quantmod")

# quantmodパッケージをロード
library(quantmod)

# 日経平均株価のデータを取得
getSymbols("^N225", src = "yahoo")

# データの確認とプロット
print(head(N225))
chartSeries(N225, name = "nikkei225")

image.png

日経平均225株の結果を設定

# CRANミラーを設定
options(repos = c(CRAN = "https://cloud.r-project.org/"))

# quantmodパッケージをインストール
if (!require("quantmod")) install.packages("quantmod")

# quantmodパッケージをロード
library(quantmod)

# 銘柄コードを指定してトヨタ株のデータを取得
getSymbols("7203.T", src = "yahoo")

# データの確認
head(`7203.T`)

# プロットをPNGファイルとして保存
file_name <- "toyota_stock_chart.png"  # 保存するファイル名
png(filename = file_name, width = 800, height = 600)  # ファイル形式とサイズを指定

# 終値のプロット
chartSeries(`7203.T`, name = "トヨタ株価")

# ファイル出力を終了
dev.off()

cat("グラフを保存しました:", file_name, "\n")

トヨタ株の結果を設定

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?