Skip to content

Commit

Permalink
adding 2023 dates + trying multiarch container in ghcr
Browse files Browse the repository at this point in the history
  • Loading branch information
IoTechCrafts committed Aug 31, 2024
1 parent d04bfa4 commit 0ae5a2d
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_shiny.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
with:
context: .
push: true
tags: ghcr.io/jalcocert/r-stocks:latest
tags: ghcr.io/jalcocert/r-stocks:v1.0
38 changes: 38 additions & 0 deletions .github/workflows/build_shiny_multiarch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI/CD Build MultiArch Shiny

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CICD_TOKEN_Shiny }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/jalcocert/r-stocks:v1.1
ghcr.io/jalcocert/r-stocks:latest
25 changes: 0 additions & 25 deletions Docker-compose.yml

This file was deleted.

13 changes: 2 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# FROM rocker/shiny:3.6.1
# LABEL maintainer "JAlcocerT <[email protected]>"
# WORKDIR /srv/shiny-serverRUN apt-get update \
# && apt-get install -y libsasl2-dev libssl-devRUN echo \
# 'options(repos=list(CRAN="https://cloud.r-project.org/"))' > \
Expand Down Expand Up @@ -28,7 +27,6 @@
# #################### Building from shiny docker image ###################3

# FROM rocker/shiny
# LABEL maintainer "JAlcocerT <[email protected]>"

# WORKDIR /srv/shiny-server

Expand Down Expand Up @@ -94,6 +92,8 @@
# ###########################OK##################################

FROM rocker/tidyverse:4
LABEL maintainer "JAlcocerT"
LABEL org.opencontainers.image.source https://github.com/JAlcocerT/R_Stocks

RUN R -e 'install.packages(c("shiny", "plotly", "viridis","dplyr", "tidyr","lubridate","shinythemes","shinyWidgets","DT","bslib","priceR","quantmod"))'

Expand All @@ -109,17 +109,8 @@ CMD R -e 'shiny::runApp("app.R", port = 3838, host = "0.0.0.0")'

# ####################################################################

# #sudo docker build -t cerdo/shiny2 .
# #sudo docker run -p3838:3838 -detached cerdo/shiny2



# #sudo DOCKER_BUILDKIT=1 docker build --no-cache --progress=plain -t fossengineer/rstocks .
# #sudo docker run -p 3838:3838 --name rstonkss -detached fossengineer/rstocks

# #sudo docker login
# #sudo docker push fossengineer/rstocks

# ########################casi casi############################

