Skip to content

Instantly share code, notes, and snippets.

View mgei's full-sized avatar

Martin Geissmann mgei

View GitHub Profile
@mgei
mgei / open_closing_hours.R
Created February 21, 2019 10:24
R create tibble for open close hours to be used for timevis with type = "range"
library(tidyverse)
library(lubridate)
days <- tibble(date = seq(date("2018-01-01"), by = "days", length.out = 730)) %>%
mutate(day = weekdays(date))
hours <- tibble(daytype = c("weekday", "weekday", "weekday", "weekday", "weekday", "weekend"),
time_from = c("00:00", "08:00", "12:00", "13:00", "17:00", "00:00" ),
time_to = c("08:00", "12:00", "13:00", "17:00", "23:59", "23:59" ),
state = c("closed", "open", "closed", "open", "closed", "closed"))
@mgei
mgei / localurl.R
Created April 2, 2019 10:27
R function to build a local URL for RMarkdown
library(tidyverse)
localurl <- function(document, path = ""){
path <- str_remove_all(path, "/$|^/")
document <- str_remove_all(document, "/$|^/")
path <- file.path(path, document) %>%
str_remove_all("/$|^/")
document <- last(str_split(path, pattern = "/", simplify = T))
# to install the latest version 0.53 of Hugo on Ubuntu:
# releases are here: https://github.com/gohugoio/hugo/releases
export VER="0.55.5"
wget https://github.com/gohugoio/hugo/releases/download/v0.55.5/hugo_${VER}_Linux-64bit.deb
sudo dpkg -i hugo_${VER}_Linux-64bit.deb
# check if right version is installed
hugo version
# make a new website (don't do that if you already have one)

What I've done thus far

Install QMKL

But before:

Install Py-videocore

Increase video memory!

library(shiny)
library(tidyverse)
# data <- readRDS("persistent_data/data.RDS")
data <- as_tibble(mtcars) %>% head()
ui <- fluidPage(
tableOutput("mytable"),
actionButton("go", "filter it"),
actionButton("save", "save it")
@mgei
mgei / letf.R
Created January 17, 2020 10:43
leveraged etf compounding performance lag
library(tidyverse)
library(ggplot2)
periods <- 10
trend <- 0
vola <- 0.1
leverage <- 2
@mgei
mgei / app.R
Created February 24, 2020 15:14
persistent data storage of user input in R Shiny
library(shiny)
library(shinyWidgets)
library(tidyverse)
# read persistent data or create a new file if it does not exist yet
if ("favs.csv" %in% list.files()) {
favs <- read_file("favs.csv") %>%
strsplit(", ") %>%
.[[1]] %>%
as.numeric() %>%
library(shiny)
ui <- fluidPage(
fluidRow(
column(width = 12,
tabsetPanel(
tabItem("main", "MENU"),
tabItem("more", uiOutput("hello"))
))
)
@mgei
mgei / SR_calc.R
Created September 25, 2020 07:35
Calculating the return, standard deviation, and SR for the SPX
library(tidyverse)
library(tidyquant)
library(lubridate)
# get data from Yahoo ----
spx <- tq_get("^GSPC")
# calculate returns ----
ret_daily <- spx %>%
mutate(ret = adjusted/lag(adjusted)-1,