Skip to content

Instantly share code, notes, and snippets.

View ecounysis's full-sized avatar

Eric Christensen ecounysis

View GitHub Profile
@ecounysis
ecounysis / bs.ml
Created July 13, 2010 08:08
Black-Scholes Option Pricing Model in OCaml
let list_sum ls = List.fold_left (fun a x->a+.x) 0.0 ls
let list_init c f = Array.to_list (Array.init c (fun x->f x))
let normal zz =
match zz with
|v when v = 0.0 -> 0.5
|v when v >= 6.0 -> 1.0
|v when v <= -6.0 -> 0.0
|v ->
let p = 0.2316419 in
@ecounysis
ecounysis / black-scholes.fs
Created July 13, 2010 00:45
Black-Scholes Option Pricing Model in F#
let normal zz =
let p = 0.2316419
let b = [0.31938153;-0.356563782;1.781477937;-1.821255978;1.330274428]
let f = 1.0/(sqrt (2.0*3.1415926))
let abszz = abs zz
let ff = f*(exp((-(abszz**2.0)/2.0)))
let sfunc e b = b/((1.0+p*abszz)**e)
let sfunclist = List.init 6 (fun x->(sfunc (float x)))
let s = List.init 5 (fun x->List.nth sfunclist (x+1) (List.nth b x))
let sz = ff * (List.sum s)
import httplib, os, urllib, base64, datetime
folder = <<workfolder>>
url = "posterous.com"
user = <<userid>>
def file_contents(filename):
readfile = open(folder + "\\" + filename, 'r')
date = readfile.readline().strip('\n')
content = readfile.read()
#light
open System
let conc ls :string =
if List.length ls = 0 then ""
else List.reduce (fun x y -> x + y) ls
let av_chars = ["0"; "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9"; "A"; "B"; "C"; "D"; "E"; "F"; "G"; "H"; "I"; "J"; "K"; "L"; "M"; "N"; "O"; "P"; "Q"; "R"; "S"; "T"; "U"; "V"; "W"; "X"; "Y"; "Z"; "a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"; "j"; "k"; "l"; "m"; "n"; "o"; "p"; "q"; "r"; "s"; "t"; "u"; "v"; "w"; "x"; "y"; "z";]
let special_chars = ["!"; "#"; "$"; "%"; "&"; "*"; "+"; "-"; "_"; "?"; "@";]
@ecounysis
ecounysis / bs.scm
Created April 5, 2010 02:33
Implementation of Black Scholes option pricing model using Scheme
(define black-scholes
[letrec (
[normal (lambda (zz)
(if (= zz 0) 0.5
[let ((p 0.2316419) (b1 0.31938153) (b2 -0.356563782) (b3 1.781477937)
(b4 -1.821255978) (b5 1.330274428)
(f (/ 1 (sqrt (* 2 3.1415926))))
(abszz (abs zz)))
[let ((ff (* f (exp (/ (- (expt abszz 2)) 2))))
(s1 (/ b1 (+ 1 (* p abszz))))
@ecounysis
ecounysis / LICENSE.txt
Created March 30, 2010 17:11
Black-Scholes Option Pricing Model
Copyright (C) 2011, Eric Christensen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
(define even?
(lambda (x)
(cond ((= x 0) #t)
(else (odd? (- x 1))))))
(define odd?
(lambda (x)
(cond ((= x 0) #f)
(else (even? (- x 1))))))
(define (p) (p))
(define (test x y)
(if (= x 0)
0
y))
(define (+ a b)
(if (= a 0)
b
(inc (+ (dec a) b))))
(define (+ a b)
(if (= a 0)
b
(+ (dec a) (inc b))))
(define pascal
(lambda (x)
(letrec ([last
(lambda (x)
(if (null? (cdr x)) x (last (cdr x))))]
[sum-two
(lambda (x)
(+ (car x) (cadr x)))]
[sum-doubles
(lambda (x)