Skip to content

Instantly share code, notes, and snippets.

@bkamins
bkamins / devsurv.jl
Created June 27, 2017 20:24
Analysis of Julia usage in StackOverflow Developer Survey 2017
using Requests
using StatsBase
const URL = "https://drive.google.com/uc?export=download&id=0B6ZlG_Eygdj-c1kzcmUxN05VUXM"
const ZNAME = "developer_survey_2017.zip"
const DNAME = "survey_results_public.csv"
function load()
isfile(DNAME) && return
if !isfile(ZNAME)
@bkamins
bkamins / bridgehand.jl
Last active September 26, 2017 13:45
Bridge hand distribution
using StatsBase # sample function
using Combinatorics # combinations function
using Plots # plotting infrastructure
# Code calculating distribution of HCP in hands of a pair of players in bridge
# Ace is worth 4 points, King 3, Queen 2, Jack 1, all other cards (36 in total) count as 0
# Get the distribution using simulation
function sim_hand()
n = 1_000_000
@bkamins
bkamins / asianoption.jl
Last active October 19, 2017 21:26
Asian option pricing in Julia
function v_asian_sample(T, r, K, σ, X₀, m::Integer)
X = X₀
x̂ = zero(X)
Δ = T/m
for i in 1:m
X *= exp((r-σ^2/2)*Δ + σ*√Δ*randn())
x̂ += X
end
exp(-r*T)*max(x̂/m - K, 0)
end
@bkamins
bkamins / asianoption.py
Created October 19, 2017 20:50
Asian option pricing in Python
import math
import random
import statistics
import numpy
from timeit import default_timer as timer
from numba import jit
def v_asian_sample(T, r, K, s, X0, m):
xhat = 0.0
X = X0
function decode_utf8(x::Char)
c = reinterpret(UInt32, x)
if c < 0x00000080
return c
end
if 0x0000C200 <= c & 0x0000FF00 <= 0x0000DF00
if c & 0xffff0000 == 0 && 0x00000080 <= c & 0x000000FF <= 0x000000BF
return (c & 0x0000003F) | ((c & 0x00001F00) >> 2)
end
end
@bkamins
bkamins / MW_PD_2.ipynb
Last active March 16, 2018 23:20
MW, praca domowa 2
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bkamins
bkamins / design.r
Created April 9, 2018 09:38
Source codes for K. Growiec, J. Growiec, B. Kamiński: Social Network Structure and The Trade-Off Between Social Utility and Economic Performance, Social Networks, forthcoming
# K. Growiec, J. Growiec, B. Kamiński
# Social Network Structure and The Trade-Off Between Social Utility and Economic Performance
# Simulation experiment design generation file
library(randtoolbox)
size <- 65536
s_design <- sobol(size, 9, TRUE, 3, 4711, FALSE)
colnames(s_design) <- c("r", "p", "lambda", "sigma", "rho",
@bkamins
bkamins / BKAMINS_DSS2018.ipynb
Created June 7, 2018 18:32
Support material for presentation at DSS2018
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bkamins
bkamins / juliacon2018_presentation.md
Last active August 10, 2018 11:40
JuliaCon 2018: Asian option pricing using Monte-Carlo simulation using multi-threading in Julia

Asian option pricing using Monte-Carlo simulation using multi-threading in Julia

JuliaCon 2018

Bogumił Kamiński

http://bogumilkaminski.pl/about

rand is not thread safe

@bkamins
bkamins / forestfire1.jl
Last active July 30, 2018 21:28
SSC2018 introduction to agent-based modeling in Julia
using Random
function setup(density)
[x == 1 ? 2 : rand() < density ? 1 : 0 for x in 1:251, y in 1:251]
end
function go(grid)
any(isequal(2), grid) || return true
for pos in shuffle!(findall(isequal(2), grid))
x, y = pos[1], pos[2]