Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin Geissmann mgei

View GitHub Profile
@mgei
mgei / pca2.R
Created February 8, 2021 16:04
View pca2.R
# What is PCA?
# - PCA is a form of multi-dimensional scaling.
# - It transforms the data into a lower dimensional space while keeping the maxiumum of information.
# Book: Multi-Dimensional Diversification
# get data https://www.msci.com/end-of-day-data-search
library(tidyverse)
library(tidyquant)
library(readxl)
View treasury.R
library(tidyquant)
ty10 <- tq_get("DGS10", get = "economic.data", from = as.Date("1950-01-01"))
mod_dur <- function(yield) {
# out <- (1-(1/(1+0.5*yield/100)^(2*10)))/(yield/100)
out <- (1-(1/(1+0.5*yield)^(2*10)))/(yield)
return(out)
View get_earnings.R
library(tidyverse)
library(jsonlite)
get_earnings <- function(symbol, av_key, get = "quarterly", cache_dir = "cache") {
if (!(cache_dir %in% list.dirs(full.names = F, recursive = F))) {
dir.create(cache_dir)
}
if (!(paste0(symbol, ".json") %in% list.files(cache_dir))) {
print("downloading")
@mgei
mgei / SR_calc.R
Created September 25, 2020 07:35
Calculating the return, standard deviation, and SR for the SPX
View SR_calc.R
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,
View tabsetgetyoucrazy.R
library(shiny)
ui <- fluidPage(
fluidRow(
column(width = 12,
tabsetPanel(
tabItem("main", "MENU"),
tabItem("more", uiOutput("hello"))
))
)
@mgei
mgei / app.R
Created February 24, 2020 15:14
persistent data storage of user input in R Shiny
View app.R
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() %>%
@mgei
mgei / letf.R
Created January 17, 2020 10:43
leveraged etf compounding performance lag
View letf.R
library(tidyverse)
library(ggplot2)
periods <- 10
trend <- 0
vola <- 0.1
leverage <- 2
View persistent-tidy-data-shiny.R
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")
View videocore_notes.md

What I've done thus far

Install QMKL

But before:

Install Py-videocore

Increase video memory!

@mgei
mgei / localurl.R
Created April 2, 2019 10:27
R function to build a local URL for RMarkdown
View localurl.R
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))