diff --git a/src/fx_currencies_anlysis.Rmd b/src/fx_currencies_anlysis.Rmd
index 4779f3e..b9141d2 100755
--- a/src/fx_currencies_anlysis.Rmd
+++ b/src/fx_currencies_anlysis.Rmd
@@ -9,43 +9,54 @@ knitr::opts_chunk$set(echo = T, warning = F)
***Analysis price of the my list of ~~the most promised cryptotokens~~ currencies.***
-## Set envinroment :earth_asia:
+## Prepare
+
+Install packages and set environment :earth_asia:
`install.packages("azuremlsdk")`
```{r set_envinroment, message=FALSE}
-library(dplyr)
-library(tidyr)
+suppressPackageStartupMessages({
+ library(dplyr)
+ library(tidyr)
+
+ library(lubridate)
+ library(stringr)
+
+ library(gt)
+ library(tidyverse)
+ library(glue)
+
+ library(ggplot2)
+
+ library(azuremlsdk)
+})
+```
-library(lubridate)
-library(stringr)
-library(gt)
-library(tidyverse)
-library(glue)
-
-library(ggplot2)
-
-library(azuremlsdk)
-
-## set params
+```{r set_params}
.azureml_dataset_name <- "Currencies"
+```
-## connect to Azure ML workspace
+
+Connect to Azure ML workspace:
+
+```{r azureml_connect}
ws <- azuremlsdk::load_workspace_from_config()
sprintf(
- "%s workspace located in %s region",ws$name, ws$location
+ "%s workspace located in %s region", ws$name, ws$location
)
-
```
-## Load dataset
+## Load dataset
+
```{r get_azure_dataset}
currencies_ds <- azuremlsdk::get_dataset_by_name(ws, name = .azureml_dataset_name)
currencies_ds$name
currencies_ds$description
```
+Get USD/RUB top higher rates:
```{r prepare_dataframe}
quotes_df <- currencies_ds$to_pandas_dataframe()
@@ -71,6 +82,10 @@ quotes_df %>%
)
```
+## Preprocessing data
+
+Calculate `Return` and `Log Return` for last 10 years:
+
```{r preprocessing}
quotes_df %<>%
transmute(
@@ -125,7 +140,7 @@ quotes_stats %>%
gt() %>%
tab_header(
- title = "Least Volatility Currencies",
+ title = "The Least Volatile Currencies",
subtitle = glue("{min(quotes_df$date)} to {max(quotes_df$date)}")
) %>%
fmt_number(
@@ -138,7 +153,7 @@ My broker available pairs:
symbols <- c(
'RUB',
'EUR', 'GBP', 'CHF', 'CNY', 'HKD', 'JPY', 'SEK', 'SGD', 'AUD',
- 'KZT', 'BYN', 'TRY', 'MXN'
+ 'AED', 'KZT', 'BYN', 'TRY', 'MXN'
)
quotes_stats %>%
@@ -147,14 +162,13 @@ quotes_stats %>%
) %>%
mutate(
`100x Volatility` = volatility*100
- #risk = if_else(volatility > volatility_threshold, "High", "Medium or low", NA_character_)
) %>%
arrange(volatility) %>%
select(-volatility) %>%
gt() %>%
tab_header(
- title = "Least Volatility Currencies",
+ title = "The Most Promised Currencies",
subtitle = glue("{min(quotes_df$date)} to {max(quotes_df$date)}")
) %>%
fmt_number(
diff --git a/src/fx_currencies_anlysis.md b/src/fx_currencies_anlysis.md
new file mode 100644
index 0000000..8d8e24e
--- /dev/null
+++ b/src/fx_currencies_anlysis.md
@@ -0,0 +1,1999 @@
+Currencies Analysis
+================
+
+***Analysis price of the my list of ~~the most promised cryptotokens~~
+currencies.***
+
+## Prepare
+
+Install packages and set environment :earth\_asia:
+
+`install.packages("azuremlsdk")`
+
+``` r
+suppressPackageStartupMessages({
+ library(dplyr)
+ library(tidyr)
+
+ library(lubridate)
+ library(stringr)
+
+ library(gt)
+ library(tidyverse)
+ library(glue)
+
+ library(ggplot2)
+
+ library(azuremlsdk)
+})
+```
+
+``` r
+.azureml_dataset_name <- "Currencies"
+```
+
+Connect to Azure ML workspace:
+
+``` r
+ws <- azuremlsdk::load_workspace_from_config()
+sprintf(
+ "%s workspace located in %s region", ws$name, ws$location
+)
+```
+
+ ## [1] "portf-opt-ws workspace located in westeurope region"
+
+## Load dataset
+
+``` r
+currencies_ds <- azuremlsdk::get_dataset_by_name(ws, name = .azureml_dataset_name)
+currencies_ds$name
+```
+
+ ## [1] "Currencies"
+
+``` r
+currencies_ds$description
+```
+
+ ## [1] "Source: https://www.kaggle.com/datasets/dhruvildave/currency-exchange-rates"
+
+Get USD/RUB top higher rates:
+
+``` r
+quotes_df <- currencies_ds$to_pandas_dataframe()
+
+# ~ 20 years, 150 currencies and 1.5M rows
+
+quotes_df %>%
+ filter(slug == "USD/RUB") %>%
+ select(-slug) %>%
+ top_n(10) %>%
+
+ gt() %>%
+ tab_header(
+ title = "USD/RUB Rate",
+ subtitle = glue("{min(quotes_df$date)} to {max(quotes_df$date)}")
+ ) %>%
+ fmt_date(
+ columns = date,
+ date_style = 6
+ ) %>%
+ fmt_number(
+ columns = c(open, high, low, close)
+ )
+```
+
+ ## Selecting by close
+
+
+
+
+
+
+
+ date |
+ open |
+ high |
+ low |
+ close |
+
+
+
+ Jan 21, 2016 |
+82.06 |
+85.82 |
+82.06 |
+81.82 |
+ Jan 22, 2016 |
+80.61 |
+81.26 |
+77.94 |
+82.90 |
+ Jan 26, 2016 |
+81.54 |
+82.16 |
+78.33 |
+79.84 |
+ Feb 3, 2016 |
+79.56 |
+79.75 |
+77.87 |
+79.71 |
+ Feb 10, 2016 |
+79.39 |
+79.49 |
+77.65 |
+79.59 |
+ Feb 12, 2016 |
+79.36 |
+79.74 |
+78.59 |
+79.77 |
+ Mar 19, 2020 |
+80.92 |
+82.07 |
+79.24 |
+80.92 |
+ Mar 23, 2020 |
+79.72 |
+81.34 |
+79.49 |
+79.84 |
+ Mar 31, 2020 |
+79.59 |
+79.69 |
+77.66 |
+79.59 |
+ Nov 3, 2020 |
+80.55 |
+80.57 |
+79.05 |
+80.52 |
+
+
+
+
+
+
+## Preprocessing data
+
+Calculate `Return` and `Log Return` for last 10 years:
+
+``` r
+quotes_df %<>%
+ transmute(
+ symbol = slug,
+ price = close,
+ date
+ ) %>%
+
+ filter(
+ str_detect(symbol, "USD/") &
+ date > max(date) - lubridate::years(10)
+ ) %>%
+
+ filter(!(symbol == "USD/RUB" & price < 1)) %>%
+
+ arrange(date) %>%
+ group_by(symbol) %>%
+
+ mutate(
+ return = c(NA_real_, diff(price))/lag(price),
+ log_return = log(1 + return)
+ ) %>%
+ na.omit
+```
+
+Base and quote currencies:
+
+``` r
+quotes_stats <- quotes_df %>%
+
+ summarise(
+ max_price = max(price),
+ min_price = min(price),
+ last_price = last(price),
+ max_min_rate = max(price)/min(price),
+ volatility = sd(log_return)
+ )
+
+volatility_threshold <- quotes_stats %>% pull(volatility) %>% quantile(probs = .75)
+
+
+quotes_stats %>%
+ filter(
+ volatility <= volatility_threshold |
+ symbol == "USD/RUB"
+ ) %>%
+ mutate(
+ `100x Volatility` = volatility*100
+ ) %>%
+ arrange(volatility) %>%
+ select(-volatility) %>%
+
+ gt() %>%
+ tab_header(
+ title = "The Least Volatile Currencies",
+ subtitle = glue("{min(quotes_df$date)} to {max(quotes_df$date)}")
+ ) %>%
+ fmt_number(
+ columns = c(max_price, min_price, max_min_rate, `100x Volatility`)
+ )
+```
+
+
+
+
+
+
+
+ symbol |
+ max_price |
+ min_price |
+ last_price |
+ max_min_rate |
+ 100x Volatility |
+
+
+
+ USD/AED |
+3.67 |
+3.67 |
+3.67280 |
+1.00 |
+0.01 |
+ USD/HKD |
+7.85 |
+7.75 |
+7.78694 |
+1.01 |
+0.03 |
+ USD/KWD |
+0.31 |
+0.27 |
+0.30060 |
+1.16 |
+0.16 |
+ USD/CNY |
+7.18 |
+6.03 |
+6.46580 |
+1.19 |
+0.23 |
+ USD/DJF |
+177.72 |
+172.00 |
+177.50000 |
+1.03 |
+0.28 |
+ USD/SGD |
+1.46 |
+1.20 |
+1.34448 |
+1.21 |
+0.33 |
+ USD/SAR |
+3.77 |
+3.30 |
+3.75050 |
+1.14 |
+0.39 |
+ USD/GTQ |
+7.89 |
+7.04 |
+7.72750 |
+1.12 |
+0.41 |
+ USD/ILS |
+4.07 |
+3.13 |
+3.20490 |
+1.30 |
+0.45 |
+ USD/TTD |
+6.78 |
+5.93 |
+6.76320 |
+1.14 |
+0.47 |
+ USD/CAD |
+1.46 |
+0.97 |
+1.26050 |
+1.51 |
+0.47 |
+ USD/MYR |
+4.49 |
+2.96 |
+4.15500 |
+1.52 |
+0.50 |
+ USD/DKK |
+7.15 |
+5.18 |
+6.29986 |
+1.38 |
+0.51 |
+ USD/EUR |
+0.96 |
+0.70 |
+0.84700 |
+1.38 |
+0.51 |
+ USD/CRC |
+619.70 |
+478.54 |
+619.70001 |
+1.29 |
+0.53 |
+ USD/PHP |
+54.23 |
+39.75 |
+49.70500 |
+1.36 |
+0.54 |
+ USD/INR |
+77.57 |
+45.70 |
+73.29200 |
+1.70 |
+0.54 |
+ USD/RON |
+4.54 |
+2.93 |
+4.17920 |
+1.55 |
+0.55 |
+ USD/JPY |
+125.63 |
+75.74 |
+109.90200 |
+1.66 |
+0.55 |
+ USD/GBP |
+0.87 |
+0.58 |
+0.72661 |
+1.49 |
+0.55 |
+ USD/JMD |
+153.88 |
+83.37 |
+150.53000 |
+1.85 |
+0.56 |
+ USD/MKD |
+58.92 |
+42.07 |
+51.98000 |
+1.40 |
+0.58 |
+ USD/MDL |
+20.31 |
+11.09 |
+17.58000 |
+1.83 |
+0.61 |
+ USD/BDT |
+84.72 |
+72.39 |
+84.72000 |
+1.17 |
+0.62 |
+ USD/AUD |
+1.74 |
+0.93 |
+1.36995 |
+1.88 |
+0.63 |
+ USD/SEK |
+10.44 |
+6.29 |
+8.61840 |
+1.66 |
+0.64 |
+ USD/CHF |
+1.03 |
+0.79 |
+0.91691 |
+1.31 |
+0.64 |
+ USD/CZK |
+26.03 |
+16.75 |
+21.67120 |
+1.55 |
+0.64 |
+ USD/BWP |
+12.19 |
+6.58 |
+11.11850 |
+1.85 |
+0.66 |
+ USD/NZD |
+1.78 |
+1.13 |
+1.42710 |
+1.57 |
+0.66 |
+ USD/THB |
+36.43 |
+28.07 |
+32.44700 |
+1.30 |
+0.67 |
+ USD/LKR |
+199.43 |
+106.22 |
+199.42999 |
+1.88 |
+0.67 |
+ USD/KRW |
+1,262.93 |
+999.83 |
+1165.89001 |
+1.26 |
+0.70 |
+ USD/RSD |
+118.47 |
+70.05 |
+99.28820 |
+1.69 |
+0.70 |
+ USD/UYU |
+45.31 |
+18.08 |
+42.53000 |
+2.51 |
+0.71 |
+ USD/PLN |
+4.28 |
+2.87 |
+3.86140 |
+1.49 |
+0.72 |
+ USD/HUF |
+338.26 |
+188.61 |
+294.66000 |
+1.79 |
+0.74 |
+ USD/MUR |
+42.55 |
+26.50 |
+42.55000 |
+1.61 |
+0.79 |
+ USD/MXN |
+25.34 |
+11.98 |
+20.13500 |
+2.11 |
+0.80 |
+ USD/NIO |
+35.13 |
+22.05 |
+35.00000 |
+1.59 |
+0.84 |
+ USD/KZT |
+454.34 |
+174.15 |
+427.17999 |
+2.61 |
+0.84 |
+ USD/QAR |
+3.90 |
+3.00 |
+3.64000 |
+1.30 |
+0.95 |
+ USD/TRY |
+8.78 |
+1.71 |
+8.37690 |
+5.12 |
+0.97 |
+ USD/ZAR |
+19.25 |
+6.98 |
+14.66110 |
+2.76 |
+0.99 |
+ USD/RUB |
+82.90 |
+28.79 |
+73.50400 |
+2.88 |
+1.05 |
+ USD/ZMW |
+22.64 |
+5.11 |
+15.82000 |
+4.43 |
+1.06 |
+ USD/BRL |
+5.89 |
+1.58 |
+5.19380 |
+3.72 |
+1.08 |
+ USD/ARS |
+97.70 |
+4.10 |
+97.70000 |
+23.85 |
+1.11 |
+ USD/TND |
+3.06 |
+1.37 |
+2.79000 |
+2.23 |
+1.17 |
+ USD/BGN |
+1.87 |
+1.21 |
+1.65734 |
+1.55 |
+1.28 |
+ USD/EGP |
+19.60 |
+5.83 |
+15.65000 |
+3.37 |
+1.29 |
+ USD/NOK |
+11.76 |
+5.36 |
+8.66435 |
+2.19 |
+1.31 |
+ USD/PEN |
+4.11 |
+2.38 |
+4.06940 |
+1.72 |
+1.34 |
+ USD/BYN |
+3.08 |
+0.51 |
+2.51000 |
+6.04 |
+1.37 |
+ USD/MAD |
+10.29 |
+7.89 |
+8.95300 |
+1.30 |
+1.43 |
+ USD/UAH |
+33.50 |
+7.80 |
+26.92000 |
+4.30 |
+1.83 |
+ USD/SDG |
+451.00 |
+1.39 |
+440.03491 |
+324.46 |
+5.96 |
+ USD/BND |
+1.43 |
+0.66 |
+1.34470 |
+2.18 |
+6.29 |
+ USD/XOF |
+647.00 |
+58.00 |
+555.46997 |
+11.16 |
+6.44 |
+ USD/IDR |
+16,504.80 |
+892.00 |
+14370.00000 |
+18.50 |
+6.58 |
+ USD/HNL |
+24.90 |
+3.00 |
+23.82560 |
+8.30 |
+8.14 |
+
+
+
+
+
+
+My broker available pairs:
+
+``` r
+symbols <- c(
+ 'RUB',
+ 'EUR', 'GBP', 'CHF', 'CNY', 'HKD', 'JPY', 'SEK', 'SGD', 'AUD',
+ 'AED', 'KZT', 'BYN', 'TRY', 'MXN'
+)
+
+quotes_stats %>%
+ filter(
+ symbol %in% str_c("USD", symbols, sep = "/")
+ ) %>%
+ mutate(
+ `100x Volatility` = volatility*100
+ ) %>%
+ arrange(volatility) %>%
+ select(-volatility) %>%
+
+ gt() %>%
+ tab_header(
+ title = "The Most Promised Currencies",
+ subtitle = glue("{min(quotes_df$date)} to {max(quotes_df$date)}")
+ ) %>%
+ fmt_number(
+ columns = c(max_price, min_price, max_min_rate, `100x Volatility`)
+ )
+```
+
+
+
+
+
+
+
+ symbol |
+ max_price |
+ min_price |
+ last_price |
+ max_min_rate |
+ 100x Volatility |
+
+
+
+ USD/AED |
+3.67 |
+3.67 |
+3.67280 |
+1.00 |
+0.01 |
+ USD/HKD |
+7.85 |
+7.75 |
+7.78694 |
+1.01 |
+0.03 |
+ USD/CNY |
+7.18 |
+6.03 |
+6.46580 |
+1.19 |
+0.23 |
+ USD/SGD |
+1.46 |
+1.20 |
+1.34448 |
+1.21 |
+0.33 |
+ USD/EUR |
+0.96 |
+0.70 |
+0.84700 |
+1.38 |
+0.51 |
+ USD/JPY |
+125.63 |
+75.74 |
+109.90200 |
+1.66 |
+0.55 |
+ USD/GBP |
+0.87 |
+0.58 |
+0.72661 |
+1.49 |
+0.55 |
+ USD/AUD |
+1.74 |
+0.93 |
+1.36995 |
+1.88 |
+0.63 |
+ USD/SEK |
+10.44 |
+6.29 |
+8.61840 |
+1.66 |
+0.64 |
+ USD/CHF |
+1.03 |
+0.79 |
+0.91691 |
+1.31 |
+0.64 |
+ USD/MXN |
+25.34 |
+11.98 |
+20.13500 |
+2.11 |
+0.80 |
+ USD/KZT |
+454.34 |
+174.15 |
+427.17999 |
+2.61 |
+0.84 |
+ USD/TRY |
+8.78 |
+1.71 |
+8.37690 |
+5.12 |
+0.97 |
+ USD/RUB |
+82.90 |
+28.79 |
+73.50400 |
+2.88 |
+1.05 |
+ USD/BYN |
+3.08 |
+0.51 |
+2.51000 |
+6.04 |
+1.37 |
+
+
+
+
+
+
+Plot exchange rate for out favorites:
+
+Define low risk symbols:
+
+``` r
+low_risk_symbols <- quotes_stats %>%
+ filter(
+ symbol %in% str_c("USD", symbols, sep = "/")
+ ) %>%
+ filter(
+ volatility <= volatility_threshold |
+ symbol == "USD/RUB"
+ ) %>%
+ pull(symbol) %>%
+ unique
+
+cat(
+ sprintf(
+ "['%s']",
+ paste(low_risk_symbols, collapse = "', '")
+))
+```
+
+ ## ['USD/AED', 'USD/AUD', 'USD/BYN', 'USD/CHF', 'USD/CNY', 'USD/EUR', 'USD/GBP', 'USD/HKD', 'USD/JPY', 'USD/KZT', 'USD/MXN', 'USD/RUB', 'USD/SEK', 'USD/SGD', 'USD/TRY']