質問編集履歴

6

a

2016/09/21 07:03

投稿

jiro260260
jiro260260

スコア25

test CHANGED
File without changes
test CHANGED
@@ -112,7 +112,7 @@
112
112
 
113
113
  ###試したこと
114
114
 
115
- #価格変化率の確率密度関数以下のソースコードのうち、それ以前の行で既出の部分を止めると以下のようになりました。
115
+ 価格変化率の確率密度関数のソースコードのうち、それ以前の行で既出の部分を止めると以下のようになりました。
116
116
 
117
117
  <エラー>
118
118
 

5

a

2016/09/21 07:03

投稿

jiro260260
jiro260260

スコア25

test CHANGED
File without changes
test CHANGED
@@ -138,7 +138,7 @@
138
138
 
139
139
  ```R
140
140
 
141
- setwd("/home/taiheisone/bootcamp")
141
+ setwd("/home/user/bootcamp")
142
142
 
143
143
  for (i in 1:5){
144
144
 

4

2016/09/21 07:02

投稿

jiro260260
jiro260260

スコア25

test CHANGED
File without changes
test CHANGED
@@ -112,7 +112,91 @@
112
112
 
113
113
  ###試したこと
114
114
 
115
+ #価格変化率の確率密度関数以下のソースコードのうち、それ以前の行で既出の部分を止めると以下のようになりました。
116
+
117
+ <エラー>
118
+
119
+ ```R
120
+
121
+ 警告メッセージ:
122
+
123
+ 1: In xy.coords(x, y, xlabel, ylabel, log) :
124
+
125
+ 2 y values <= 0 omitted from logarithmic plot
126
+
127
+ 2: In xy.coords(x, y, xlabel, ylabel, log) :
128
+
129
+ 1 y value <= 0 omitted from logarithmic plot
130
+
131
+ 3: In xy.coords(x, y, xlabel, ylabel, log) :
132
+
133
+ 4 y values <= 0 omitted from logarithmic plot
134
+
135
+ ```
136
+
137
+ <ソースコード>
138
+
139
+ ```R
140
+
141
+ setwd("/home/taiheisone/bootcamp")
142
+
143
+ for (i in 1:5){
144
+
145
+ x <- read.table("StockCode.txt", skip = i-1, nrows = 1)
146
+
147
+ file_title <- paste("data", as.character(x[1,1]), ".csv", sep = "")
148
+
115
- 課題に対してアプローチしたことを記載してください
149
+ data_x <- read.csv(file_title)
150
+
151
+ data_x$closing_adjusted<-round(data_x$closing_adjusted,digits=3)
152
+
153
+ data_x <- data_x[order(data_x$date_s),]
154
+
155
+ data_x$date_s <- as.Date(as.character(data_x$date_s), "%Y%m%d")
156
+
157
+ #価格時系列
158
+
159
+ plot(data_x$date_s, data_x$closing_adjusted, main=paste("Stock price(", as.character(x[1,1]), ")", sep = ""), xlab="Time [date]", ylab="ClosingPrice(Adjusted)", type="l") #図の作成
160
+
161
+ dev.copy2eps(file=paste("Price", as.character(x[1,1]), ".eps",sep = ""), width=6, height=4) #図の保存
162
+
163
+ #価格変化率時系列
164
+
165
+ RDP <- diff(data_x$closing_adjusted)/data_x$closing_adjusted[1:length(data_x$closing_adjusted)-1]
166
+
167
+ plot(data_x$date_s[1:length(data_x$closing_adjusted)-1], RDP, xlab="Time [date]",
168
+
169
+ ylab="RDP(Adjusted)", type="l", ylim=c(-0.4, 0.4)) #図の作成
170
+
171
+ dev.copy2eps(file=paste("RDP", as.character(x[1,1]), ".eps",sep = ""), width=6, height=4) #図の保存
172
+
173
+ #価格変化率の確率密度関数
174
+
175
+ #data_x <- data_x[order(data_x$date_s),]
176
+
177
+ head(data_x)
178
+
179
+ #data_x$date_s <- as.Date(as.character(data_x$date_s), "%Y%m%d")
180
+
181
+ #plot(data_x$date_s, data_x$closing_adjusted, main=paste("Stock price(", as.character(x[1,1]), ")", sep = ""), xlab="Time [date]", ylab="ClosingPrice(Adjusted)", type="l")
182
+
183
+ DP <- diff(data_x$closing_adjusted)
184
+
185
+ hist_temp <- hist(DP, plot=FALSE)
186
+
187
+ plot(hist_temp$mids, hist_temp$density, xlim=c(-100, 100), ylim=c(0.00001, 0.1), log="y", xlab="DP", ylab="PDF")
188
+
189
+ x <- -50:50
190
+
191
+ lines(x, dnorm(x, mean(DP), sd(DP)))
192
+
193
+ }
194
+
195
+ ```
196
+
197
+
198
+
199
+
116
200
 
117
201
 
118
202
 

3

2016/09/21 07:01

投稿

jiro260260
jiro260260

スコア25

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ###発生している問題・エラーメッセージ
8
8
 
9
- 価格時系列,価格変化率時系列は描けましたが、価格変化率の確率密度関数はエラーが出てしまい描くことができません。原因が不明です。
9
+ 価格時系列,価格変化率時系列は描けましたが、価格変化率の確率密度関数はエラーが出てしまい描くことができません。
10
10
 
11
11
 
12
12
 

2

2016/09/21 05:55

投稿

jiro260260
jiro260260

スコア25

test CHANGED
File without changes
test CHANGED
@@ -118,4 +118,4 @@
118
118
 
119
119
  ###補足情報(言語/FW/ツール等のバージョンなど)
120
120
 
121
- より詳細な情報
121
+ 銘柄コード一覧ファイル(StockCode.txt)には5つの銘柄コード(9007,9008,9020,9021,9042)が入っています。それぞれの銘柄コードの株価データはcsvファイル(data9007.csv,data9008.csv,data9020.csv,data9021.csv,data9042.csv)に保存されています。

1

a

2016/09/21 05:54

投稿

jiro260260
jiro260260

スコア25

test CHANGED
File without changes
test CHANGED
@@ -50,55 +50,57 @@
50
50
 
51
51
  for (i in 1:5){
52
52
 
53
- x <- read.table("StockCode.txt", skip = i-1, nrows = 1)
53
+ x <- read.table("StockCode.txt", skip = i-1, nrows = 1) #テキストファイルから銘柄コードを順次読み込む
54
54
 
55
- file_title <- paste("data", as.character(x[1,1]), ".csv", sep = "")
55
+ file_title <- paste("data", as.character(x[1,1]), ".csv", sep = "")
56
56
 
57
- data_x <- read.csv(file_title)
57
+ data_x <- read.csv(file_title) #読み込んだ銘柄コードの株価データが入ったcsvファイルを読み込む
58
58
 
59
- data_x$closing_adjusted<-round(data_x$closing_adjusted,digits=3)
59
+ data_x$closing_adjusted<-round(data_x$closing_adjusted,digits=3) #丸め込み
60
60
 
61
- data_x <- data_x[order(data_x$date_s),]
61
+ data_x <- data_x[order(data_x$date_s),] #日付(date_s)によるソート(昇順)
62
62
 
63
- data_x$date_s <- as.Date(as.character(data_x$date_s), "%Y%m%d")
63
+ data_x$date_s <- as.Date(as.character(data_x$date_s), "%Y%m%d") #型変換( integer → string → date(double) )
64
64
 
65
- #価格時系列
65
+ #価格時系列
66
66
 
67
- plot(data_x$date_s, data_x$closing_adjusted, main=paste("Stock price(", as.character(x[1,1]), ")", sep = ""), xlab="Time [date]", ylab="ClosingPrice(Adjusted)", type="l") #図の作成
67
+ plot(data_x$date_s, data_x$closing_adjusted, main=paste("Stock price(", as.character(x[1,1]), ")", sep = ""), xlab="Time [date]", ylab="ClosingPrice(Adjusted)", type="l") #図の作成
68
68
 
69
- dev.copy2eps(file=paste("Price", as.character(x[1,1]), ".eps",sep = ""), width=6, height=4) #図の保存
69
+ dev.copy2eps(file=paste("Price", as.character(x[1,1]), ".eps",sep = ""), width=6, height=4) #図の保存
70
70
 
71
- #価格変化率時系列
71
+ #価格変化率時系列
72
72
 
73
- RDP <- diff(data_x$closing_adjusted)/data_x$closing_adjusted[1:length(data_x$closing_adjusted)-1]
73
+ RDP <- diff(data_x$closing_adjusted)/data_x$closing_adjusted[1:length(data_x$closing_adjusted)-1]
74
74
 
75
- plot(data_x$date_s[1:length(data_x$closing_adjusted)-1], RDP, xlab="Time [date]",
75
+ plot(data_x$date_s[1:length(data_x$closing_adjusted)-1], RDP, xlab="Time [date]",
76
76
 
77
- ylab="RDP(Adjusted)", type="l", ylim=c(-0.4, 0.4)) #図の作成
77
+ ylab="RDP(Adjusted)", type="l", ylim=c(-0.4, 0.4)) #図の作成
78
78
 
79
- dev.copy2eps(file=paste("RDP", as.character(x[1,1]), ".eps",sep = ""), width=6, height=4) #図の保存
79
+ dev.copy2eps(file=paste("RDP", as.character(x[1,1]), ".eps",sep = ""), width=6, height=4) #図の保存
80
80
 
81
- #価格変化率確率密度関数
81
+ #価格変化率確率密度関数
82
82
 
83
- data_x <- data_x[order(data_x$date_s),]
83
+ data_x <- data_x[order(data_x$date_s),] #日付(date_s)によるソート(昇順)
84
84
 
85
- head(data_x)
85
+ head(data_x)
86
86
 
87
- data_x$date_s <- as.Date(as.character(data_x$date_s), "%Y%m%d")
87
+ data_x$date_s <- as.Date(as.character(data_x$date_s), "%Y%m%d") #型変換( integer → string → date(double) )
88
88
 
89
- plot(data_x$date_s, data_x$closing_adjusted, main=paste("Stock price(", as.character(x[1,1]), ")", sep = ""), xlab="Time [date]", ylab="ClosingPrice(Adjusted)", type="l")
89
+ plot(data_x$date_s, data_x$closing_adjusted, main=paste("Stock price(", as.character(x[1,1]), ")", sep = ""), xlab="Time [date]", ylab="ClosingPrice(Adjusted)", type="l") #グラフの描画
90
90
 
91
- DP <- diff(data_x$closing_adjusted)
91
+ DP <- diff(data_x$closing_adjusted) #ベクトルの作成(価格差)
92
92
 
93
- hist_temp <- hist(DP, plot=FALSE)
93
+ hist_temp <- hist(DP, plot=FALSE) #ヒストグラム,確率密度関数の作成
94
94
 
95
- plot(hist_temp$mids, hist_temp$density, xlim=c(-100, 100), ylim=c(0.00001, 0.1), log="y", xlab="DP", ylab="PDF")
95
+ plot(hist_temp$mids, hist_temp$density, xlim=c(-100, 100), ylim=c(0.00001, 0.1), log="y", xlab="DP", ylab="PDF") #確率密度関数の図示
96
96
 
97
- x <- -50:50
97
+ x <- -50:50 #正規分布による近似線を追加
98
98
 
99
- lines(x, dnorm(x, mean(DP), sd(DP)))
99
+ lines(x, dnorm(x, mean(DP), sd(DP)))
100
100
 
101
101
  }
102
+
103
+
102
104
 
103
105
  ```
104
106