• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Revisión6ec285935d15d49990aab56532eb203004cab23a (tree)
Tiempo2024-02-29 21:59:19
AutorLorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

I added an extra plot on th performance of my assets plus I cleaned the code.

Cambiar Resumen

Diferencia incremental

diff -r fbb6ea23a317 -r 6ec285935d15 R-codes/technical_analysis.R
--- a/R-codes/technical_analysis.R Thu Feb 29 09:01:40 2024 +0100
+++ b/R-codes/technical_analysis.R Thu Feb 29 13:59:19 2024 +0100
@@ -3,9 +3,9 @@
33 library(tidyverse)
44 library(crypto2)
55 library(TTR)
6-
7-
8-
6+library(openxlsx)
7+library(janitor)
8+library(scales)
99
1010 source("/home/lorenzo/myprojects-hg/R-codes/stat_lib.R")
1111
@@ -16,35 +16,99 @@
1616
1717 y_size <- 16
1818
19-days_back <- 90
19+days_back <- 40
2020
2121 final_day <- gsub('-', '', today())
2222
23-initial_day <- gsub('-', '', today()-days_back)
23+initial_day <- gsub('-', '', today()-days_back-1)
2424
2525 currency <- ## "EUR"
2626 "USD"
2727
28-mylist_slug <- c("cardano" , "avalanche",
29- "injective",
30- "chainlink", "mina", "xrp",
31- "cosmos", "polygon", "optimism-ethereum",
32- "algorand", "kava", "solana", "cartesi",
33- "near-protocol", "mantra", "polkadot-new", "axie-infinity",
34- "alchemy-pay", "pancakeswap", "dodo",
35- "floki-inu",
36- "arbitrum"
37- ,"celestia"
38- , "apecoin-ape",
39- "celestia", "aave", "biswap", "moonbeam", "bitcoin",
40- "bnb", "skale-network", "ethereum", "harmony"
41- )
28+
29+n_assets <- 16 ## how many assets to consider
30+
31+value_min <- 2 ## min_value of the asset to be considered
32+
33+## mylist_slug <- c("cardano" , "avalanche",
34+## "injective",
35+## "chainlink", "mina", "xrp",
36+## "cosmos", "polygon", "optimism-ethereum",
37+## "algorand", "kava", "solana", "cartesi",
38+## "near-protocol", "mantra", "polkadot-new", "axie-infinity",
39+## "alchemy-pay", "pancakeswap", "dodo",
40+## "floki-inu",
41+## "arbitrum"
42+## ,"celestia"
43+## , "apecoin-ape",
44+## "celestia", "aave", "biswap", "moonbeam", "bitcoin",
45+## "bnb", "skale-network", "ethereum", "harmony",
46+## "phala-network"
47+## )
48+
49+
50+## mylist_slug <- c("cardano" , "avalanche",
51+## "injective"## ,
52+## ## "chainlink", "mina", "xrp",
53+## ## "cosmos", "polygon", "optimism-ethereum",
54+## ## "algorand", "kava", "solana", "cartesi",
55+## ## "near-protocol", "mantra", "polkadot-new", "axie-infinity",
56+## ## "alchemy-pay", "pancakeswap", "dodo",
57+## ## "floki-inu",
58+## ## "arbitrum"
59+## ## ,"celestia"
60+## ## , "apecoin-ape",
61+## ## "celestia", "aave", "biswap", "moonbeam", "bitcoin",
62+## ## "bnb", "skale-network", "ethereum", "harmony",
63+## ## "phala-network"
64+## )
65+
66+
67+
68+my_symbol_list <- read_excel("portfolio_summary.xlsx") |>
69+ arrange(desc(total_value_usdt)) |>
70+ ## slice(1:n_assets) |>
71+ filter(total_value_usdt>value_min) |>
72+ mutate(asset=if_else(asset=="BEAMX", "BEAM", asset)) |>
73+ pull(asset)
74+
4275
4376 coins_all <- crypto_list(only_active=TRUE)
4477
78+slug_negation <- c("bigone-token","onedex", "onetoken",
79+ "apecoin", "apemove","arbit", "arb-protocol",
80+ "beam", "shiba-floki", "baby-moon-floki", "bonk-bnb",
81+ "strike","meta-dance", "starknet-token"
82+ )
4583
4684 coins <- coins_all |>
47- filter(slug %in% mylist_slug)
85+ filter(symbol %in% my_symbol_list) |>
86+ filter(slug %!in% slug_negation) ## |>
87+ ## select(-c(rank, id, is_active, last_historical_data))
88+
89+## mylist_slug <- coins_temp |>
90+## select(symbol,slug) |>
91+## arrange(symbol) |>
92+## filter(slug %!in% c("apecoin", "apemove", "arbit",
93+## "arb-protocol",
94+## "bigone-token", "onedex", "onetoken",
95+## "shiba-floki", "baby-moon-floki",
96+## "strike", "connect-united",
97+## "beam", "bonk-bnb",
98+## "meta-dance",
99+## "pixelverse"),
100+## symbol %!in% c("PEPE", "XAI", "PIXEL", "PORTAL")) |>
101+## pull(slug)
102+
103+## coins <- coins_all |>
104+## filter(slug %in% mylist_slug)
105+
106+
107+## coins <- coins_all |>
108+## filter(slug %in% mylist_slug)
109+
110+
111+
48112
49113 coin_hist <- crypto_history(coins,
50114 convert = currency,
@@ -400,8 +464,57 @@
400464
401465 ggsave(fname, gpl, width=x_size,height=y_size)
402466
467+#####################################################################
468+
469+##calculate the performance of the coins along the period.
470+
471+## coin_ini_end <- coin_hist |>
472+## select(symbol, timestamp, Close) |>
473+## group_by(symbol) |>
474+## arrange(timestamp) |>
475+## slice(c(1, n())) |>
476+## ungroup()
477+
478+## coin_performance <- coin_ini_end |>
479+## group_by(symbol) |>
480+## summarise(performance=(Close[2]-Close[1])/Close[1]) |>
481+## ungroup() |>
482+## arrange(performance) |>
483+## mutate(perc_perf=format_col_percentage(performance*100, 1))
403484
404485
486+## growth rates along period
487+
488+coin_growth <- coin_hist |>
489+ group_by(symbol) |>
490+ summarise(growth=(Close[n()]-Close[1])/Close[1]) |>
491+ ungroup() |>
492+ arrange(growth) |>
493+ mutate(name_symb=fct_inorder(symbol)) |>
494+ mutate(relation_to_median=if_else(growth>= median(growth),
495+ "Above the median", "Below the median")) |>
496+ mutate(perc_perf=format_col_percentage(growth*100, 1))
497+
498+
499+
500+gpl3 <- ggplot(coin_growth, aes(y=name_symb, x=growth,
501+ fill=relation_to_median)) +
502+ geom_bar(stat = "identity") +
503+ geom_text(aes(label=perc_perf),
504+ position=position_dodge(width=0.9), hjust=0,
505+ size=5)+
506+
507+ ggtitle(title_name)+
508+ scale_x_continuous(labels = label_percent(),
509+ expand = c(0.,0.1), limits = c(NA, NA)) +
510+ my_ggplot_theme2("top")+
511+ ggtitle(title_name)+
512+ scale_fill_manual(NULL, values=c("blue", "red")) +
513+ xlab("Growth along Period")+
514+ ylab(NULL)
515+
516+
517+ggsave("./history_usdt/growth_rates.pdf", gpl3, width=12,height=8)
405518
406519
407520