• R/O
  • SSH

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision8ff618b5b4296a81a2181e2cbcc20854e2474f8f (tree)
Zeit2024-12-17 01:25:43
AutorLorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

I modified some paths and changed a bit the code.

Ändern Zusammenfassung

Diff

diff -r c7509780b13c -r 8ff618b5b429 R-codes/technical_analysis.R
--- a/R-codes/technical_analysis.R Mon Dec 16 13:17:26 2024 +0100
+++ b/R-codes/technical_analysis.R Mon Dec 16 17:25:43 2024 +0100
@@ -6,6 +6,8 @@
66 library(openxlsx)
77 library(janitor)
88 library(scales)
9+## library(tsfeatures)
10+
911
1012 source("/home/lorenzo/myprojects-hg/R-codes/stat_lib.R")
1113
@@ -16,7 +18,7 @@
1618
1719 y_size <- 16
1820
19-days_back <- 40
21+days_back <- 120 ## 360
2022
2123 final_day <- gsub('-', '', today())
2224
@@ -96,16 +98,21 @@
9698
9799
98100
99-my_symbol_list <- read_excel("portfolio_summary.xlsx") |>
101+my_symbol_list <- read_excel("../output/portfolio_summary.xlsx") |>
100102 arrange(desc(total_value_usdt)) |>
101103 ## slice(1:n_assets) |>
102- filter(total_value_usdt>value_min) |>
104+ ## filter(total_value_usdt>value_min) |>
105+ slice(1:10) |>
103106 mutate(asset=if_else(asset=="BEAMX", "BEAM", asset)) |>
104107 pull(asset)
105108
106109
107110 coins_all <- crypto_list(only_active=TRUE)
108111
112+all_quotes <- crypto_global_quotes(which="historical", quote=TRUE)
113+
114+saveRDS(all_quotes, "../output/market_stats.RDS")
115+
109116 slug_negation <- c("bigone-token","onedex", "onetoken",
110117 "apecoin", "apemove","arbit", "arb-protocol",
111118 "beam", "shiba-floki", "baby-moon-floki", "bonk-bnb",
@@ -140,13 +147,15 @@
140147 ## filter(slug %in% mylist_slug)
141148
142149
143-
144-
145-coin_hist <- crypto_history(coins,
150+coin_temp <- crypto_history(coins,
146151 convert = currency,
147152 ## limit=3,
148153 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 |>
150159 mutate(timestamp=as_date(timestamp)) |>
151160 group_by(slug) |>
152161 arrange(timestamp, .by_group=T) |>
@@ -158,6 +167,10 @@
158167 rename("High"="high", "Low"="low", "Close"="close",
159168 "Volume"= "volume")
160169
170+
171+
172+
173+
161174 ## create a simpler tibble with the relevant data
162175
163176 df <- coin_hist |>
@@ -183,14 +196,24 @@
183196
184197 ## See https://stackoverflow.com/questions/39638233/grouped-data-frame-to-list/71926304#71926304
185198
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+
188204
189205 names(df_list) <- df |> group_by(symbol) |>
190206 group_map(~.y) |>
191207 unlist()
192208
193209
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+
194217 ## See https://stackoverflow.com/questions/73714344/how-to-convert-a-list-of-tibbles-tino-a-data-frame-in-r/73714438#73714438
195218
196219 ad_list <- map(df_list,\(x) chaikinAD(x[,c("High","Low","Close")], x[,"Volume"]) |> as_tibble() |>
@@ -198,34 +221,48 @@
198221 bind_rows(.id="coin")|>
199222 complete_cases()
200223
224+saveRDS(ad_list, "../output/ad_list.RDS")
225+
226+
201227 cmf_list <- map(df_list,\(x) CMF(x[,c("High","Low","Close")], x[,"Volume"])|> as_tibble()|>
202228 mutate(timestamp=x$timestamp) )|>
203229 bind_rows(.id="coin")|>
204230 complete_cases()
205231
206232
233+saveRDS(cmf_list, "../output/cmf_list.RDS")
234+
207235 cmo_list <- map(df_list,\(x) CMO(x[,c("Close")])|> as_tibble() |>
208236 mutate(timestamp=x$timestamp))|>
209237 bind_rows(.id="coin")|>
210238 complete_cases()
211239
240+saveRDS(cmo_list, "../output/cmo_list.RDS")
212241
213242 mfi_list <- map(df_list,\(x) MFI(x[,c("High","Low","Close")], x[,"Volume"]) |> as_tibble()|>
214243 mutate(timestamp=x$timestamp))|>
215244 bind_rows(.id="coin")|>
216245 complete_cases()
217246
247+saveRDS(mfi_list, "../output/mfi_list.RDS")
248+
218249 obv_list <- map(df_list,\(x) OBV(x[,c("Close")], x[,"Volume"])|> as_tibble()|>
219250 mutate(timestamp=x$timestamp) )|>
220251 bind_rows(.id="coin")|>
221252 complete_cases()
222253
254+saveRDS(obv_list, "../output/obv_list.RDS")
255+
223256
224257 bollinger_list <- map(df_list,\(x) BBands(x[,c("High","Low","Close")]) |> as_tibble() |>
225258 mutate(timestamp=x$timestamp) )|>
226259 bind_rows(.id="coin")|>
227260 complete_cases()
228261
262+
263+saveRDS(bollinger_list, "../output/bollinger_list.RDS")
264+
265+
229266 bollinger_list_long <- bollinger_list |>
230267 pivot_longer(cols=c(dn,mavg,up), names_to="indicator", values_to="value")
231268
@@ -234,12 +271,16 @@
234271 bind_rows(.id="coin")|>
235272 complete_cases()
236273
274+saveRDS(rsi_list, "../output/rsi_list.RDS")
275+
237276
238277 aroon_list <- map(df_list,\(x) aroon(x[,c("High", "Low")], n=20) |> as_tibble() |>
239278 mutate(timestamp=x$timestamp) )|>
240279 bind_rows(.id="coin")|>
241280 complete_cases()
242281
282+saveRDS(aroon_list, "../output/aroon_list.RDS")
283+
243284
244285 aroon_list_long <- aroon_list |>
245286 pivot_longer(cols=c(aroonUp,aroonDn,oscillator), names_to="indicator", values_to="value")
@@ -253,6 +294,9 @@
253294 complete_cases()
254295
255296
297+saveRDS(macd_list, "../output/macd_list.RDS")
298+
299+
256300 macd_list_long <- macd_list |>
257301 pivot_longer(cols=c(macd,signal), names_to="indicator", values_to="value")
258302
@@ -262,12 +306,22 @@
262306 complete_cases()
263307
264308
309+saveRDS(RRt_list, "../output/RRt_list.RDS")
310+
311+
265312 SIGMAt_list <- map(df_list, \(x) SIGMAt(x) |> as_tibble() |>
266313 mutate(timestamp=x$timestamp)) |>
267314 bind_rows(.id="coin")|>
268315 complete_cases()
269316
270317
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+
271325
272326
273327 ###########################################################################
@@ -287,7 +341,7 @@
287341 ylab(paste("Coin Price in ", currency, sep=""))+
288342 xlab(NULL)
289343
290-fname <- paste("./history_usdt/coin_prices.pdf")
344+fname <- paste("../output/coin_prices.pdf")
291345
292346 ggsave(fname, gpl, width=x_size,height=y_size)
293347
@@ -303,7 +357,7 @@
303357 ylab(paste("Coin Volume in ", currency, sep=""))+
304358 xlab(NULL)
305359
306-fname <- paste("./history_usdt/coin_volumes.pdf")
360+fname <- paste("../output/coin_volumes.pdf")
307361
308362 ggsave(fname, gpl, width=x_size,height=y_size)
309363
@@ -320,7 +374,7 @@
320374 ylab("Normalized Coin Price")+
321375 xlab(NULL)
322376
323-fname <- paste("./history_usdt/coin_prices_normalized.pdf")
377+fname <- paste("../output/coin_prices_normalized.pdf")
324378
325379 ggsave(fname, gpl, width=x_size,height=y_size)
326380
@@ -338,7 +392,7 @@
338392 ylab("Normalized Coin Volume")+
339393 xlab(NULL)
340394
341-fname <- paste("./history_usdt/coin_volumes_normalized.pdf")
395+fname <- paste("../output/coin_volumes_normalized.pdf")
342396
343397 ggsave(fname, gpl, width=x_size,height=y_size)
344398
@@ -359,7 +413,7 @@
359413 ylab("Chaikin Accumulator")+
360414 xlab(NULL)
361415
362-fname <- paste("./history_usdt/chaikin_accumulator.pdf")
416+fname <- paste("../output/chaikin_accumulator.pdf")
363417
364418 ggsave(fname, gpl, width=x_size,height=y_size)
365419
@@ -375,7 +429,7 @@
375429 ylab("Relative Price Change")+
376430 xlab(NULL)
377431
378-fname <- paste("./history_usdt/relative_price_change_fixed_y.pdf")
432+fname <- paste("../output/relative_price_change_fixed_y.pdf")
379433
380434 ggsave(fname, gpl, width=x_size,height=y_size)
381435
@@ -391,7 +445,7 @@
391445 ylab("Relative Price Change")+
392446 xlab(NULL)
393447
394-fname <- paste("./history_usdt/relative_price_change.pdf")
448+fname <- paste("../output/relative_price_change.pdf")
395449
396450 ggsave(fname, gpl, width=x_size,height=y_size)
397451
@@ -407,7 +461,7 @@
407461 ylab("Range Volatility")+
408462 xlab(NULL)
409463
410-fname <- paste("./history_usdt/range_volatility.pdf")
464+fname <- paste("../output/range_volatility.pdf")
411465
412466 ggsave(fname, gpl, width=x_size,height=y_size)
413467
@@ -422,7 +476,7 @@
422476 ylab("Range Volatility")+
423477 xlab(NULL)
424478
425-fname <- paste("./history_usdt/range_volatility_fixed_y.pdf")
479+fname <- paste("../output/range_volatility_fixed_y.pdf")
426480
427481 ggsave(fname, gpl, width=x_size,height=y_size)
428482
@@ -443,7 +497,7 @@
443497 ylab("Chaikin Money Flow")+
444498 xlab(NULL)
445499
446-fname <- paste("./history_usdt/chaikin_money_flow.pdf")
500+fname <- paste("../output/chaikin_money_flow.pdf")
447501
448502 ggsave(fname, gpl, width=x_size,height=y_size)
449503
@@ -463,7 +517,7 @@
463517 ylab("Chande Momentum Oscillator")+
464518 xlab(NULL)
465519
466-fname <- paste("./history_usdt/chande_momentum_oscillator.pdf")
520+fname <- paste("../output/chande_momentum_oscillator.pdf")
467521
468522 ggsave(fname, gpl, width=x_size,height=y_size)
469523
@@ -482,7 +536,7 @@
482536 ylab("Money Flow Index")+
483537 xlab(NULL)
484538
485-fname <- paste("./history_usdt/money_flow_index.pdf")
539+fname <- paste("../output/money_flow_index.pdf")
486540
487541 ggsave(fname, gpl, width=x_size,height=y_size)
488542
@@ -499,7 +553,7 @@
499553 ylab("On Balance Volume")+
500554 xlab(NULL)
501555
502-fname <- paste("./history_usdt/on_balance_volume.pdf")
556+fname <- paste("../output/on_balance_volume.pdf")
503557
504558 ggsave(fname, gpl, width=x_size,height=y_size)
505559
@@ -520,7 +574,7 @@
520574 ylab("Bollinger Bands")+
521575 xlab(NULL)
522576
523-fname <- paste("./history_usdt/bollinger_bands.pdf")
577+fname <- paste("../output/bollinger_bands.pdf")
524578
525579 ggsave(fname, gpl, width=x_size,height=y_size)
526580
@@ -537,7 +591,7 @@
537591 ylab("Relative Strength Index")+
538592 xlab(NULL)
539593
540-fname <- paste("./history_usdt/relative_strength_index.pdf")
594+fname <- paste("../output/relative_strength_index.pdf")
541595
542596 ggsave(fname, gpl, width=x_size,height=y_size)
543597
@@ -563,7 +617,7 @@
563617 ylab("Aroon Indicator")+
564618 xlab(NULL)
565619
566-fname <- paste("./history_usdt/aroon_indicator.pdf")
620+fname <- paste("../output/aroon_indicator.pdf")
567621
568622 ggsave(fname, gpl, width=x_size,height=y_size)
569623
@@ -584,7 +638,7 @@
584638 ylab("MACD Oscillator")+
585639 xlab(NULL)
586640
587-fname <- paste("./history_usdt/macd_oscillator.pdf")
641+fname <- paste("../output/macd_oscillator.pdf")
588642
589643 ggsave(fname, gpl, width=x_size,height=y_size)
590644
@@ -638,7 +692,7 @@
638692 ylab(NULL)
639693
640694
641-ggsave("./history_usdt/growth_rates.pdf", gpl3, width=12,height=8)
695+ggsave("../output/growth_rates.pdf", gpl3, width=12,height=8)
642696
643697
644698