Skip to content

Instantly share code, notes, and snippets.

View lildata's full-sized avatar

Programming is fun lildata

View GitHub Profile
def usd(amount) = Scale(Const(amount),One("USD"))
def stock(symbol) = Scale(Lookup(symbol),One("USD"))
def buy(contract, amount) = And(contract,Give(usd(amount)))
def sell(contract, amount) = And(Give(contract),usd(amount))
def zcb(maturity, notional, currency) = When(maturity, Scale(Const(notional),One(currency)))
def option(contract) = Or(contract,Zero())
def europeanCallOption(at, c1, strike) = When(at, option(buy(c1,strike)))
def europeanPutOption(at, c1, strike) = When(at, option(sell(c1,strike)))
def americanCallOption(at, c1, strike) = Anytime(at, option(buy(c1,strike)))
def americanPutOption(at, c1, strike) = Anytime(at, option(sell(c1,strike)))
@lildata
lildata / mapdb.clj
Created October 8, 2015 09:17 — forked from hideshi/mapdb.clj
This is hash map database written in Clojure. See also: http://d.hatena.ne.jp/hideshi_o/20121123/1353698397
;mapdb.clj
(ns db.mapdb
(:use
[clojure.contrib.duck-streams :only (reader)]
[clojure.java.io :only (writer)]
[clojure.string :only (split)]
[clojure.contrib.server-socket :only (create-server close-server)]))
(def database-file "/Users/hideshi/Dev/Clojure/db/dbfile")
(ns async-tut1.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [goog.dom :as dom]
[goog.events :as events]
[cljs.core.async :refer [<! put! chan]])
(:import [goog.net Jsonp]
[goog Uri]))
(def wiki-search-url
"http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=")
(dont cheat)

\w is the same as [a-zA-Z0-9]

@lildata
lildata / simple-date-format.clj
Created September 10, 2015 21:10
there is a simpler one I think if you have Java 8
(.format (java.text.SimpleDateFormat. "yyyy-MM-dd") (java.util.Date.))
@lildata
lildata / common-1-letter-var-names.clj
Last active September 10, 2015 21:08
One letter variables names that most people will probably recognize
x: item
n: a number
m: map
v: value
k: key
i: index
c: char
t: tree
f: function
(defnk net-present-value
"(net-present-value :rate 0.05 :cashflows [-1000 500 600 800])"
[:rate :cashflows]
(reduce + (map #(/ %1 (pow (inc rate) %2)) cashflows (range))))