This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
life_table <- read.table(file = "path_to_file/.../life_table.txt", header = T, | |
skip = 2, stringsAsFactors = F) | |
q_x <- life_table[life_table$Year == 2011, "qx"] # q_x[x + 1] reffers to age x | |
p_x <- 1 - q_x | |
rm(life_table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(copula) | |
library(stats4) | |
set.seed(1) | |
# simulate sample from copula | |
u <- rCopula(n = 1000, copula = claytonCopula(param = 2, dim = 2)) | |
# simulate marginals | |
x <- cbind(qnorm(u[, 1], mean = 10, sd = 10), qnorm(u[, 2], mean = 5, sd = 5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WARNING: searches for risk aversion coefficient root assuming to be in range | |
# 0.01 and 1000 | |
markowitz_portfolio <- function(means, sds, corr, | |
fixed = c("mean", "variance", "lambda"), | |
fixed_level) { | |
fixed <- match.arg(fixed) | |
n <- length(means) | |
one <- rep(1, n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# library("ggplot2") | |
# library(reshape2) | |
adjust_data <- function(vector, name, na_list) { | |
vector <- clean_data(vector = vector, na_list = na_list) | |
frequencies <- numeric(5) | |
for(i in seq_along(vector)) { | |
frequencies[vector[i]] <- frequencies[vector[i]] + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(readxl) | |
library(xtable) | |
excel2latex <- function(path, sheet = 1, col_names = TRUE, col_types = NULL, | |
na = "", skip = 0) { | |
data <- readxl::read_excel(path = path, sheet = sheet, | |
col_names = col_names, col_types = col_types, | |
na = na, skip = skip) | |
browser() | |
output <- print(xtable(data, digits = 5), include.rownames = FALSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
country_continent <- c( | |
AD= "Europe", | |
AE = "Asia", | |
AF = "Asia", | |
AG = "North America", | |
AI = "North America", | |
AL = "Europe", | |
AM = "Asia", | |
AN = "North America", | |
AO = "Africa", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string <- "Maximize | |
obj: x1 + 2 x2 + 3 x3 + x4 | |
Subject To | |
c1: - x1 + x2 + x3 + 10 x4 <= 20 | |
c2: x1 - 3 x2 + x3 <= 30 | |
c3: x2 - 3.5 x4 = 0 | |
Bounds | |
0 <= x1 <= 40 | |
2 <= x4 <= 3 | |
General |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options(stringsAsFactors = FALSE) | |
library("rvest") | |
library("stringr") | |
rm(list = ls()) | |
equal_lengths <- function(...) { | |
sizes <- sapply(X = list(...), FUN = length) | |
return(all(rep(sizes[1], length(sizes)) == sizes)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("ggplot2") | |
log_alm <- read.csv(file = "/Users/irudnyts/Documents/projects/data/alm_logs.csv", | |
stringsAsFactors = FALSE) | |
exercises <- as.Date(c("2016-10-18", "2016-11-02", "2016-11-16", "2016-12-07")) | |
before_exercises <- exercises - 7 | |
midterm <- as.Date("2016-11-23") | |
colnames(log_alm) <- tolower(colnames(log_alm)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("rvest") | |
library("stringr") | |
base_url <- "http://www.artemis.bm" | |
url <- "http://www.artemis.bm/deal_directory/" | |
links <- paste0(base_url, | |
read_html(url) %>% | |
html_nodes(".table-style01 a") %>% |
OlderNewer