-
Notifications
You must be signed in to change notification settings - Fork 20
/
research.r.R
324 lines (286 loc) · 11.5 KB
/
research.r.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
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
library(psych)
library(magrittr)
source("./indicatorPlots.r")
symbol <- "BTC-USD"
securityData <- mainOpenSecurity(symbol, 14, 28, "%Y-%m-%d", "2010-01-01")
# Experiment grid search with different aspects energy factors.
filterFeatures <- c(
'Date', 'origin', 'type', 'p.x', 'p.y',
'orb', 'lon.y', 'lon.x',
#'sp.y', 'sp.x', 'spn.y', 'spn.x',
#'act', 'agt',
paste("a", aspects, ".x", sep = ""),
#paste("a", aspects, ".y", sep = ""),
paste("a", aspects, sep = ""),
paste("a", aspects, ".g", sep = ""),
'orbdir'
)
dailyAspects <- prepareHourlyAspectsModelK()
dailyAspectsPrice <- merge(securityData[, c('Date', 'diffPercent')], dailyAspects, by = "Date")
dailyAspectsPrice[, result := cut(diffPercent, c(-100, 0, 100), c("down", "up"))]
#dailyAspects[, apos := a60.x + a60.y + a120.x + a120.y]
#dailyAspects[, aneg := a90.x + a90.y + a150.x + a150.y]
#dailyAspects[, aneg := a90.x + a90.y + a180.x + a180.y]
#dailyAspects[, apos := a60.x + a60.y + a120.x + a120.y]
#dailyAspects[, apos := a60.t + a60.t + a120.t + a120.t]
#dailyAspects[, aneg := a90.t + a90.t + a150.t + a150.t]
# dailyAspects[, adiff := apos - aneg]
# dailyAspects[, apos2 := apos]
# dailyAspects[adiff > 0, apos2 := apos + a0 + a180 + a150]
# dailyAspects[, aneg2 := aneg]
# dailyAspects[adiff < 0, aneg2 := aneg + a0 + a180 + a150]
# dailyAspects[, adiff2 := apos2 - aneg2]
# dailyAspects[, orbtype := cut(orb, seq(0, 12, by = 1))]
# Price diff aspect histogram / x & y speed for fast planets except MO.
ggplot(data = dailyAspectsPrice[p.x %ni% c('MO', 'JU', 'NN', 'SA', 'UR', 'NE', 'PL'),]) +
geom_point(aes(y = spn.y, x = diffPercent), color = "gray") +
stat_ellipse(aes(y = spn.y, x = diffPercent), type = "norm", color = "yellow") +
facet_grid(aspect ~ origin, scales = "free") +
theme_black()
ggplot(data = dailyAspectsPrice[p.x %ni% c('MO', 'JU', 'NN', 'SA', 'UR', 'NE', 'PL'),]) +
geom_point(aes(y = spn.x, x = diffPercent), color = "gray") +
stat_ellipse(aes(y = spn.x, x = diffPercent), type = "norm", color = "yellow") +
facet_grid(aspect ~ origin, scales = "free") +
theme_black()
ggplot(data = dailyAspectsPrice[p.x %ni% c('MO', 'JU', 'NN', 'SA', 'UR', 'NE', 'PL'),]) +
aes(x = diffPercent) +
geom_histogram(color = "gray", bins = 25) +
geom_vline(xintercept = 0, linetype = "dashed", color = "red", size = 0.6, alpha = 0.7) +
facet_grid(aspect ~ origin, scales = "free_y") +
theme_black()
# Price diff aspect histogram / x & y speed for MO and slow planets.
ggplot(data = dailyAspectsPrice[p.x %in% c('MO', 'JU', 'NN', 'SA', 'UR', 'NE', 'PL'),]) +
aes(x = diffPercent) +
geom_histogram(color = "gray", bins = 25) +
geom_vline(xintercept = 0, linetype = "dashed", color = "red", size = 0.6, alpha = 0.7) +
facet_grid(aspect ~ origin, scales = "free_y") +
theme_black()
ggplot(data = dailyAspectsPrice[p.x %in% c('MO', 'JU', 'NN', 'SA', 'UR', 'NE', 'PL'),]) +
geom_point(aes(y = spn.y, x = diffPercent), color = "gray") +
stat_ellipse(aes(y = spn.y, x = diffPercent), type = "norm", color = "yellow") +
facet_grid(aspect ~ origin, scales = "free") +
theme_black()
ggplot(data = dailyAspectsPrice[p.x %in% c('MO', 'JU', 'NN', 'SA', 'UR', 'NE', 'PL'),]) +
geom_point(aes(y = spn.x, x = diffPercent), color = "gray") +
stat_ellipse(aes(y = spn.x, x = diffPercent), type = "norm", color = "yellow") +
facet_grid(aspect ~ origin, scales = "free") +
theme_black()
dailyAspectsFast <- dailyAspectsPrice[
p.x %ni% c('CE', 'JU', 'SA', 'UR', 'NE', 'PL')
][
origin %ni% c('MESU'),
]
# Fast planets former bodies speed effect.
ggplot(data = dailyAspectsFast) +
aes(y = sp.x, x = diffPercent) +
#aes(y=spn.x, x=diffPercent, color=type) +
geom_point(color = "white") +
facet_grid(aspect ~ origin, scales = "free_y") +
stat_ellipse(type = "norm", color = "yellow") +
scale_x_continuous(limits = c(-10, 10)) +
#scale_y_continuous(limits=c(0, 1)) +
#geom_smooth(orientation="y") +
theme_black()
# Fast planets former bodies speed effect.
ggplot(data = dailyAspectsFast) +
aes(y = sp.x, x = diffPercent) +
#aes(y=spn.x, x=diffPercent, color=type) +
geom_point(color = "white") +
facet_grid(aspect ~ origin, scales = "free_y") +
stat_ellipse(type = "norm", color = "yellow") +
scale_x_continuous(limits = c(-10, 10)) +
#scale_y_continuous(limits=c(0, 1)) +
#geom_smooth(orientation="y") +
theme_black()
ggplot(data = dailyAspectsFast) +
aes(y = sp.y, x = diffPercent) +
geom_point(color = "white") +
facet_grid(aspect ~ origin, scales = "free_y") +
stat_ellipse(type = "norm", color = "yellow") +
scale_x_continuous(limits = c(-10, 10)) +
theme_black()
# Cumulative former bodies external aspects energy effect.
ggplot(data = dailyAspectsFast) +
aes(y = enpos, x = abs(diffPercent)) +
#aes(y=spn.x, x=diffPercent, color=type) +
geom_point(color = "white") +
facet_grid(aspect ~ origin, scales = "free_y") +
stat_ellipse(type = "norm", color = "yellow") +
scale_x_continuous(limits = c(0, 10)) +
#scale_y_continuous(limits=c(0, 1)) +
#geom_smooth(orientation="y") +
theme_black()
# Cumulative former bodies slow boody external energy.
ggplot(data = dailyAspectsFast) +
aes(y = encum.y, x = abs(diffPercent)) +
#aes(y=spn.x, x=diffPercent, color=type) +
geom_point(color = "white") +
facet_grid(aspect ~ origin, scales = "free_y") +
stat_ellipse(type = "norm", color = "yellow") +
scale_x_continuous(limits = c(0, 10)) +
#scale_y_continuous(limits=c(0, 1)) +
#geom_smooth(orientation="y") +
theme_black()
# Cumulative former bodies fast boody external energy.
ggplot(data = dailyAspectsFast) +
aes(y = encum.x, x = abs(diffPercent)) +
#aes(y=spn.x, x=diffPercent, color=type) +
geom_point(color = "white") +
facet_grid(aspect ~ origin, scales = "free_y") +
stat_ellipse(type = "norm", color = "yellow") +
scale_x_continuous(limits = c(0, 10)) +
#scale_y_continuous(limits=c(0, 1)) +
#geom_smooth(orientation="y") +
theme_black()
# Slow planets former bodies speed effect.
dailyAspectsSlow <- dailyAspectsPrice[
p.x %in% c('CE', 'JU', 'SA', 'UR', 'NE', 'PL')
][
origin %ni% c('MESU')
]
ggplot(data = dailyAspectsSlow) +
aes(y = sp.x, x = diffPercent) +
geom_point(color = "white") +
facet_grid(aspect ~ origin, scales = "free_y") +
stat_ellipse(type = "norm", color = "yellow") +
scale_x_continuous(limits = c(-10, 10)) +
theme_black()
ggplot(data = dailyAspectsSlow) +
aes(y = sp.y, x = diffPercent) +
geom_point(color = "white") +
facet_grid(aspect ~ origin, scales = "free_y") +
stat_ellipse(type = "norm", color = "yellow") +
scale_x_continuous(limits = c(-10, 10)) +
theme_black()
# Own aspect energy.
ggplot(data = dailyAspectsFast) +
aes(y = ennow, x = abs(diffPercent)) +
#aes(y=spn.x, x=diffPercent, color=type) +
geom_point(color = "white") +
facet_grid(aspect ~ origin, scales = "free_y") +
stat_ellipse(type = "norm", color = "yellow") +
scale_x_continuous(limits = c(0, 10)) +
#scale_y_continuous(limits=c(0, 1)) +
#geom_smooth(orientation="y") +
theme_black()
# CONCLUSIONS (DAILY CURRENT ASPECTS):
# 1) The retrograde motions of ME highly correlates with positive/negative aspect effect.
# 2) With lower evidence the MA, CE and JU retrograde motion seems that may affect the effect but we don't have enough data.
# 3) Applicative / separative aspect transition show an important change of the effect after partil.
# 4) Classical aspects in partil orb seems to show the highest effect.
# 5) Interaction of other aspects within same orb correlates with higher effect, joining forces.
# 6) Aspects former planets received cumulative energy from other aspects show relation to the increase on priece effect
# in few aspects, for higher cumulative energy more drastical price moves.
# 7) Some aspects with high cumulative energy activation seems to block price move effect that resume when effect pass away,
# is possible that this is caused by the opposite polarity combination of former planets or external aspects that neutralize.
library(caret)
library(randomForest)
library(rattle)
library(tidyverse)
library(parallel)
aspectView <- dailyAspectsPrice[p.x == "MO" & aspect == 120]
aspectView[, result := cut(diffPercent, c(-1, 0, 1), c("down", "up"))]
selectCols <- c("spd", "spp", "spr", "dcd", "dcp", "dcr", "VE", "VE.x", "acx", "acy", "result")
#selectCols <- c("dcd", "dcp", "dcr", "result")
#selectCols <- c(20, 22, 81:91, 92)
aspectView <- aspectView[, ..selectCols]
aspectViewTrain <- aspectView %>% sample_frac(.70)
aspectViewTest <- aspectView %>% anti_join(aspectViewTrain)
tree1 = train(
result ~ .,
data = aspectViewTrain,
method = "rpart",
trControl = trainControl(method = "cv")
)
summary(tree1$finalModel)
effect_p <- tree1 %>% predict(newdata = aspectViewTrain)
# Prediction results on train.
table(
actualclass = aspectViewTrain$result,
predictedclass = effect_p
) %>%
confusionMatrix() %>%
print()
effect_p <- tree1 %>% predict(newdata = aspectViewTest)
# Prediction results on test.
table(
actualclass = aspectViewTest$result,
predictedclass = effect_p
) %>%
confusionMatrix() %>%
print()
# Project futures predictions.
futureAspectsView <- dailyAspects[p.x == "MO" & Date == as.Date("2020-09-15")]
selectCols2 <- selectCols[selectCols != "result"]
futureAspectsFeatures <- futureAspectsView[, ..selectCols2]
effect_p <- tree1 %>% predict(newdata = futureAspectsFeatures)
futureAspectsView$effect_p <- effect_p
# Experiment with Random Forest model.
aspectViewRaw <- dailyAspectsPrice[p.x == "MO"]
aspectViewRaw[, result := cut(diffPercent, c(-1, 0, 1), c("down", "up"))]
#selectCols <- c("spp", "dcp", "VE", "VE.x", "acx", "acy", "result")
#selectCols <- c("dcd", "dcp", "dcr", "result")
aspectsT <- paste("a", aspects, sep = "")
aspectsX <- paste("a", aspects, ".x", sep = "")
aspectsY <- paste("a", aspects, ".y", sep = "")
#selectCols <- c("result", "acx", aspectsX, "spp", "dcp", "zx", "zy", "MO", "ME", "VE", "SU", "MA", "JU", "SA")
#selectCols <- c("result", aspectsX, "ME.x", "VE.x", "MA.x", "JU.x", "SA.x", "NN.x")
selectCols <- c("result", aspectsX)
aspectView <- aspectViewRaw[, ..selectCols]
trainIndex <- createDataPartition(aspectView$result, p=0.70, list=FALSE)
aspectViewTrain <- aspectView[trainIndex,]
aspectViewTest <- aspectView[-trainIndex,]
#aspectViewTrain <- aspectView %>% sample_frac(.70)
#aspectViewTest <- aspectView %>% anti_join(aspectViewTrain)
tree.rf <- randomForest(
result ~ .,
data = aspectViewTrain,
ntree = 200,
importance = T,
metric = "Accuracy"
)
print(tree.rf)
varImpPlot(tree.rf)
importance(tree.rf)
control <- trainControl(
method = "repeatedcv",
number = 10,
repeats = 2,
search = "random",
allowParallel = T
)
tree1 = train(
formula(result ~ .),
data = aspectViewTrain,
method = "rf",
metric = "Accuracy",
tuneLength = 2,
ntree = 100,
trControl = control,
importance = T
)
#summary(tree1)
effect_p <- tree1 %>% predict(newdata = aspectViewTrain)
# Prediction results on train.
table(
actualclass = aspectViewTrain$result,
predictedclass = effect_p
) %>%
confusionMatrix() %>%
print()
effect_p <- tree1 %>% predict(newdata = aspectViewTest)
# Prediction results on test.
table(
actualclass = aspectViewTest$result,
predictedclass = effect_p
) %>%
confusionMatrix() %>%
print()
saveRDS(tree1, "./models/MO_general_rf4.rds")
selectCols2 <- selectCols[selectCols != "result"]
futureAspects <- dailyAspects[Date >= as.Date("2020-08-20") & p.x == "MO",]
futureAspectsFeatures <- futureAspects[, ..selectCols2]
effect_p <- tree1 %>% predict(newdata = futureAspectsFeatures)
futureAspects$effect_p <- effect_p
marketPrediction <- futureAspects[, c('Date', "origin", "aspect", "effect_p")]
view(marketPrediction)