This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Positions { | |
trait Investment | |
trait Position { | |
def investment: Investment | |
def tradingPnL: Option[Double] | |
def inventoryPnL: Option[Double] | |
final def totalPnL = inventoryPnL → tradingPnL | |
} | |
import Monoid._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Monoid[A] { | |
def identity: A | |
def mplus(a1: A, a2: A): A | |
} | |
object Monoid { | |
implicit val IntMonoid = new Monoid[Int] { | |
def identity = 0 | |
def mplus(a1: Int, a2: Int) = a1 + a2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Currency | |
object Fx { | |
type CcyPair = (Currency, Currency) | |
case class FxRate(from: Currency, to: Currency, rate: BigDecimal) { | |
def pair: CcyPair = from → to | |
def unary_~ = FxRate(to, from, 1 / rate) | |
def *(that: FxRate): FxRate = { | |
require(this.to == that.from) | |
FxRate(this.from, that.to, this.rate * that.rate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait MyList[+A] { | |
def fold[B](k: Option[(A, B)] => B): B | |
def map[B](f: A => B): MyList[B] = sys.error("Implement me in terms of fold") | |
def flatMap[B](f: A => MyList[B]): MyList[B] = sys.error("Implement me in terms of fold") | |
def headOption: Option[B] = sys.error("Implement me in terms of fold") | |
def tailOption: Option[MyList[B]] = sys.error("Implement me in terms of fold") | |
def isEmpty = sys.error("Implement me in terms of fold") | |
def length = sys.error("Implement me in terms of fold") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source.fromFile | |
import scalala.scalar._ | |
import scalala.tensor.:: | |
import scalala.tensor.mutable._ | |
import scalala.tensor.dense._ | |
import scalala.tensor.sparse._ | |
import scalala.library.Library._ | |
import scalala.library.LinearAlgebra._ | |
import scalala.library.Statistics._ | |
import scalala.library.Plotting._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object GOption { | |
def some[A](a: A): GOption[A] = new GOption[A] { | |
def cata[B](n: => B, s: A => B): B = sys.error("Implement me") | |
} | |
def none[A]: GOption[A] = new GOption[A] { | |
def cata[B](n: => B, s: A => B): B = sys.error("Implement me") | |
} | |
} | |
trait GOption[+A] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.math.ceil | |
import scala.math.log | |
import scala.math.min | |
import scala.math.abs | |
import scala.math.exp | |
import scala.math.pow | |
import java.security.MessageDigest | |
import java.nio.charset.Charset | |
import scalaz._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void sendMessage(String url, String params){ | |
final HttpURLConnection connection; | |
try { | |
URL requestUrl = new URL(url); | |
connection = (HttpURLConnection) requestUrl.openConnection(); | |
connection.setDoOutput(true); | |
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | |
connection.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length)); | |
connection.setRequestProperty("Content-Language", "en-US"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Goal: Use Scalding to datamine the 2010 US Census data (kindly provided by @ElonAzoulay & @hmason), to find | |
Where do the WEALTHY WELL EDUCATED ELITE live ? | |
WEALTHY == house value quarter million, household income 150k | |
WELL EDUCATED == sort by edu, edu = (10 * Phd + 5 * MS + 1 * BS) score | |
*/ | |
import com.twitter.scalding._ | |
import cascading.tuple.Fields | |
import cascading.tap.SinkMode |