Skip to content

Instantly share code, notes, and snippets.

estimate <- function(targetRate,difference,errorProb) {
ceiling(-log(errorProb) * targetRate / (difference^2))
}
estimate(0.045, 0.004, 0.05)
# Listing B.20 Exact binomial sample size calculation
errorProb <- function(targetRate,difference,size) {
pbinom(
ceiling(( targetRate - difference) * size),
size = size, prob = targetRate)
}
print(errorProb(0.045 , 0.004, est)) ## [1] 0.04153646
binSearchNonPositive <- function(fEventuallyNegative) {
@vladiim
vladiim / map.R
Created September 20, 2017 03:45
map <- list('index' = 'mapping')
vector <- c('index')
as.character(map[vector])
Date SP500 Dividend Earnings Consumer Price Index Long Interest Rate Real Price Real Dividend Real Earnings PE10
1871-01-01 4.44 0.26 0.4 12.46 5.32 85.1 4.98 7.67
1871-02-01 4.5 0.26 0.4 12.84 5.32 83.7 4.84 7.44
1871-03-01 4.61 0.26 0.4 13.03 5.33 84.49 4.77 7.33
1871-04-01 4.74 0.26 0.4 12.56 5.33 90.16 4.95 7.61
1871-05-01 4.86 0.26 0.4 12.27 5.33 94.6 5.06 7.79
1871-06-01 4.82 0.26 0.4 12.08 5.34 95.29 5.14 7.91
1871-07-01 4.73 0.26 0.4 12.08 5.34 93.51 5.14 7.91
1871-08-01 4.79 0.26 0.4 11.89 5.34 96.22 5.22 8.03
1871-09-01 4.84 0.26 0.4 12.18 5.35 94.94 5.1 7.85
set.seed(1)
x=matrix(rnorm(200),100,2)
xmean=matrix(rnorm(8,sd=4),4,2)
which=sample(1:4,100,replace=T)
x=x+xmean[which,]
plot(x,col=which,pch=19)
# Gen app
rails new blah -T
# Update Gemfile
# gem 'devise'
# gem 'bootstrap', '~> 4.0.0.alpha3'
# Install gems
bundle
require(lambda.tools)
chunk <- c('Garpolu', 'Grand Cape', 'blah Mount')
# List of c(replace_pattern, replace_with)
xforms <- list(c('Garpolu', 'Gbarpolu'), c('Grand Cape$', 'Grand Cape Mount'), c('ˆMount$', ''))
fold(xforms, function(r,ch) sub(r[1],r[2],ch), chunk)
chiS <- function(control_non_convert, control_convert, test_non_convert, test_convert) {
control <- c(control_non_convert, control_convert)
test <- c(test_non_convert, test_convert)
d <- as.data.frame(rbind(control, test))
chisq.test(d)
}
diffReq <- function(control_non_convert, control_convert, confidence) {
control_non_convert_test <- control_non_convert / 2
control_convert_test <- control_convert / 2
# http://www.r-bloggers.com/portfolio-optimization-using-r-and-plotly/
library(PortfolioAnalytics)
library(quantmod)
library(PerformanceAnalytics)
library(zoo)
library(stringr)
library(memoise)
# library(plotly)
#!/bin/bash
#
# When you are working on your macbook sitting in cafe and you have to go pee,
# you need some way to guard you machine.
#
# Start this script, remove any earphones, and go do the job.
# The assumption is the thief will close the lid of the laptop before taking it away.
# This script detects the closing of the lid and plays some loud audio that will
# likely distract the thief and/or grab attention of nearby people, making the