Skip to content

Instantly share code, notes, and snippets.

View ecounysis's full-sized avatar

Eric Christensen ecounysis

View GitHub Profile
@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)
@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.scm
Created August 22, 2010 21:48
Black-Scholes Option Pricing Model in Scheme
(define new-pi 3.1415926)
(define days-in-year 365)
(define (sqrt-t days-to-expiration)
(sqrt (/ days-to-expiration days-in-year)))
(define (normal-dist zz)
(if (= zz 0) 0.5
[let ((p 0.2316419) (b1 0.31938153) (b2 -0.356563782)
#include <stdio.h>
#define BUFFER_SIZE 2
enum FLAGS {NONE, SLASH, COMMENT1, COMMENTM, QUOTE1, QUOTE2, COMMENTM_STAR};
char buffer[BUFFER_SIZE];
int buff_pointer = 0;
void flush(char buff[]);
int state = NONE;
char t;
#include <stdio.h>
#include <stdlib.h>
double stack[100];
char buffer[100];
int isDot(char);
int handle(char);
int ptr=0;
int bufptr=0;
@ecounysis
ecounysis / circuits.py
Created October 21, 2010 05:52
modeling different types of circuits for fun
class Circuit:
"""Base class for modeling circuits"""
_type="Circuit"
def __init__(self,a,b):
self.set(a,b)
def __repr__(self):
return str(self)
def cond(self, e, r1, r2):
if e:
return r1
@ecounysis
ecounysis / closure_recursion_1.js
Created November 25, 2010 19:24
Closures and Recursion in JavaScript
var SlideChanger = function(seconds_each) {
var index = -1;
// on the first cycle, index will be set to zero below
var maxindex = ($(".change_link").length) - 1;
// how many total slides are there (count the slide buttons)
var timer = function() {
// this is the function returned by SlideChanger
var logic = function() {
// this is an inner function which uses the
// enclosed values (index and maxindex) to cycle through the slides
@ecounysis
ecounysis / jalert.js
Created December 18, 2010 06:57
jQuery UI plugin for themed alerts and dialogs
/*
* jalert jQuery JavaScript Plugin v0.0.1
*
* Copyright 2010, Eric Christensen
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the copyright holder not be used in
@ecounysis
ecounysis / ll.c
Created February 11, 2011 06:32
My first attempt at building a linked list in C that actually compiles and works
#include <stdlib.h>
#include <stdio.h>
#include "ll.h"
LL *createlist(int item)
{
LL *it = malloc(sizeof(LL));
it->val = item;
printf("creating new LL@%p whose value is %d\n", it, item);
return it;
var callback = function(msg) {
alert(msg);
}
var funcList = [];
var vals = ['do', 're', 'mi'];
for(var m in vals) {
funcList[m] = function() {
callback(m);