-
Notifications
You must be signed in to change notification settings - Fork 0
/
plots_study.R
197 lines (133 loc) · 6.84 KB
/
plots_study.R
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
##### Different type of plots are tried in this plot.
# This code file has trial and error plots and data.
# It mainly uses stats object obtained from results$tradeStats
#Author: Onur Boyar
hp0 <- HP.Filter(Cl(BIST), 0)
#hp10 <- HP.Filter(Cl(BIST),10)
hp100 <- HP.Filter(Cl(BIST),100)
hp1600 <- HP.Filter(Cl(BIST), 1600)
hp3600 <- HP.Filter(Cl(BIST), 3600)
comparison = c(Cl(BIST), hp3600)
plot(comparison,
plot.type = "single",
col = c("brown", "black"))
plot(hp100)
#install.packages('tseries')
library("tseries")
comb_ts <- cbind(Cl(BIST), hp3600) # please make sure the length of both your timeseries
plot.ts(comb_ts, plot.type = "single")
par(mfrow = c(1,2))
stats <- stats[order(stats$Ann.Sharpe, decreasing = T),]
barplot(stats$Ann.Sharpe[1:10],
names.arg=paste(stats$F_Fast[1:10],stats$F_Slow[1:10], sep="/"),
las=2,cex.names=0.75)
stats <- stats[order(stats$Ann.Sharpe, decreasing = F),]
barplot(stats$Ann.Sharpe[1:10],
names.arg=paste(stats$F_Fast[1:10],stats$F_Slow[1:10], sep="/"),
las=2,cex.names=0.75)
stats <- stats[order(stats$Profit.To.Max.Draw, decreasing = T),]
barplot(stats$Profit.To.Max.Draw[1:10],
names.arg=paste(stats$F_Fast[1:10],stats$F_Slow[1:10], sep="/"),
las=2,cex.names=0.75)
stats <- stats[order(stats$Profit.To.Max.Draw, decreasing = F),]
barplot(stats$Profit.To.Max.Draw[1:10],
names.arg=paste(stats$F_Fast[1:10],stats$F_Slow[1:10], sep="/"),
las=2,cex.names=0.75)
ggplot(stats) + geom_point(aes(y = Ann.Sharpe, x = Profit.To.Max.Draw, color = Symbol), size =5) #+ xlim(c(10,30))
stats <- stats[order(stats$Avg.WinLoss.Ratio, decreasing = T),]
barplot(stats$Avg.WinLoss.Ratio[1:10],
names.arg=paste(stats$F_Fast[1:10],stats$F_Slow[1:10], sep="/"),
las=2,cex.names=0.75)
stats <- stats[order(stats$Med.WinLoss.Ratio, decreasing = T),]
barplot(stats$Med.WinLoss.Ratio[1:10],
names.arg=paste(stats$F_Fast[1:10],stats$F_Slow[1:10], sep="/"),
las=2,cex.names=0.75)
# burada en iyi deger hangisi onu konus
chart.Posn(portfolio.st, "BIST")
#
Eq<-getAccount(account.st)$summary[,"End.Eq"]
plot(Eq)
chart.ME(portfolio.st, 'BIST', scale='percent', type='MAE')
chart.ME(portfolio.st, 'BIST', scale='percent', type='MFE')
stats$ratio <- stats$F_Fast / stats$F_Slow
ggplot(stats) + geom_point(aes(y = Ann.Sharpe, x = ratio, color = Symbol), size =5) #+ xlim(c(10,30))
ggplot(stats) + geom_point(aes(y = Profit.To.Max.Draw, x = ratio, color = Symbol), size =5) #+ xlim(c(10,30))
sharpe_groups_mean = stats %>% group_by(Symbol) %>% summarise(mean = mean(na.omit(Ann.Sharpe)))
sharpe_groups_median = stats %>% group_by(Symbol) %>% summarise(median = median(na.omit(Ann.Sharpe)))
p.max.dr_mean = stats %>% group_by(Symbol) %>% summarise(mean = mean(na.omit(Profit.To.Max.Draw)))
p.max.dr_median = stats %>% group_by(Symbol) %>% summarise(median = median(na.omit(Profit.To.Max.Draw)))
ending_mean = stats %>% group_by(Symbol) %>% summarise(mean = mean(End.Equity))
average.min_loss = stats %>% group_by(Symbol) %>% summarise(mean = mean(Avg.WinLoss.Ratio))
med.min_loss = stats %>% group_by(Symbol) %>% summarise(mean = mean(Med.WinLoss.Ratio))
p1 <- ggplot(sharpe_groups_mean) + geom_bar(aes(x = Symbol, y = mean, fill = Symbol), stat = 'identity') +
theme(legend.position = "none") + ggtitle('Sharpe Ratio Mean Values') + xlab('Stock Type') +
ylab('Mean Value')
p2 <- ggplot(p.max.dr_mean) + geom_bar(aes(x = Symbol, y = mean, fill = Symbol), stat = 'identity') +
ggtitle('Profit to Max Drawdown Mean Values')+ xlab('Stock Type') +
ylab('Mean Value')
p2
library(ggpubr)
ggarrange(p1, p2)
sharpe_groups_max = stats %>% group_by(Symbol) %>% summarise(max = max(na.omit(Ann.Sharpe)))
sharpe_groups_min = stats %>% group_by(Symbol) %>% summarise(min = min(na.omit(Ann.Sharpe)))
sharpe_sd = stats %>% group_by(Symbol) %>% summarise(sd = sd(na.omit(Ann.Sharpe)))
p.mdraw_sd = stats %>% group_by(Symbol) %>% summarise(sd = sd(na.omit(Profit.To.Max.Draw)))
p.mdraw_max = stats %>% group_by(Symbol) %>% summarise(max = max(na.omit(Profit.To.Max.Draw)))
p.mdraw_min = stats %>% group_by(Symbol) %>% summarise(min = min(na.omit(Profit.To.Max.Draw)))
par(mfrow = c(1,2))
stats <- stats[order(stats$Ann.Sharpe, decreasing = T),]
# her grup icin en yuksek 10 Ann.Sharpe Geldi
x <- stats %>%
group_by(Symbol) %>%
top_n(10, Ann.Sharpe)
stats <- stats[order(stats$Ann.Sharpe, decreasing = T),]
barplot(stats$Ann.Sharpe[1:5],
names.arg=paste(round(stats$Profit.To.Max.Draw[1:5],2)),
las=2,cex.names=0.75)
title(main = list("Maximum and Minumum Sharpe Ratios with Diferent F Values", font = 4))
stats <- stats[order(stats$Profit.To.Max.Draw, decreasing = T),]
barplot(stats$Profit.To.Max.Draw[1:5],
names.arg=paste(round(stats$Ann.Sharpe[1:5], 2)),
las=2,cex.names=0.75)
### burada 0.1/0.4 hem cok iyi hem cok kotu. bir hisse icin
# iyi sonuc verirken digeri icin cok kotu veriyor. onlar hangileri?
f_vals <- stats[stats$F_Fast == 0.1 & stats$F_Slow == 0.4,]
f_vals[which.min(f_vals$Ann.Sharpe),]$Symbol
f_vals[which.max(f_vals$Ann.Sharpe),]$Symbol
comparison = cbind(Cl(MGROS), Cl(TTKOM), my.lowess(MGROS, 0.1), my.lowess(MGROS, 0.4))
plot(comparison,
plot.type = "single",
col = c("red", "blue", "black", "brown"))
#title(main = list("Min Sharpe Ratios with Different F Values", font = 4))
# Kardemir icin lowess'li degerler ve gercek degerin gorseli
stats_krd = stats[stats$Symbol == 'KRDMD',]
# 0.1, 0.2
krdmd.fast <- my.lowess(KRDMD, 0.1)
krdmd.slow <- my.lowess(KRDMD, 0.2)
plot(krdmd.fast)
comparison = cbind(Cl(KRDMD), krdmd.fast, krdmd.slow)
plot(comparison,
plot.type = "single",
col = c("gray","red", "blue"))
## simple_lwess icin en iyi f degerlerinden gelen
# smoothed grafik, ve orjinal deger ust uste!!!
#############################################################
###
# burada her grup icin en iyi 5 sharpe, 5 P.Max Drawdown, Grup bazli
# Sonra da genel.
x_sharpe <- stats %>%
group_by(Symbol) %>%
top_n(5, Ann.Sharpe)
x_p.max <- stats %>%
group_by(Symbol) %>%
top_n(5, Profit.To.Max.Draw)
ggplot(x_p.max) + geom_point(aes(y = Ann.Sharpe, x = Profit.To.Max.Draw, color = Symbol), size =5) #+ xlim(c(10,30))
barplot(stats[stats$Symbol == 'TTKOM',]$Ann.Sharpe[1:10],
names.arg=paste(stats$F_Fast[1:10],stats$F_Slow[1:10], sep="/"),
las=2,cex.names=0.75)
sharpe_groups_max = stats %>% group_by(Symbol) %>% summarise(max = max(na.omit(Ann.Sharpe)))
sharpe_groups_min = stats %>% group_by(Symbol) %>% summarise(min = min(na.omit(Ann.Sharpe)))
sharpe_sd = stats %>% group_by(Symbol) %>% summarise(sd = sd(na.omit(Ann.Sharpe)))
p.mdraw_sd = stats %>% group_by(Symbol) %>% summarise(sd = sd(na.omit(Profit.To.Max.Draw)))
p.mdraw_max = stats %>% group_by(Symbol) %>% summarise(max = max(na.omit(Profit.To.Max.Draw)))
p.mdraw_min = stats %>% group_by(Symbol) %>% summarise(min = min(na.omit(Profit.To.Max.Draw)))