Skip to content

Instantly share code, notes, and snippets.

View nairbv's full-sized avatar

Brian Vaughan nairbv

View GitHub Profile
@nairbv
nairbv / CallOptionPrice.scala
Last active April 3, 2020 18:26
Scala script to price a call option using a binomial model. Work backwards from market price (using a solver) to find implied vol.
import scala.math
import scala.util.Random
/**
* Pricing a call option using a binomial option pricing model.
* Formulas from: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.119.9442&rep=rep1&type=pdf
*/
val r = new Random
@nairbv
nairbv / gist:7923811
Created December 12, 2013 06:02
An example of using a Manifest to get around type erasure
scala> def foo[T : Manifest](a : List[T]) = {
| val m = implicitly[Manifest[T]]
| val I = classOf[Int]
| val S = classOf[String]
| m.erasure match {
| case I => "hi"
| case S => "bye"
| case _ => "whatever"
| }
| }
//quick hack to pretty-print some text:
"((hi)(bye(yeah))((x)))".foldLeft(0){
(a,b)=> {
var indent=a;
b match {
case '('=> println("("); indent=a+2; print(" "*indent);
case ')'=>println;indent=a-2;println(" "*indent + ")");print(" "*indent)
case x => print(x);