Skip to content

Instantly share code, notes, and snippets.

@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.
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 / 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
@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 / 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 / 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)