F# For Quantitative Finance Review

F# For Quantitative Finance at Packt Pub Buy F# for Quantitative Finance on Amazon

Book Details

ISBN: 139781782164623

Paperback: 286 pages

Skill Level: Beginner/Intermediate F#, no previous finance knowledge assumed.

TLDR

Buy this book if you’re more comfortable with coding than mathematics and have wondered if there was any substance to the financial world. This book will definitely appeal to anyone who shares that curiosity but has no previous background in Finance.

Author: Johan Astborg

Excerpted from packtpub.com

"Most of Johan's quantitative background comes from Lund University, where he studied courses in computer science, mathematics, and physics. Currently Johan is studying pure mathematics at Lund University, Sweden, and is aiming for a PhD in the future, combining mathematics and functional programming.

Professionally, Johan has worked as a part-time developer for Sony Ericsson and various smaller firms in Sweden. He also works as a part-time consultant focusing on web technologies and cloud solutions. You can easily contact him by sending an e-mail to joastbg@gmail.com or visit his GitHub page at https://github.com/joastbg."

Reading format I bought and read this as an ebook, mostly via iBooks on a desktop MacBook.

F#?

You probably don't know about F# unless you're a professional .NET developer who's into ML-family languages. That must be the saddest Venn Diagram in history. Sadder still because F# is really terrific.

Think OCaml with cleaned up, refined syntax. F# is elegant, pragmatic, and interoperates well with existing C# .NET code while still providing a more functional philosophy for anyone who cares to embrace it.

Book Structure

The book is basically structured as follows:

  • Intro to F#
  • Intro to Volatility and Option Pricing
  • Build your own trading system

The first four chapters are a whirlwind tour of FSharp and some of the libraries used in the later parts.
This section will no doubt age the worst, as the libraries are constantly evolving. I also found myself skimming it as I'd played with the language a bit already. That said I still learned a thing or two. Chapter 5 though is where the magic begins...

The next part of the book delves into the world of volatility. The writing style becomes snappier as Johan starts to ease us into the bewildering lexicon and mathematical bag of tricks that is Quantitative Finance. I found the subject matter fascinating but bewildering at times. Think of it as a small, focused toolset for studying numerical variance in some sort of Time-Series. It could just as well apply to your Dev-Ops job as your pension plan.

/// Calculate logarithmic returns
let calcDailyReturns(prices:seq<float>) =  
    prices
    |> Seq.pairwise
    |> Seq.map (fun (x, y) -> log (x / y))

/// Annualized volatility
let annualVolatility(returns:seq<float>) =  
    let sd = stddev(calcDailyReturns(returns))

This bit demonstrates FSharp's pipe function, the very clear Seq module, and the nice, clear lambda syntax.

Another stylistic choice I really appreciate when I'm new to a language is that where possible there are no superfluous libraries used in this book. Johan is comfortable enough with the mathematics and the F# language to give us unadorned, unsophisticated, beautiful code examples.

Here's an example for calculating the Black-Scholes Delta (a ratio comparing the change in the price of an asset, usually a marketable security, to the corresponding change in the price of its derivative).

type PutCallFlag = Put | Call  
// The constants a1 to a5 are the Taylor series coefficients 
// used in the approximation for the numerical implementation:
/// Cumulative distribution function
let cnd x =  
  let a1 =  0.31938153
  let a2 = -0.356563782
  let a3 =  1.781477937
  let a4 = -1.821255978
  let a5 =  1.330274429
  let pi = 3.141592654
  let l  = abs(x)
  let k  = 1.0 / (1.0 + 0.2316419 * l)
  let w  = (1.0-1.0/sqrt(2.0*pi)*exp(-l*l/2.0)*(a1*k+a2*k*k+a3*(pow k 3.0)+a4*(pow k 4.0)+a5*(pow k 5.0)))
  if x < 0.0 then 1.0 - w else w

/// Black-Scholes Delta
// call_put_flag: Put | Call
// s: stock price
// x: strike price of option
// t: time to expiration in years
// r: risk free interest rate
// v: volatility
let black_scholes_delta call_put_flag s x t r v =  
  let d1=(log(s / x) + (r+v*v*0.5)*t)/(v*sqrt(t))
  match call_put_flag with
  | Put -> cnd(d1) - 1.0
  | Call -> cnd(d1)

I won't claim to understand all of this, but the code is incredibly clear, parameters are well documented and also any "magic" constants are explained to let the reader decide to pursue further reading about topics such as the Taylor Series.

Conclusion

Buy this book as an introduction to quantitative finance as a somewhat functional developer. For learning the F# language itself a better starting point would be http://fsharpforfunandprofit.com or simply http://fsharp.org

Mark

Read more posts by this author.

Subscribe to Functional Books

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!