Skip to content

Instantly share code, notes, and snippets.

@stucchio
stucchio / valuation_of_cash_flow_with_wealth_tax.py
Last active October 20, 2019 01:00
How to compute the valuation of a cash flow in the presence of a wealth tax.
import numpy as np
from numpy.linalg import solve
def vmat(n, discount_rate, tax_rate):
m = np.zeros(shape=(n,n))
discount = tax_rate*np.exp(-1*discount_rate*np.arange(n))
for i in range(n):
m[i, i:n] = discount[0:n-i]
m[i,i] = 1
return m
from pylab import *
from numpy import *
from numpy.linalg import solve
from scipy.integrate import odeint
from scipy.stats import norm, uniform, beta
from scipy.special import jacobi
a = 0.0
b = 3.0
theta=1.0
@stucchio
stucchio / beta_bandit.py
Created April 14, 2013 15:46
The beta-distribution based bayesian bandit algorith,.
from numpy import *
from scipy.stats import beta
class BetaBandit(object):
def __init__(self, num_options=2, prior=(1.0,1.0)):
self.trials = zeros(shape=(num_options,), dtype=int)
self.successes = zeros(shape=(num_options,), dtype=int)
self.num_options = num_options
self.prior = prior
@stucchio
stucchio / nyc_teacher.py
Created May 26, 2012 02:51
Plots used in my "NO SCATTERPLOT" post
# Data from: http://www.ny1.com/content/top_stories/156599/now-available--2007-2010-nyc-teacher-performance-data#doereports
from pylab import *
from pandas import *
import re
def get_data(filename):
d = read_csv(filename, delimiter="\t")
d['teacher'] = d['teacher_name_first_1'] + " " + d['teacher_name_last_1']
return d

Keybase proof

I hereby claim:

  • I am stucchio on github.
  • I am stucchio (https://keybase.io/stucchio) on keybase.
  • I have a public key ASA_kgAJceWD7PGBJvFyqObwCMqZDv2hcDqFPpdi8DrJvgo

To claim this, I am signing this object:

from scipy.stats import norm
from numpy import mean
x = norm(0,1).rvs(10000)
y = norm(1,1).rvs(10000) # Group Y is 1 standard deviation better than group X
print("Mean of group X, exceeding the cutoff: " + str(mean(x[x > 3]))) # Prints 3.22
print("Mean of group Y, exceeding the cutoff: " + str(mean(y[y > 3]))) # prints 3.40
from pylab import *
from numpy import *
from numpy.linalg import solve
from scipy.integrate import odeint
from scipy.stats import norm, uniform, beta
from scipy.special import jacobi
a = 0.0
@stucchio
stucchio / compass.py
Created January 8, 2016 10:44
Bayesian compass calibration script
from pylab import *
from scipy.stats import norm, uniform
theta_grid = arange(0,2*pi,1.0/1024.0)
true_b = pi/2
b_belief = ones(shape=theta_grid.shape, dtype=float)
b_belief /= b_belief.sum()
from pylab import *
hiv_infections = 29418
gun_homicides = 11078
gun_suicides = 19392
gun_deaths = gun_homicides + gun_suicides
hiv_qualys = array([22.9, 31.9])
hiv_qualys_discounted = array([9.34, 13.18])
@stucchio
stucchio / basic_income_with_death_estimate.py
Created November 15, 2013 20:51
Same as https://gist.github.com/stucchio/7447067 but accounting for death rates, as suggested by a commenter on the blog.
from pylab import *
from scipy.stats import *
num_adults = 227e6
basic_income = 7.25*40*50
labor_force = 154e6
disabled_adults = 21e6
current_wealth_transfers = 3369e9
def jk_rowling(num_non_workers):