Skip to content

Instantly share code, notes, and snippets.

(* Define monadic operations for a list *)
let return x = [x]
let (>>=) lst f = List.concat (List.map f lst)
(* Generate the combinations of k distinct objects from a list *)
(* Simple version

FX Forwards

The standard no-arbitrage price $F_{t,T}$ for currency forwards when the spot price is $S_t$, the domestic rate is $r_d$ and the foreign rate is $r_f$ is

$$F_{t,T} = S_t (1 + (r_d-r_f)(T-t) )$$

and the price time $\delta t$ later is

<h1 id="fx-forwards">FX Forwards</h1>
<p>The standard no-arbitrage price <span class="MathJax_Preview"></span><span class="MathJax" id="MathJax-Element-1-Frame" role="textbox" aria-readonly="true"><nobr><span class="math" id="MathJax-Span-1" style="width: 2.069em; display: inline-block;"><span style="display: inline-block; position: relative; width: 1.715em; height: 0px; font-size: 121%;"><span style="position: absolute; clip: rect(1.243em 1000.003em 2.6em -0.469em); top: -2.122em; left: 0.003em;"><span class="mrow" id="MathJax-Span-2"><span class="msubsup" id="MathJax-Span-3"><span style="display: inline-block; position: relative; width: 1.656em; height: 0px;"><span style="position: absolute; clip: rect(1.243em 1000.003em 2.305em -0.469em); top: -2.122em; left: 0.003em;"><span class="mi" id="MathJax-Span-4" style="font-family: MathJax_Math; font-style: italic;">F<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.121em;"></span></span><span style="display: inline-block; width: 0px; h
@chris-taylor
chris-taylor / interpreter.hs
Last active August 29, 2015 14:04
Interpreter for Hanno's made-up assembly language
import Data.Map (Map, (!), insert, empty)
import Control.Monad.State (StateT, put, get, liftIO, evalStateT)
type Val = Int
type Var = String
data Instruction =
Set Val Var
| Print Var
| Add Var Var Var
@chris-taylor
chris-taylor / design.hs
Created June 23, 2015 09:59
scrappy code to find (n,k,t) designs with greedy algorithm
select [] = []
select (x:xs) = (x,xs) : select xs
pairs nums = [(a, b) | (a, bs) <- select nums, b <- bs]
triples nums = [(a,b,c) | (a,bs) <- select nums, (b,cs) <- select bs, c <- cs]
overlap (a,b,c) (d,e,f) =
case compare a d of
{-# LANGUAGE GADTs #-}
module Spreadsheet where
import Control.Applicative
import Control.Monad (forM_)
import Data.IORef
import Data.List (union)
import Data.Unique
@chris-taylor
chris-taylor / isdual.m
Created March 9, 2012 10:25
Test if a Matlab object is a Dual
function b = isdual(a)
%ISDUAL Return true if a is of class Dual, else return false
b = strcmp(class(a),'Dual');
end
@chris-taylor
chris-taylor / SetDefault.m
Created March 23, 2012 09:23
Set default values for Matlab function arguments
function SetDefault(argname,value)
%SETDEFAULT Provide a default value of VALUE for the argument ARGNAME.
%
%USAGE
% SetDefault('x',1)
% If no variable 'x' exists in the calling function, or if the variable exists
% but it is empty, then this call assigns the value 1 to 'x'. If the variable
% 'x' already exists, and is non-empty, then no action is taken.
%
@chris-taylor
chris-taylor / sicp3.3.hs
Created April 9, 2012 21:40
Exercise in 3.3 of SICP
import Control.Monad.ST
import Data.STRef
-- Primitive actions
getSignal wire = wire GetSignal
setSignal wire x = wire (SetSignal x)
addAction wire proc = wire (AddAction proc)
@chris-taylor
chris-taylor / ffi.py
Created April 29, 2012 11:38
Quick and dirty implementation of first fit decreasing algo for bin packing
import random
import time
N = 200
binsize = 8000;
xs = [100 * random.randint(1,40) for i in range(N)]
print '\nObjects to be packed:\n'
print xs