-
Notifications
You must be signed in to change notification settings - Fork 6
/
.Rhistory
512 lines (512 loc) · 16 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
dm <- dim(GAX)
dm
colnames(GAX)[dm[2]]
colnames(GAX)[dm[2]] <- "Direction"
colnames(GAX)
issd <- "2013-01-01"
ised <- "2017-12-31"
ossd <- "2018-01-01"
osed <- "2018-11-20"
isrow <- which(index(GAX) >= issd & index(GAX) <= ised)
osrow <- which(index(GAX) >= ossd & index(GAX) <= osed)
isGAX <- GAX[isrow,]
osGAX <- GAX[osrow,]
#표준화#
isme <- apply(isGAX, 2, mean)
isstd <- apply(isGAX, 2, sd)
isidn <- matrix(1, dim(isGAX)[1], dim(isGAX)[2])
norm_isGAX <- (isGAX - t(isme * t(isGAX))) / t(isstd * t(isidn))
dm<-dim(isGAX)
norm_isGAX[,dm[2]] <- direction[isrow]
formula <- paste("Direction ~ .", sep ="")
model <-glm(formula, family = "binomial", norm_isGAX)
summary(model)
pred <- predict(model, norm_isGAX)
prob <- 1/(1+exp(-(pred)))
par(mflow = c(2,1))
plot(pred,type = "l")
plot(prob, type = "l")
head(prob)
tail(prob)
pred_direction <- NULL
pred_direction[prob > 0.5] <- 1
pred_direction[prob <= 0.5] <- 0
pred_direction
#오차행렬에 집어넣을 때, pred_direction이랑 norm_isdji 간 객체 차 존재. Table로 집어넣어야 함, e1071패키지 설치 후 실행
matrix <- confusionMatrix(table(pred_direction,norm_isGAX$Direction))
matrix
#예측 정확도 94%
#정규화
osidn <- matrix(1,dim(osGAX)[1], dim(osGAX)[2])
norm_osGAX <- (osGAX - t(isme*t(osidn))) / t(isstd*t(osidn))
dm <- dim(osGAX)
norm_osGAX[,dm[2]] <- direction[osrow]
#표본 외 데이터 값, 확률
ospred <- predict(model, norm_osGAX)
osprob <- 1/(1+exp(-(ospred)))
ospred_direction <- NULL
ospred_direction[osprob >0.5]<-1
ospred_direction[osprob<=0.5]<-0
osmatrix <- confusionMatrix(table(ospred_direction, norm_osGAX$Direction))
osmatrix
#84% accuracy, 트레이딩 비용, 시장 슬리피지 고려X, 다른 전략 X 오로지 예측
#### 트레이딩 후 Cummulative return 구하는 코딩
#로지스틱 CUM RET 구하는 법
signal <- ifelse(ospred_direction == 1, 1, ifelse(ospred_direction == 0,-1,0))
testrow <- which(index(GAX) >= ossd & index(GAX) <= osed)
GAX <- GOLD.AX$GOLD.AX.Close
ret <- GAX/lag(GAX) -1
ret <- ret[testrow]
ret
cost <- 0
length(signal)
length(ret)
dim(ret)
length(testrow)
trade_ret <- ret * Lag(signal) - cost
dim(ret)
cumm_ret <- Return.cumulative(trade_ret)
anual_ret <- Return.annualized(trade_ret)
charts.PerformanceSummary(trade_ret)
### Data ###
getSymbols("GOLD.AX", src = "yahoo")
GAX <- GOLD.AX
GAX <- GAX[,"GOLD.AX.Close"]
GAX <- na.omit(GAX)
#Varaible #
avg10 <- rollapply(GAX, 10, mean)
avg20 <- rollapply(GAX, 20, mean)
std10 <- rollapply(GAX,10,sd)
std20 <- rollapply(GAX,20,sd)
rsi5 <- RSI(GAX, 5, "SMA")
rsi14 <- RSI(GAX, 14, "SMA")
macd12269 <- MACD(GAX, 12, 26, 9, "SMA")
macd7205 <- MACD(GAX, 7, 20, 5, "SMA")
bbands <- BBands(GAX, 20, "SMA", 2)
direction <- NULL
direction[GAX > Lag(GAX, 20)] <- 1
direction[GAX < Lag(GAX, 20)] <- 0
GAX <- cbind(GAX, avg10, avg20, std10, std20, rsi5, rsi14, macd12269, macd7205, bbands, direction)
dm <- dim(GAX)
dm
colnames(GAX)[dm[2]]
colnames(GAX)[dm[2]] <- "Direction"
colnames(GAX)
issd <- "2013-01-01"
ised <- "2017-12-31"
ossd <- "2018-01-01"
osed <- "2018-11-20"
isrow <- which(index(GAX) >= issd & index(GAX) <= ised)
osrow <- which(index(GAX) >= ossd & index(GAX) <= osed)
isGAX <- GAX[isrow,]
osGAX <- GAX[osrow,]
#표준화#
isme <- apply(isGAX, 2, mean)
isstd <- apply(isGAX, 2, sd)
isidn <- matrix(1, dim(isGAX)[1], dim(isGAX)[2])
norm_isGAX <- (isGAX - t(isme * t(isGAX))) / t(isstd * t(isidn))
dm<-dim(isGAX)
norm_isGAX[,dm[2]] <- direction[isrow]
formula <- paste("Direction ~ .", sep ="")
model <-glm(formula, family = "binomial", norm_isGAX)
summary(model)
pred <- predict(model, norm_isGAX)
prob <- 1/(1+exp(-(pred)))
par(mflow = c(2,1))
plot(pred,type = "l")
plot(prob, type = "l")
head(prob)
tail(prob)
pred_direction <- NULL
pred_direction[prob > 0.5] <- 1
pred_direction[prob <= 0.5] <- 0
pred_direction
#오차행렬에 집어넣을 때, pred_direction이랑 norm_isdji 간 객체 차 존재. Table로 집어넣어야 함, e1071패키지 설치 후 실행
matrix <- confusionMatrix(table(pred_direction,norm_isGAX$Direction))
matrix
#예측 정확도 94%
#정규화
osidn <- matrix(1,dim(osGAX)[1], dim(osGAX)[2])
norm_osGAX <- (osGAX - t(isme*t(osidn))) / t(isstd*t(osidn))
dm <- dim(osGAX)
norm_osGAX[,dm[2]] <- direction[osrow]
#표본 외 데이터 값, 확률
ospred <- predict(model, norm_osGAX)
osprob <- 1/(1+exp(-(ospred)))
ospred_direction <- NULL
ospred_direction[osprob >0.5]<-1
ospred_direction[osprob<=0.5]<-0
osmatrix <- confusionMatrix(table(ospred_direction, norm_osGAX$Direction))
osmatrix
#84% accuracy, 트레이딩 비용, 시장 슬리피지 고려X, 다른 전략 X 오로지 예측
#### 트레이딩 후 Cummulative return 구하는 코딩
#로지스틱 CUM RET 구하는 법
signal <- ifelse(ospred_direction == 1, 1, ifelse(ospred_direction == 0,-1,0))
testrow <- which(index(GAX) >= ossd & index(GAX) <= osed)
GAX <- GOLD.AX$GOLD.AX.Close
ret <- GAX/lag(GAX) -1
ret <- ret[testrow]
ret
cost <- 0
length(signal)
length(ret)
dim(ret)
length(testrow)
trade_ret <- ret * Lag(signal) - cost
dim(ret)
cumm_ret <- Return.cumulative(trade_ret)
anual_ret <- Return.annualized(trade_ret)
charts.PerformanceSummary(trade_ret)
cumm_ret
anual_ret
### Neural Network Machine Learning ###
rm(list=ls())
getSymbols("GOLD.AX", src = "yahoo")
GAX <- GOLD.AX[,"GOLD.AX.Close"]
GAX <- na.omit(GAX)
chartSeries(ClCl(GAX))
plot(GAX)
#수익률 계산, 델타 함수가 안되어요 ㅜㅜ
ret <- GAX/lag(GAX) -1 # 중요함
avg10 <- rollapply(GAX,10,mean)
avg20 <- rollapply(GAX,20,mean)
std10<-rollapply(GAX,10,sd)
std20<-rollapply(GAX,20,sd)
rsi5 <- RSI(GAX,5,"SMA")
rsi14<-RSI(GAX,14,"SMA")
macd12269 <- MACD(GAX,12,26,9,"SMA")
macd7205 <- MACD(GAX,7,20,5,"SMA")
bbands<-BBands(GAX,20,"SMA",2)
#지난 20일간 수익률 2% 이상이면 up, -2% down, 그사이 nowhere
direction <- data.frame(matrix(NA,dim(GAX)[1],1))
#20일 수익률
lagret <- (GAX - Lag(GAX,20)) / Lag(GAX,20)
direction[lagret > 0.02] <- "Up"
direction[lagret < -0.02] <- "Down"
direction[lagret < 0.02 & lagret > -0.02] <- "Nowhere"
GAX <- cbind(GAX,avg10,avg20, std10, std20,rsi5,rsi14,macd12269,macd7205,bbands)
#훈련용, 검증용, 평가용 데이터집합
train_sdate <- "2013-01-01"
train_edate <- "2016-12-31"
vali_sdate <- "2017-01-01"
vali_edate <- "2017-12-31"
test_sdate <- "2018-01-01"
test_edate <- "2018-12-31"
trainrow <- which(index(GAX) >= train_sdate & index(GAX) <= train_edate)
valirow <- which(index(GAX) >= vali_sdate & index(GAX) <= vali_edate)
testrow <- which(index(GAX) >= test_sdate & index(GAX) <= test_edate)
trainGAX <- GAX[trainrow,]
valiGAX <- GAX[valirow,]
testGAX <- GAX[testrow,]
trainme <- apply(trainGAX,2,mean)
trainstd <- apply(trainGAX,2,sd)
#정규화
trainidn <- (matrix(1,dim(trainGAX)[1],dim(trainGAX)[2]))
valiidn <- (matrix(1,dim(valiGAX)[1],dim(valiGAX)[2]))
testidn <- (matrix(1,dim(testGAX)[1],dim(testGAX)[2]))
norm_trainGAX <- (trainGAX - t(trainme*t(trainidn)))/t(trainstd*t(trainidn))
norm_valiGAX <- (valiGAX - t(trainme*t(valiidn)))/t(trainstd*t(valiidn))
norm_testGAX <- (testGAX - t(trainme*t(testidn)))/t(trainstd*t(testidn))
traindir <- direction[trainrow,1]
validir <- direction[valirow,1]
testdir<-direction[testrow,1]
#신경망 적합(정규화열,날짜별 방향, 신경수, 트레이스 출력 여부)
set.seed(1)
model <- nnet(norm_trainGAX, class.ind(traindir),size = 4, trace = F)
model
dim(norm_trainGAX)
vali_pred <- predict(model, norm_valiGAX)
head(vali_pred)
vali_pred_class <- data.frame(matrix(NA,dim(vali_pred)[1],1))
vali_pred_class[vali_pred[,"Down"]>0.5, 1]<- "Down"
vali_pred_class[vali_pred[,"Nowhere"]>0.5,1] <- "Nowhere"
vali_pred_class[vali_pred[,"Up"]>0.5, 1] <- "Up"
vali_pred_class
matrix<- confusionMatrix(table(vali_pred_class[,1],validir))
matrix
#87.65%
test_pred <- predict(model,norm_testGAX)
test_pred_class <- data.frame(matrix(NA,dim(test_pred)[1],1))
test_pred_class[test_pred[,"Down"]>0.5, 1]<- "Down"
test_pred_class[test_pred[,"Nowhere"]>0.5,1] <- "Nowhere"
test_pred_class[test_pred[,"Up"]>0.5, 1] <- "Up"
test_matrix <- confusionMatrix(table(test_pred_class[,1],testdir))
test_matrix
#82pro
#Signal generator
signal <- ifelse(test_pred_class == "Up", 1, ifelse(test_pred_class == "Down",-1,0))
ret <- ret[testrow]
ret
cost <- 0
trade_ret <- ret * Lag(signal) - cost
cumm_ret <- Return.cumulative(trade_ret)
anual_ret <- Return.annualized(trade_ret)
charts.PerformanceSummary(trade_ret)
#charts.PerformanceSummary(cumm_ret)
#plot(cumm_ret)
#Deep Neural Network
set.seed(1)
model <- dbn.dnn.train(norm_testGAX,class.ind(traindir),hidden=c(3,4,6))
nn.predict(model,norm_valiGAX)
nn.test(model,norm_valiGAX,class.ind(validir),t=0.4)
data <- cbind(as.data.frame(norm_trainGAX),traindir)
class(norm_trainGAX)
class(traindir)
h2o.init()
datah2o <- as.h2o(data,"h2o")
class(datah2o)
dim(datah2o)
#은닉층이 4개, 각 뉴런수 4,5,2,7
model <- h2o.deeplearning(1:15, 16,training_frame = datah2o,hidden = c(4,5,2,7))
vali_pred <- predict(model, as.h2o(norm_valiGAX,"h2o"))
vali_pred <- as.data.frame(vali_pred)
vali_pred_class <- data.frame(matrix(NA,dim(vali_pred)[1],1))
vali_pred_class[vali_pred[,"Down"]>0.5, 1]<- "Down"
vali_pred_class[vali_pred[,"Nowhere"]>0.5,1] <- "Nowhere"
vali_pred_class[vali_pred[,"Up"]>0.5, 1] <- "Up"
vali_matrix <- confusionMatrix(table(vali_pred_class[,1],validir))
vali_matrix
## Deep Graph ##
signal <- ifelse(vali_pred_class == "Up", 1, ifelse(vali_pred_class == "Down",-1,0))
ret <- GAX/lag(GAX) -1 # 중요함
ret <- ret[valirow]
ret <- ret[,1]
cost <- 0
trade_ret <- ret * Lag(signal) - cost
cumm_ret <- Return.cumulative(trade_ret)
anual_ret <- Return.annualized(trade_ret)
charts.PerformanceSummary(trade_ret)
rm(list=ls())
getSymbols("GOLD.AX", src = "yahoo")
GAX <- GOLD.AX
GAX <- GAX[,"GOLD.AX.Close"]
GAX <- na.omit(GAX)
avg10 <- rollapply(GAX, 10, mean)
avg20 <- rollapply(GAX, 20, mean)
std10 <- rollapply(GAX,10,sd)
std20 <- rollapply(GAX,20,sd)
rsi5 <- RSI(GAX, 5, "SMA")
rsi14 <- RSI(GAX, 14, "SMA")
macd12269 <- MACD(GAX, 12, 26, 9, "SMA")
macd7205 <- MACD(GAX, 7, 20, 5, "SMA")
bbands <- BBands(GAX, 20, "SMA", 2)
direction <- NULL
direction[GAX > Lag(GAX, 20)] <- 1
direction[GAX < Lag(GAX, 20)] <- 0
GAX <- cbind(GAX, avg10, avg20, std10, std20, rsi5, rsi14, macd12269, macd7205, bbands, direction)
dm <- dim(GAX)
dm
colnames(GAX)[dm[2]]
colnames(GAX)[dm[2]] <- "Direction"
colnames(GAX)
issd <- "2013-01-01"
ised <- "2017-12-31"
ossd <- "2018-01-01"
osed <- "2018-12-31"
isrow <- which(index(GAX) >= issd & index(GAX) <= ised)
osrow <- which(index(GAX) >= ossd & index(GAX) <= osed)
isGAX <- GAX[isrow,]
osGAX <- GAX[osrow,]
#표준화
isme <- apply(isGAX, 2, mean)
isstd <- apply(isGAX, 2, sd)
isidn <- matrix(1, dim(isGAX)[1], dim(isGAX)[2])
norm_isGAX <- (isGAX - t(isme * t(isidn))) / t(isstd * t(isidn))
norm_isGAX
dm<-dim(isGAX)
norm_isGAX[,dm[2]] <- direction[isrow]
#정규화
osidn <- matrix(1,dim(osGAX)[1], dim(osGAX)[2])
norm_osGAX <- (osGAX - t(isme*t(osidn))) / t(isstd*t(osidn))
dm <- dim(osGAX)
norm_osGAX[,dm[2]] <- direction[osrow]
#방향설정
GAX <- GOLD.AX
GAX <- GAX[,"GOLD.AX.Close"] #다시 설정
GAX <- na.omit(GAX)
lagret <- (GAX - Lag(GAX,20))/Lag(GAX,20)
direction[lagret >0.02]<-"Up"
direction[lagret < -0.02]<-"Down"
direction[lagret < 0.02 & lagret > -0.02]<-"Nowhere"
isdir <- direction[isrow]
osdir <- direction[osrow]
model <- svm(norm_isGAX, as.factor(isdir))
model
pred <- predict(model, norm_osGAX)
head(pred)
table(pred,osdir)
model
#적중률
sum(diag(table(pred,osdir)))/sum(table(pred,osdir))
####서포트벡터 트레이딩 후 Cummulative return 구하는 코딩
signal <- ifelse(pred == "Up", 1, ifelse(pred == "Down",-1,0))
#테스트할 날짜 데이터 집합
testrow <- which(index(GAX) >= ossd & index(GAX) <= osed)
testrow
#리턴 구하는 공식과 그 공식 활용 테스트 날짜별 리턴
ret <- GAX/lag(GAX) -1
ret <- ret[testrow]
ret
cost <- 0
trade_ret <- ret * Lag(signal) - cost
length(signal)
dim(ret)
cumm_ret <- Return.cumulative(trade_ret)
anual_ret <- Return.annualized(trade_ret)
charts.PerformanceSummary(trade_ret)
### K-clustering ###
rm(list=ls())
#Data
getSymbols("GOLD.AX", src = "yahoo")
GAX <- GOLD.AX
GAX <- GAX[,"GOLD.AX.Close"]
GAX <- na.omit(GAX)
#variable
avg10 <- rollapply(GAX, 10, mean)
avg20 <- rollapply(GAX, 20, mean)
std10 <- rollapply(GAX,10,sd)
std20 <- rollapply(GAX,20,sd)
rsi5 <- RSI(GAX, 5, "SMA")
rsi14 <- RSI(GAX, 14, "SMA")
macd12269 <- MACD(GAX, 12, 26, 9, "SMA")
macd7205 <- MACD(GAX, 7, 20, 5, "SMA")
bbands <- BBands(GAX, 20, "SMA", 2)
direction <- NULL
direction[GAX > Lag(GAX, 20)] <- 1
direction[GAX < Lag(GAX, 20)] <- 0
GAX <- cbind(GAX, avg10, avg20, std10, std20, rsi5, rsi14, macd12269, macd7205, bbands, direction)
dm <- dim(GAX)
dm
colnames(GAX)[dm[2]]
colnames(GAX)[dm[2]] <- "Direction"
colnames(GAX)
issd <- "2013-01-01"
ised <- "2017-12-31"
ossd <- "2018-01-01"
osed <- "2018-12-31"
isrow <- which(index(GAX) >= issd & index(GAX) <= ised)
osrow <- which(index(GAX) >= ossd & index(GAX) <= osed)
isGAX <- GAX[isrow,]
osGAX <- GAX[osrow,]
#표준화
isme <- apply(isGAX, 2, mean)
isstd <- apply(isGAX, 2, sd)
isidn <- matrix(1, dim(isGAX)[1], dim(isGAX)[2])
norm_isGAX <- (isGAX - t(isme * t(isidn))) / t(isstd * t(isidn))
dm<-dim(isGAX)
norm_isGAX[,dm[2]] <- direction[isrow]
osidn <- matrix(1,dim(osGAX)[1], dim(osGAX)[2])
norm_osGAX <- (osGAX - t(isme*t(osidn))) / t(isstd*t(osidn))
dm <- dim(osGAX)
norm_osGAX[,dm[2]] <- direction[osrow]
clusters <- 3
set.seed(1)
#디렉션 제거
dm<- dim(isGAX)
isGAX[,-dm[2]]
isGAX <- isGAX[,-dm[2]]
norm_isGAX <- norm_isGAX[,-dm[2]]
dm<-dim(osGAX)
osGAX<-osGAX[,-dm[2]]
norm_osGAX<-norm_osGAX[,-dm[2]]
#isdji 바탕으로 클러스터화 모델
model <- kmeans(norm_isGAX, clusters)
head(model$cluster)
model$cluster
model$center
model$size
#클러스터 내제곱합과 총제곱합 비율 최소화
model$tot.withinss
model$totss
model$tot.withinss/model$totss
ospredict <- cl_predict(model, norm_osGAX)
norm_osGAX
head(ospredict)
ospredict
GAX <- GOLD.AX
GAX <- GAX[,"GOLD.AX.Close"]
GAX <- na.omit(GAX)
lagret <- (GAX - Lag(GAX,20))/Lag(GAX,20)
direction[lagret >0.02]<-"Up"
direction[lagret < -0.02]<-"Down"
direction[lagret < 0.02 & lagret > -0.02]<-"Nowhere"
isdir <- direction[isrow]
osdir <- direction[osrow]
neighborhood <- 3
set.seed(1)
dim(norm_isGAX)
dim(norm_osGAX)
model <- knn(norm_isGAX, norm_osGAX, isdir, neighborhood)
model
head(model)
summary(model)
matrix <- confusionMatrix(table(model, osdir))
matrix
diag(matrix$table)
#for 사용해 confusionmatrix의 행렬 계산, 총 대각선 요소-총대각선 요소 수/총데이터요소수
accuracy<- NULL
for(i in c(1:100)){
model <- knn(isGAX, osGAX, isdir, i)
matrix <- confusionMatrix(table(model,osdir))
diag <- sum(diag(matrix$table))
total <- sum(matrix$table)
accuracy[i] <- (total - diag)/total
}
accuracy
plot(accuracy,type = "l")
plot(accuracy,label = "Accuracy of K % " ,type = "l")
#for 사용해 confusionmatrix의 행렬 계산, 총 대각선 요소-총대각선 요소 수/총데이터요소수
accuracy<- NULL
for(i in c(1:100)){
model <- knn(isGAX, osGAX, isdir, i)
matrix <- confusionMatrix(table(model,osdir))
diag <- sum(diag(matrix$table))
total <- sum(matrix$table)
accuracy[i] <- diag/total
}
accuracy
plot(accuracy ,type = "l")
install.packages('tidyverse')
### ##K Cluster 모형 CumRet 구하는법
GAX <- GOLD.AX
GAx <- GOLD.AX[,"GOLD.AX.Close"]
GAX <- na.omit(GAX)
signal <- ifelse( model== "Up", 1, ifelse( model== "Down",-1,0))
testrow <- which(index(GAX) >= ossd & index(GAX) <= osed)
ret <- GAX/lag(GAX,1) -1
ret <- ret[testrow]
ret
cost <- 0
length(signal)
length(ret)
length(testrow)
trade_ret <- ret * Lag(signal) - cost
signal
length(signal)
dim(ret)
cumm_ret <- Return.cumulative(trade_ret)
anual_ret <- Return.annualized(trade_ret)
charts.PerformanceSummary(trade_ret)
GAX <- GOLD.AX
GAx <- GOLD.AX[,"GOLD.AX.Close"]
GAX <- na.omit(GAX)
GAX <- GOLD.AX
GAX <- GOLD.AX[,"GOLD.AX.Close"]
GAX <- na.omit(GAX)
signal <- ifelse( model== "Up", 1, ifelse( model== "Down",-1,0))
testrow <- which(index(GAX) >= ossd & index(GAX) <= osed)
ret <- GAX/lag(GAX,1) -1
ret <- ret[testrow]
ret
cost <- 0
length(signal)
length(ret)
length(testrow)
trade_ret <- ret * Lag(signal) - cost
signal
length(signal)
dim(ret)
cumm_ret <- Return.cumulative(trade_ret)
anual_ret <- Return.annualized(trade_ret)
charts.PerformanceSummary(trade_ret)
plot(GAX)