Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import numpy.random as nr
def gen(N):
X = nr.choice([0,1],size=N,p=[0.6,0.4])
D = nr.choice([0,1],size=N,p=[0.6,0.4])
epsi = nr.uniform(0,2,N)
Y = X+D*epsi
return X,D,epsi,Y
def estim(D,Y):
@jmoy
jmoy / thugs_suitcase.py
Last active May 29, 2017 04:43
River crossing puzzle
import itertools as it
NTHUGS = 3
NCASES = 2
BOATCAP = 3
thugs = set()
cases = set()
owner = dict()
nresults = 0
@jmoy
jmoy / CL_RBC.py
Last active October 9, 2016 19:06
Value Function Iteration Using OpenCL
# Basic RBC model with full depreciation
# U(c) = log(c)
# F(K) = Z k^\alpha
# where Z is a finite-state Markov chain
#
# Original version:
# Jesus Fernandez-Villaverde
# Haverford, July 3, 2013
# https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Python.py
#
@jmoy
jmoy / KnightTours.hs
Created April 27, 2016 16:36
Enumerate all closed Knight's tours (multithreaded, Haskell)
{-#LANGUAGE BangPatterns #-}
{-
Enumerate all closed Knight's Tours in an
arbitrarity sized chessboard. Multi-threaded version.
Usage:
KnightTours m n +RTS -N
Compile with:
/*
A multi-threaded brute-force search for closed Knight's tours (used OpenMP)
Usage: knights_tours [m] [n]
to search for tour on a m x n board
rows are denoted by letters A.., columns by numbers 0..
Compile with
g++ -O3 -Wall -std=c++11 -fopenmp knight_tours.cc -o knight_tours
@jmoy
jmoy / knights_tour.cc
Created April 23, 2016 07:32
Knight's Tour using OpenMP
/*
A multi-threaded brute-force search for closed Knight's tours (used OpenMP)
Usage: knights_tours [m] [n]
to search for tour on a m x n board
rows are denoted by letters A.., columns by numbers 0..
Compile with
g++ -O3 -Wall -std=c++11 -fopenmp knight_tours.cc -o knight_tours
@jmoy
jmoy / CompetitiveStoragePython.ipynb
Last active August 28, 2018 19:15
Solving the competitive storage model using collocation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jmoy
jmoy / wheat.py
Created September 19, 2015 07:13
Scrape daily wheat price data using Selenium and LXML
#!/usr/bin/python3
"""
Download wheat price data from http://agmarket.nic.in
Data is saved in file wheat.csv in current directory
Author: Jyotirmoy Bhattacharya, Ambedkar University, New Delhi, [email protected]
"""
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
library(QZ)
# Parameters
sigma = 1 #log utility
phi=1 #unitary Frisch elasticity
phi_pi = 1.5 #inflation feedback Taylor Rule
phi_y = .5/4 #output feedback Taylor Rule
theta=2/3 #Calvo parameter
rho_nu = 0.5 #autocorrelation monetary policy shock
/*
An implementation of Norvig's spelling corrector
Original: http://norvig.com/spell-correct.html
Author: Jyotirmoy Bhattacharya [[email protected]]
Must be compiled as C++14 (-std=c++1y for g++)
*/
#include <iostream>