Revision | 8ff618b5b4296a81a2181e2cbcc20854e2474f8f (tree) |
---|---|
Zeit | 2024-12-17 01:25:43 |
Autor | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
I modified some paths and changed a bit the code.
@@ -6,6 +6,8 @@ | ||
6 | 6 | library(openxlsx) |
7 | 7 | library(janitor) |
8 | 8 | library(scales) |
9 | +## library(tsfeatures) | |
10 | + | |
9 | 11 | |
10 | 12 | source("/home/lorenzo/myprojects-hg/R-codes/stat_lib.R") |
11 | 13 |
@@ -16,7 +18,7 @@ | ||
16 | 18 | |
17 | 19 | y_size <- 16 |
18 | 20 | |
19 | -days_back <- 40 | |
21 | +days_back <- 120 ## 360 | |
20 | 22 | |
21 | 23 | final_day <- gsub('-', '', today()) |
22 | 24 |
@@ -96,16 +98,21 @@ | ||
96 | 98 | |
97 | 99 | |
98 | 100 | |
99 | -my_symbol_list <- read_excel("portfolio_summary.xlsx") |> | |
101 | +my_symbol_list <- read_excel("../output/portfolio_summary.xlsx") |> | |
100 | 102 | arrange(desc(total_value_usdt)) |> |
101 | 103 | ## slice(1:n_assets) |> |
102 | - filter(total_value_usdt>value_min) |> | |
104 | + ## filter(total_value_usdt>value_min) |> | |
105 | + slice(1:10) |> | |
103 | 106 | mutate(asset=if_else(asset=="BEAMX", "BEAM", asset)) |> |
104 | 107 | pull(asset) |
105 | 108 | |
106 | 109 | |
107 | 110 | coins_all <- crypto_list(only_active=TRUE) |
108 | 111 | |
112 | +all_quotes <- crypto_global_quotes(which="historical", quote=TRUE) | |
113 | + | |
114 | +saveRDS(all_quotes, "../output/market_stats.RDS") | |
115 | + | |
109 | 116 | slug_negation <- c("bigone-token","onedex", "onetoken", |
110 | 117 | "apecoin", "apemove","arbit", "arb-protocol", |
111 | 118 | "beam", "shiba-floki", "baby-moon-floki", "bonk-bnb", |
@@ -140,13 +147,15 @@ | ||
140 | 147 | ## filter(slug %in% mylist_slug) |
141 | 148 | |
142 | 149 | |
143 | - | |
144 | - | |
145 | -coin_hist <- crypto_history(coins, | |
150 | +coin_temp <- crypto_history(coins, | |
146 | 151 | convert = currency, |
147 | 152 | ## limit=3, |
148 | 153 | start_date=initial_day, |
149 | - end_date=final_day, finalWait=FALSE) |> | |
154 | + end_date=final_day, finalWait=FALSE) | |
155 | + | |
156 | + | |
157 | + | |
158 | +coin_hist <- coin_temp |> | |
150 | 159 | mutate(timestamp=as_date(timestamp)) |> |
151 | 160 | group_by(slug) |> |
152 | 161 | arrange(timestamp, .by_group=T) |> |
@@ -158,6 +167,10 @@ | ||
158 | 167 | rename("High"="high", "Low"="low", "Close"="close", |
159 | 168 | "Volume"= "volume") |
160 | 169 | |
170 | + | |
171 | + | |
172 | + | |
173 | + | |
161 | 174 | ## create a simpler tibble with the relevant data |
162 | 175 | |
163 | 176 | df <- coin_hist |> |
@@ -183,14 +196,24 @@ | ||
183 | 196 | |
184 | 197 | ## See https://stackoverflow.com/questions/39638233/grouped-data-frame-to-list/71926304#71926304 |
185 | 198 | |
186 | -df_list <- df |> group_by(symbol, slug) |> | |
187 | - group_map(~.x) | |
199 | +df_list <- df |> | |
200 | + group_by(symbol## , slug | |
201 | + ) |> | |
202 | + group_map(~.x) | |
203 | + | |
188 | 204 | |
189 | 205 | names(df_list) <- df |> group_by(symbol) |> |
190 | 206 | group_map(~.y) |> |
191 | 207 | unlist() |
192 | 208 | |
193 | 209 | |
210 | +df_frame <- df_list |> | |
211 | + bind_rows(.id="coin") |> | |
212 | + select(-ends_with("norm")) | |
213 | + | |
214 | + | |
215 | +saveRDS(df_frame, "../output/coin_prices.RDS") | |
216 | + | |
194 | 217 | ## See https://stackoverflow.com/questions/73714344/how-to-convert-a-list-of-tibbles-tino-a-data-frame-in-r/73714438#73714438 |
195 | 218 | |
196 | 219 | ad_list <- map(df_list,\(x) chaikinAD(x[,c("High","Low","Close")], x[,"Volume"]) |> as_tibble() |> |
@@ -198,34 +221,48 @@ | ||
198 | 221 | bind_rows(.id="coin")|> |
199 | 222 | complete_cases() |
200 | 223 | |
224 | +saveRDS(ad_list, "../output/ad_list.RDS") | |
225 | + | |
226 | + | |
201 | 227 | cmf_list <- map(df_list,\(x) CMF(x[,c("High","Low","Close")], x[,"Volume"])|> as_tibble()|> |
202 | 228 | mutate(timestamp=x$timestamp) )|> |
203 | 229 | bind_rows(.id="coin")|> |
204 | 230 | complete_cases() |
205 | 231 | |
206 | 232 | |
233 | +saveRDS(cmf_list, "../output/cmf_list.RDS") | |
234 | + | |
207 | 235 | cmo_list <- map(df_list,\(x) CMO(x[,c("Close")])|> as_tibble() |> |
208 | 236 | mutate(timestamp=x$timestamp))|> |
209 | 237 | bind_rows(.id="coin")|> |
210 | 238 | complete_cases() |
211 | 239 | |
240 | +saveRDS(cmo_list, "../output/cmo_list.RDS") | |
212 | 241 | |
213 | 242 | mfi_list <- map(df_list,\(x) MFI(x[,c("High","Low","Close")], x[,"Volume"]) |> as_tibble()|> |
214 | 243 | mutate(timestamp=x$timestamp))|> |
215 | 244 | bind_rows(.id="coin")|> |
216 | 245 | complete_cases() |
217 | 246 | |
247 | +saveRDS(mfi_list, "../output/mfi_list.RDS") | |
248 | + | |
218 | 249 | obv_list <- map(df_list,\(x) OBV(x[,c("Close")], x[,"Volume"])|> as_tibble()|> |
219 | 250 | mutate(timestamp=x$timestamp) )|> |
220 | 251 | bind_rows(.id="coin")|> |
221 | 252 | complete_cases() |
222 | 253 | |
254 | +saveRDS(obv_list, "../output/obv_list.RDS") | |
255 | + | |
223 | 256 | |
224 | 257 | bollinger_list <- map(df_list,\(x) BBands(x[,c("High","Low","Close")]) |> as_tibble() |> |
225 | 258 | mutate(timestamp=x$timestamp) )|> |
226 | 259 | bind_rows(.id="coin")|> |
227 | 260 | complete_cases() |
228 | 261 | |
262 | + | |
263 | +saveRDS(bollinger_list, "../output/bollinger_list.RDS") | |
264 | + | |
265 | + | |
229 | 266 | bollinger_list_long <- bollinger_list |> |
230 | 267 | pivot_longer(cols=c(dn,mavg,up), names_to="indicator", values_to="value") |
231 | 268 |
@@ -234,12 +271,16 @@ | ||
234 | 271 | bind_rows(.id="coin")|> |
235 | 272 | complete_cases() |
236 | 273 | |
274 | +saveRDS(rsi_list, "../output/rsi_list.RDS") | |
275 | + | |
237 | 276 | |
238 | 277 | aroon_list <- map(df_list,\(x) aroon(x[,c("High", "Low")], n=20) |> as_tibble() |> |
239 | 278 | mutate(timestamp=x$timestamp) )|> |
240 | 279 | bind_rows(.id="coin")|> |
241 | 280 | complete_cases() |
242 | 281 | |
282 | +saveRDS(aroon_list, "../output/aroon_list.RDS") | |
283 | + | |
243 | 284 | |
244 | 285 | aroon_list_long <- aroon_list |> |
245 | 286 | pivot_longer(cols=c(aroonUp,aroonDn,oscillator), names_to="indicator", values_to="value") |
@@ -253,6 +294,9 @@ | ||
253 | 294 | complete_cases() |
254 | 295 | |
255 | 296 | |
297 | +saveRDS(macd_list, "../output/macd_list.RDS") | |
298 | + | |
299 | + | |
256 | 300 | macd_list_long <- macd_list |> |
257 | 301 | pivot_longer(cols=c(macd,signal), names_to="indicator", values_to="value") |
258 | 302 |
@@ -262,12 +306,22 @@ | ||
262 | 306 | complete_cases() |
263 | 307 | |
264 | 308 | |
309 | +saveRDS(RRt_list, "../output/RRt_list.RDS") | |
310 | + | |
311 | + | |
265 | 312 | SIGMAt_list <- map(df_list, \(x) SIGMAt(x) |> as_tibble() |> |
266 | 313 | mutate(timestamp=x$timestamp)) |> |
267 | 314 | bind_rows(.id="coin")|> |
268 | 315 | complete_cases() |
269 | 316 | |
270 | 317 | |
318 | +saveRDS(SIGMAt_list, "../output/SIGMAt_list.RDS") | |
319 | + | |
320 | + | |
321 | +## all_quotes <- crypto_global_quotes(which="historical", quote=TRUE) |> | |
322 | +## select(-USD_timestamp) | |
323 | + | |
324 | + | |
271 | 325 | |
272 | 326 | |
273 | 327 | ########################################################################### |
@@ -287,7 +341,7 @@ | ||
287 | 341 | ylab(paste("Coin Price in ", currency, sep=""))+ |
288 | 342 | xlab(NULL) |
289 | 343 | |
290 | -fname <- paste("./history_usdt/coin_prices.pdf") | |
344 | +fname <- paste("../output/coin_prices.pdf") | |
291 | 345 | |
292 | 346 | ggsave(fname, gpl, width=x_size,height=y_size) |
293 | 347 |
@@ -303,7 +357,7 @@ | ||
303 | 357 | ylab(paste("Coin Volume in ", currency, sep=""))+ |
304 | 358 | xlab(NULL) |
305 | 359 | |
306 | -fname <- paste("./history_usdt/coin_volumes.pdf") | |
360 | +fname <- paste("../output/coin_volumes.pdf") | |
307 | 361 | |
308 | 362 | ggsave(fname, gpl, width=x_size,height=y_size) |
309 | 363 |
@@ -320,7 +374,7 @@ | ||
320 | 374 | ylab("Normalized Coin Price")+ |
321 | 375 | xlab(NULL) |
322 | 376 | |
323 | -fname <- paste("./history_usdt/coin_prices_normalized.pdf") | |
377 | +fname <- paste("../output/coin_prices_normalized.pdf") | |
324 | 378 | |
325 | 379 | ggsave(fname, gpl, width=x_size,height=y_size) |
326 | 380 |
@@ -338,7 +392,7 @@ | ||
338 | 392 | ylab("Normalized Coin Volume")+ |
339 | 393 | xlab(NULL) |
340 | 394 | |
341 | -fname <- paste("./history_usdt/coin_volumes_normalized.pdf") | |
395 | +fname <- paste("../output/coin_volumes_normalized.pdf") | |
342 | 396 | |
343 | 397 | ggsave(fname, gpl, width=x_size,height=y_size) |
344 | 398 |
@@ -359,7 +413,7 @@ | ||
359 | 413 | ylab("Chaikin Accumulator")+ |
360 | 414 | xlab(NULL) |
361 | 415 | |
362 | -fname <- paste("./history_usdt/chaikin_accumulator.pdf") | |
416 | +fname <- paste("../output/chaikin_accumulator.pdf") | |
363 | 417 | |
364 | 418 | ggsave(fname, gpl, width=x_size,height=y_size) |
365 | 419 |
@@ -375,7 +429,7 @@ | ||
375 | 429 | ylab("Relative Price Change")+ |
376 | 430 | xlab(NULL) |
377 | 431 | |
378 | -fname <- paste("./history_usdt/relative_price_change_fixed_y.pdf") | |
432 | +fname <- paste("../output/relative_price_change_fixed_y.pdf") | |
379 | 433 | |
380 | 434 | ggsave(fname, gpl, width=x_size,height=y_size) |
381 | 435 |
@@ -391,7 +445,7 @@ | ||
391 | 445 | ylab("Relative Price Change")+ |
392 | 446 | xlab(NULL) |
393 | 447 | |
394 | -fname <- paste("./history_usdt/relative_price_change.pdf") | |
448 | +fname <- paste("../output/relative_price_change.pdf") | |
395 | 449 | |
396 | 450 | ggsave(fname, gpl, width=x_size,height=y_size) |
397 | 451 |
@@ -407,7 +461,7 @@ | ||
407 | 461 | ylab("Range Volatility")+ |
408 | 462 | xlab(NULL) |
409 | 463 | |
410 | -fname <- paste("./history_usdt/range_volatility.pdf") | |
464 | +fname <- paste("../output/range_volatility.pdf") | |
411 | 465 | |
412 | 466 | ggsave(fname, gpl, width=x_size,height=y_size) |
413 | 467 |
@@ -422,7 +476,7 @@ | ||
422 | 476 | ylab("Range Volatility")+ |
423 | 477 | xlab(NULL) |
424 | 478 | |
425 | -fname <- paste("./history_usdt/range_volatility_fixed_y.pdf") | |
479 | +fname <- paste("../output/range_volatility_fixed_y.pdf") | |
426 | 480 | |
427 | 481 | ggsave(fname, gpl, width=x_size,height=y_size) |
428 | 482 |
@@ -443,7 +497,7 @@ | ||
443 | 497 | ylab("Chaikin Money Flow")+ |
444 | 498 | xlab(NULL) |
445 | 499 | |
446 | -fname <- paste("./history_usdt/chaikin_money_flow.pdf") | |
500 | +fname <- paste("../output/chaikin_money_flow.pdf") | |
447 | 501 | |
448 | 502 | ggsave(fname, gpl, width=x_size,height=y_size) |
449 | 503 |
@@ -463,7 +517,7 @@ | ||
463 | 517 | ylab("Chande Momentum Oscillator")+ |
464 | 518 | xlab(NULL) |
465 | 519 | |
466 | -fname <- paste("./history_usdt/chande_momentum_oscillator.pdf") | |
520 | +fname <- paste("../output/chande_momentum_oscillator.pdf") | |
467 | 521 | |
468 | 522 | ggsave(fname, gpl, width=x_size,height=y_size) |
469 | 523 |
@@ -482,7 +536,7 @@ | ||
482 | 536 | ylab("Money Flow Index")+ |
483 | 537 | xlab(NULL) |
484 | 538 | |
485 | -fname <- paste("./history_usdt/money_flow_index.pdf") | |
539 | +fname <- paste("../output/money_flow_index.pdf") | |
486 | 540 | |
487 | 541 | ggsave(fname, gpl, width=x_size,height=y_size) |
488 | 542 |
@@ -499,7 +553,7 @@ | ||
499 | 553 | ylab("On Balance Volume")+ |
500 | 554 | xlab(NULL) |
501 | 555 | |
502 | -fname <- paste("./history_usdt/on_balance_volume.pdf") | |
556 | +fname <- paste("../output/on_balance_volume.pdf") | |
503 | 557 | |
504 | 558 | ggsave(fname, gpl, width=x_size,height=y_size) |
505 | 559 |
@@ -520,7 +574,7 @@ | ||
520 | 574 | ylab("Bollinger Bands")+ |
521 | 575 | xlab(NULL) |
522 | 576 | |
523 | -fname <- paste("./history_usdt/bollinger_bands.pdf") | |
577 | +fname <- paste("../output/bollinger_bands.pdf") | |
524 | 578 | |
525 | 579 | ggsave(fname, gpl, width=x_size,height=y_size) |
526 | 580 |
@@ -537,7 +591,7 @@ | ||
537 | 591 | ylab("Relative Strength Index")+ |
538 | 592 | xlab(NULL) |
539 | 593 | |
540 | -fname <- paste("./history_usdt/relative_strength_index.pdf") | |
594 | +fname <- paste("../output/relative_strength_index.pdf") | |
541 | 595 | |
542 | 596 | ggsave(fname, gpl, width=x_size,height=y_size) |
543 | 597 |
@@ -563,7 +617,7 @@ | ||
563 | 617 | ylab("Aroon Indicator")+ |
564 | 618 | xlab(NULL) |
565 | 619 | |
566 | -fname <- paste("./history_usdt/aroon_indicator.pdf") | |
620 | +fname <- paste("../output/aroon_indicator.pdf") | |
567 | 621 | |
568 | 622 | ggsave(fname, gpl, width=x_size,height=y_size) |
569 | 623 |
@@ -584,7 +638,7 @@ | ||
584 | 638 | ylab("MACD Oscillator")+ |
585 | 639 | xlab(NULL) |
586 | 640 | |
587 | -fname <- paste("./history_usdt/macd_oscillator.pdf") | |
641 | +fname <- paste("../output/macd_oscillator.pdf") | |
588 | 642 | |
589 | 643 | ggsave(fname, gpl, width=x_size,height=y_size) |
590 | 644 |
@@ -638,7 +692,7 @@ | ||
638 | 692 | ylab(NULL) |
639 | 693 | |
640 | 694 | |
641 | -ggsave("./history_usdt/growth_rates.pdf", gpl3, width=12,height=8) | |
695 | +ggsave("../output/growth_rates.pdf", gpl3, width=12,height=8) | |
642 | 696 | |
643 | 697 | |
644 | 698 |