# #https://hub.docker.com/r/rocker/r-ver
Expand Down
42 changes: 21 additions & 21 deletions EDA/R_Stocks_Analysis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ df_tickers_curr$price_close_eur = df_tickers_curr$price_close*df_tickers_curr$on
library(dplyr)
df_tickers_inflation <- df_tickers %>% filter(ref_date <= '2021-12-31')
df_tickers_inflation <- df_tickers %>% filter(ref_date <= '2023-12-31')
```

Expand All @@ -806,18 +806,18 @@ library(priceR)
#show_countries()
Year <- 2000:2021
Year <- 2000:2023
nominal_prices <- rep(1,length(Year))
df_inflation <- data.frame(Year, nominal_prices)
df_inflation$in_202x_dollars_factor <- adjust_for_inflation(nominal_prices, Year, "US", to_date = 2021) #PriceR
df_inflation$in_202x_dollars_factor <- adjust_for_inflation(nominal_prices, Year, "US", to_date = 2023) #PriceR
df_inflation <- mutate(df_inflation, inflation_level = ( lag(in_202x_dollars_factor)/in_202x_dollars_factor -1)*100 )
plot_ly(df_inflation, type = 'scatter', mode = 'lines') %>%
add_trace(x = ~Year, y = ~in_202x_dollars_factor, name="Inflation factor to Y2021") %>%
add_trace(x = ~Year, y = ~in_202x_dollars_factor, name="Inflation factor to Y2023") %>%
layout(title = '<b>US Historical Inflation<b>', xaxis = list(title = 'Year'),
yaxis = list(title = 'a'),
legend = list(title=list(text='<b> Legend </b>'))) %>%
Expand All @@ -829,11 +829,11 @@ plot_ly(df_inflation, type = 'scatter', mode = 'lines') %>%
plot_ly(df_inflation) %>%
add_trace(x = ~Year, y = ~in_202x_dollars_factor, type = 'scatter', mode = "lines", yaxis = "y2",name="$ Factor Y2021") %>%
add_trace(x = ~Year, y = ~in_202x_dollars_factor, type = 'scatter', mode = "lines", yaxis = "y2",name="$ Factor Y2023") %>%
add_trace(x = ~Year, y = ~inflation_level, type = 'bar',name='Yearly Inflation US')%>%
layout(title = '<b>US Inflation Data<b>', xaxis = list(title = 'Date'),
yaxis = list(title = 'Inflation (%Y)'), legend = list(title=list(text='<b> Legend </b>')),
yaxis2 = list(overlaying = "y", side = "right",automargin = T,title = "Factor Y2021",range = c(0,3))
yaxis2 = list(overlaying = "y", side = "right",automargin = T,title = "Factor Y2023",range = c(0,3))
)
Expand Down Expand Up @@ -887,13 +887,13 @@ plot_ly(df_inflation) %>%
#
# # Specifying second error message
# error = function(e){
# print(paste("There was an error message for 2022 too. Then considering one year less for inflation:","2021"))
# print(paste("There was an error message for 2022 too. Then considering one year less for inflation:","2023"))
#
# a=a+1
# Year <- 2000:2021
# Year <- 2000:2023
# nominal_prices <- rep(1,length(Year))
# df_inflation <- data.frame(Year, nominal_prices)
# df_inflation$in_202x_dollars_factor <- adjust_for_inflation(nominal_prices, Year, "US", to_date = 2021) #PriceR
# df_inflation$in_202x_dollars_factor <- adjust_for_inflation(nominal_prices, Year, "US", to_date = 2023) #PriceR
# })
# },
# finally = {
Expand Down Expand Up @@ -1469,12 +1469,12 @@ for(i in (n+1):nrow(divs_agg_ticker)) {
library(tidyr) #for drop_na
Year <- 2000:2021
Year <- 2000:2023
#nominal_prices <- rnorm(10, mean=10, sd=3)
nominal_prices <- rep(1,length(Year))
df_inflation <- data.frame(Year, nominal_prices)
df_inflation$in_2020_dollars_factor <- adjust_for_inflation(nominal_prices, Year, "US", to_date = 2021) #PriceR
df_inflation$in_2020_dollars_factor <- adjust_for_inflation(nominal_prices, Year, "US", to_date = 2023) #PriceR
Expand Down Expand Up @@ -1764,7 +1764,7 @@ ending_date="2022-01-01"
#inflation & money input (priceR)
Year <- (year(initial_date)-1):(year(ending_date)-1) #2000 to 2021
Year <- (year(initial_date)-1):(year(ending_date)-1) #2000 to 2023
#nominal_prices <- rnorm(10, mean=10, sd=3)
nominal_prices <- rep(1,length(Year))
Expand Down Expand Up @@ -1868,7 +1868,7 @@ ending_date="2022-01-01"
#inflation & money input (priceR)
Year <- (year(initial_date)-1):(year(ending_date)-1) #2000 to 2021
Year <- (year(initial_date)-1):(year(ending_date)-1) #2000 to 2023
#nominal_prices <- rnorm(10, mean=10, sd=3)
nominal_prices <- rep(1,length(Year))
Expand Down Expand Up @@ -1992,9 +1992,9 @@ divs_agg <- setNames( aggregate(div ~ year(date) + ticker, data = divs, FUN = su
#divs_agg %>% group_by(ticker) %>% top_n(1, Year_div)
#divs_agg %>% group_by(ticker) %>% top_n(2, Year_div)
#divs_agg[divs_agg$Year_div== 2021,]%>% group_by(ticker)
#divs_agg[divs_agg$Year_div== 2023,]%>% group_by(ticker)
DCA_df_divs <- left_join(DCA_df, divs_agg[divs_agg$Year_div== 2021,]%>% group_by(ticker), by=c('ticker'='ticker'))
DCA_df_divs <- left_join(DCA_df, divs_agg[divs_agg$Year_div== 2023,]%>% group_by(ticker), by=c('ticker'='ticker'))
#DCA_df_divs <- left_join(DCA_df, divs_agg %>% group_by(ticker) %>% top_n(1, Year_div), by=c('ticker'='ticker'))
DCA_df_divs <- left_join(DCA_df_divs, hist_price %>% group_by(ticker) %>% top_n(1, ym), by=c('ticker'='ticker'))
Expand Down Expand Up @@ -2166,7 +2166,7 @@ ending_date="2022-01-01"
#inflation & money input (priceR)
Year <- (year(initial_date)-1):(year(ending_date)-1) #2000 to 2021
Year <- (year(initial_date)-1):(year(ending_date)-1) #2000 to 2023
#nominal_prices <- rnorm(10, mean=10, sd=3)
nominal_prices <- rep(1,length(Year))
Expand Down Expand Up @@ -2331,13 +2331,13 @@ historical_yield <- list()
historical_CF <- list()
# j=2021
# j=2023
# DCA_df_divs <- left_join(DCA_df, divs_agg %>% group_by(ticker) %>% filter( Year_div == j) , by=c('ticker'='ticker'))
# DCA_df_divs$div_cash_flow <- DCA_df_divs$Stocks*DCA_df_divs$div
# (sum(DCA_df_divs$div_cash_flow)/sum(hist_price_infl_filtered[hist_price_infl_filtered$Year <= j ,]$money_input_infl)+1)*100-100
for ( j in 2000:2021 ) {
for ( j in 2000:2023 ) {
#divs_agg %>% group_by(ticker) %>% filter( Year_div == j)
#divs_agg %>% group_by(ticker) %>% top_n(1, Year_div)
Expand Down Expand Up @@ -2369,7 +2369,7 @@ historical_CF <- list()
historical_yield =unlist(historical_yield)
historical_CF =unlist(historical_CF)
yearz = 2000:2021
yearz = 2000:2023
dfz = data.frame(historical_yield,historical_CF,yearz)
Expand Down Expand Up @@ -2435,15 +2435,15 @@ invest = 1000 #it will assume that all given tickers are included in the hist_pr
initial_date="2005-01-01" #year(initial_date)
ending_date="2021-12-31"
ending_date="2023-12-31"
initial_investment_date <- "2005-01-01"
final_investment_date <- "2008-12-31"
#inflation & money input (priceR)
Year <- (year(initial_date)-1):(year(ending_date)) #2018 to 2021
Year <- (year(initial_date)-1):(year(ending_date)) #2018 to 2023
#nominal_prices <- rnorm(10, mean=10, sd=3)
nominal_prices <- rep(1,length(Year))
Expand Down
16 changes: 8 additions & 8 deletions EDA/R_Stocks_Shiny.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ ending_date = today() #IMPORTANT: Historical inflation data on the current y
#ending_date="2023-01-14"
ending_date="2021-12-31"
ending_date="2023-12-31"
Expand Down Expand Up @@ -373,7 +373,7 @@ df_inflation <- mutate(df_inflation, inflation_level = ( lag(in_202x_dollars_fac
theme <- bs_theme(
# Controls the default grayscale palette
bg = "#202123", fg = "#B8BCC2",
bg = "#202323", fg = "#B8BCC2",
# Controls the accent (e.g., hyperlink, button, etc) colors
primary = "#EA80FC", secondary = "#48DAC6",
base_font = c("Grandstander", "sans-serif"),
Expand Down Expand Up @@ -574,9 +574,9 @@ if (interactive()) {
min = min_year, max = max_year-1, value = c(2010, 2020)),
sliderInput("year_yoc",
"YoC looking from the year (TODAY*)",
min = min_year, max = max_year-1, value = 2021,width = "90%"),
min = min_year, max = max_year-1, value = 2023,width = "90%"),
sliderInput("money_in_portf",
"Monetary input - Monthly (value of 2021)",
"Monetary input - Monthly (value of 2023)",
min = 100, max = 5000, value = 1000,width = "90%"),
selectInput(
'selected_tickers_portf',
Expand Down Expand Up @@ -732,7 +732,7 @@ if (interactive()) {
sliderInput("years_inflation",
label = h3("Years"),
min = min_year, max = max_year-1, value = c(2000, 2021)),
min = min_year, max = max_year-1, value = c(2000, 2023)),
selectInput(
'selected_countries',
'Select Countries',
Expand Down Expand Up @@ -1426,17 +1426,17 @@ df_inflation$money_input_infl_year <- input$money_in_portf/df_inflation$in_202x_
# plot_ly(df_inflation) %>%
# add_trace(x = ~Year, y = ~in_202x_dollars_factor, type = 'scatter', mode = "lines", yaxis = "y2",name="$ Factor Y2021") %>%
# add_trace(x = ~Year, y = ~in_202x_dollars_factor, type = 'scatter', mode = "lines", yaxis = "y2",name="$ Factor Y2023") %>%
# add_trace(x = ~Year, y = ~inflation_level, type = 'bar',name='Yearly Inflation US')%>%
# layout(title = '<b>US Inflation Data<b>', xaxis = list(title = 'Date'),
# yaxis = list(title = 'Inflation (%Y)'), legend = list(title=list(text='<b> Legend </b>')),
# yaxis2 = list(overlaying = "y", side = "right",automargin = T,title = "Factor Y2021",range = c(0,3))
# yaxis2 = list(overlaying = "y", side = "right",automargin = T,title = "Factor Y2023",range = c(0,3))
# )
#
plot_ly(df_inflationinteractive(), type = 'scatter', mode = 'lines') %>%
add_trace(x = ~Year, y = ~in_202x_dollars_factor, name="Inflation factor to Y2021") %>%
add_trace(x = ~Year, y = ~in_202x_dollars_factor, name="Inflation factor to Y2023") %>%
layout(title = '<b>US Historical Inflation<b>', xaxis = list(title = 'Year'),
yaxis = list(title = 'a'),
legend = list(title=list(text='<b> Legend </b>'))) %>%
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

Using public financial data together with in R to create an interactive Shiny App to check how noisy the stock market can be and definitely [not a tool to guide your personal finances](https://github.com/JAlcocerT/R_Stocks#important---no-investment-advice).

* Further Description at: <https://fossengineer.com/project-shiny-R-Stocks/>
* Further Description at: <https://jalcocert.github.io/JAlcocerT/R-Stocks/>

## Repisotory Structure

Expand All @@ -31,8 +31,8 @@ Using public financial data together with in R to create an interactive Shiny Ap
* Dividend Analysis: yfR, QuantMod, PriceR, *QuandDl (optional)*
* Portfolio Analysis: yfR, QuantMod, PriceR
* **The R-Stocks App:**
* [Docker and the R-Stocks Shiny App](https://fossengineer.com/building-r-shiny-apps-container-image-with-docker/)
* Versioning of the Docker Images: <https://hub.docker.com/repository/docker/fossengineer/r_stocks>
* [Docker and the R-Stocks Shiny App](https://jalcocert.github.io/JAlcocerT/building-r-shiny-apps-container-image-with-docker/)
* Versioning of the [Docker Container Images at GHCR](https://github.com/users/JAlcocerT/packages/container/package/r-stocks)

## 🎯 Features and RoadMap

Expand Down Expand Up @@ -83,20 +83,17 @@ I am listing here the ones that served as major pilars for making the project co
&nbsp;

* <https://github.com/ropensci/yfR>
* [Discovering the yfR package](https://fossengineer.com/r-yfR-package-guide/)
* <https://github.com/stevecondylios/priceR>
* [Querying currency pairs with PriceR](https://fossengineer.com/r-priceR-package-guide/)
* <https://github.com/joshuaulrich/quantmod>
* [My guide for QuantMod Package](https://fossengineer.com/r-Quantmod-package-guide/)
* <https://github.com/quandl/quandl-r>
* [Using the quandl R Package](https://fossengineer.com/r-quandl-package-guide/)

</details>

* Other Data sources:
* For the Flexdashboard: <https://github.com/datasets/s-and-p-500>
* <https://finance.yahoo.com/quote/GC=F/>
* <https://www.macrotrends.net/1333/historical-gold-prices-100-year-chart>
* FED <https://fred.stlouisfed.org/series/FEDFUNDS>


#### Visualizations
Expand All @@ -122,7 +119,7 @@ I need to mention the importance of additional **open source tools** that made t

* Support extra evening code sessions:

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/FossEngineer)
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Z8Z1QPGUM)

## IMPORTANT! - NO INVESTMENT ADVICE

Expand Down
Loading

0 comments on commit 0ae5a2d

Please sign in to comment.