F# for Quantitative Finance


F# for Quantitative Finance
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
$22.94
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
$44.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • Learn functional programming with an easy-to-follow combination of theory and tutorials
  • Build a complete automated trading system with the help of code snippets
  • Use F# Interactive to perform exploratory development
  • Leverage the .NET platform and other existing tools from Microsoft using F#

Book Details

Language : English
Paperback : 286 pages [ 235mm x 191mm ]
Release Date : December 2013
ISBN : 1782164626
ISBN 13 : 9781782164623
Author(s) : Johan Astborg
Topics and Technologies : All Books, Open Source


Table of Contents

Preface
Chapter 1: Introducing F# Using Visual Studio
Chapter 2: Learning More About F#
Chapter 3: Financial Mathematics and Numerical Analysis
Chapter 4: Getting Started with Data Visualization
Chapter 5: Learning Option Pricing
Chapter 6: Exploring Volatility
Chapter 7: Getting Started with Order Types and Market Data
Chapter 8: Setting Up the Trading System Project
Chapter 9: Trading Volatility for Profit
Chapter 10: Putting the Pieces Together
Index
  • Chapter 1: Introducing F# Using Visual Studio
    • Introduction
    • Getting started with Visual Studio
      • Creating a new F# project
        • Creating a new project in Visual Studio
        • Understanding the program template
        • Adding an F# script file
    • Understanding F# Interactive
    • Language overview
    • Explaining mutability and immutability
    • Primitive types
    • Explaining type inference
    • Explaining functions
      • Learning about anonymous functions
      • Explaining higher-order functions
      • Currying
      • Investigating lists
        • Concatenating lists
      • Tuples
      • The pipe operator
    • Documenting your code
    • Your first application
    • The whole program
      • Understanding the program
      • Extending the example program
      • The entire program
    • The power of prototyping
    • Functional languages in quantitative finance
    • Understanding the imperative code and interoperability
    • Summary
  • Chapter 2: Learning More About F#
    • Structuring your F# program
      • Looking into modules
        • Using functions and values in modules
      • Namespaces
    • Looking deeper inside data structures
      • Record types
      • Discriminated unions
      • Enumerations
      • Arrays
        • Interesting functions in an array module
      • Lists
        • Pattern matching and lists
        • Interesting functions in a list module
      • Sequences
        • Interesting functions in the sequence module
      • Sets
      • Maps
      • Interesting functions in the map module
      • Options
      • Strings
        • Interesting functions in the string module
    • Choosing data structures
      • Arrays
      • Lists
      • Sets
      • Maps
    • More on functional programming
      • Recursive functions
      • Tail recursion
      • Pattern matching
        • Incomplete pattern matching
        • Using guards
        • Pattern matching in assignment and input parameters
        • Active patterns
      • Introducing generics
      • Lazy evaluation
      • Units of measure
    • Asynchronous and parallel programming
      • Events
      • Background workers
      • Threads
      • Thread pools
      • Asynchronous programming
        • The F# asynchronous workflows
        • Asynchronous binding
        • Examples of using an async workflow
      • Parallel programming using TPL
      • MailboxProcessor
    • A brief look at imperative programming
      • Object-oriented programming
        • Classes
        • Objects and members
        • Methods and properties
        • Overloaded operators
    • Using XML documentation
      • Useful XML tags
      • Typical XML documentation
    • Summary
  • Chapter 3: Financial Mathematics and Numerical Analysis
    • Understanding the number representation
      • Integers
        • Two's complement
      • Floating-point numbers
        • The IEEE 754 floating-point standard
    • Learning about numerical types in F#
    • Arithmetic operators
    • Learning about arithmetic comparisons
    • Math operators
    • Conversion functions
    • Introducing statistics
      • Aggregate statistics
        • Calculating the sum of a sequence
        • Calculating the average of a sequence
        • Calculating the minimum of a sequence
        • Calculating the maximum of a sequence
        • Calculating the variance and standard deviation of a sequence
        • Looking at an example application
    • Using the Math.NET library
      • Installing the Math.NET library
      • Introduction to random number generation
        • Pseudo-random numbers
        • Mersenne Twister
      • Probability distributions
        • Normal distribution
      • Statistics
      • Linear regression
        • Using the least squares method
        • Using polynomial regression
    • Learning about root-finding algorithms
      • The bisection method
        • Looking at an example
      • Finding roots using the Newton–Raphson method
        • Looking at an example
      • Finding roots using the secant method
        • Looking at an example
    • Summary
  • Chapter 4: Getting Started with Data Visualization
    • Making your first GUI in F#
    • Composing interfaces
      • More about agents
      • The user interface
      • The main application
      • Learning about event handling
    • Displaying data
      • Extending the form to use a table
      • Displaying financial data from Yahoo! Finance
      • Understanding the application code
    • Extending the application to use Bollinger bands
    • Using FSharp.Charting
      • Creating a candlestick chart from stock prices
    • Creating a bar chart
    • Summary
  • Chapter 5: Learning Option Pricing
    • Introduction to options
      • Looking into contract specifications
      • European options
      • American options
      • Exotic options
      • Learning about Wiener processes
    • Learning the Black-Scholes formula
      • Implementing Black-Scholes in F#
      • Using Black-Scholes together with charts
      • Introducing the greeks
        • First-order greeks
        • Second-order greeks
      • Implementing the greeks in F#
        • Delta
        • Gamma
        • Vega
        • Theta
        • Rho
        • Investigating the sensitivity of the greeks
        • Code listing for visualizing the four greeks
    • The Monte Carlo method
    • Summary
  • Chapter 6: Exploring Volatility
    • Introduction to volatility
      • Actual volatility
      • Implied volatility
      • Exploring volatility in F#
        • The complete application
    • Learning about implied volatility
      • Solving for implied volatility
    • Delta hedging using Black-Scholes
    • Exploring the volatility smile
    • Summary
  • Chapter 7: Getting Started with Order Types and Market Data
    • Introducing orders
      • Order types
        • Market orders
        • Limit orders
        • Conditional and stop-orders
      • Order properties
    • Understanding order execution
    • Introducing market data
    • Implementing simple pretrade risk analysis
      • Validating orders
    • Introducing FIX and QuickFIX/N
      • Using FIX 4.2
        • Configuring QuickFIX to use the simulator
    • Summary
  • Chapter 8: Setting Up the Trading System Project
    • Explaining automated trading
    • Understanding software testing and test-driven development
    • Understanding NUnit and FsUnit
      • Requirements for the system
      • Setting up the project
      • Installing the NUnit and FsUnit frameworks
    • Connecting to Microsoft SQL Server
    • Introducing type providers
      • Using LINQ and F#
        • Explaining sample code using type providers and LINQ
      • Creating the remaining table for our project
    • Writing test cases
      • Details about the setup
    • Summary
  • Chapter 9: Trading Volatility for Profit
    • Trading the volatility
    • Plotting payoff diagrams with FSharpCharts
    • Learning directional trading strategies
      • Trading volatility using options
        • Trading the straddle
      • Trading the butterfly spread
        • The long butterfly spread
        • The short butterfly spread
      • Trading the VIX
      • Trading the delta neutral portfolio
    • Deriving the mathematics
      • Hedging with implied volatility
      • Implementing the mathematics
    • Learning relative value trading strategies
      • Trading the slope of the smile
    • Defining the trading strategy
      • Case 1 – increasing the slope
      • Case 2 – decreasing the slope
      • Defining the entry rules
      • Defining the exit rules
    • Summary
  • Chapter 10: Putting the Pieces Together
    • Understanding the requirements
    • Revisiting the structure of the system
    • Understanding the Model-View-Controller pattern
      • The model
      • The view
      • The controller
    • Executing the trading strategy using a framework
    • Building the GUI
    • Presenting information in the GUI
    • Adding support for downloading the data
    • Looking at possible additions to the system
      • Improving the data feed
      • Support for backtesting
      • Extending the GUI
      • Converting to the client-server architecture
    • Summary

Johan Astborg

Johan Astborg is the developer and architect of various kinds of software systems and applications, financial software systems, trading systems, as well as mobile and web applications. He is interested in computer science, mathematics, and quantitative finance, with a special focus on functional programming. Johan is passionate about languages such as F#, Clojure, and Haskell, and operating systems such as Linux, Mac OS X, and Windows for his work. 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.

Sorry, we don't have any reviews for this title yet.

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


Errata

- 17 submitted: last submission 05 Feb 2014

Errata Category: Code

On  page no: 110 

Under the Finding roots using the secant method heading:

The last line of the code is:

secant (n + 1) N f x x0

It should be:

secant (n + 1) N f x x0 x2

 

Errata Category: Typo

On page no: 149

Under the Investigating the sensitivity of the greeks heading:

The figure caption is: The surface plot of Delta, Gamma, Theta, and Rho of a call option

It should be this: The surface plot of Delta, Gamma, Theta, and Vega of a call option

 

Errata Category: Code

On page no: 17

Under the Explaining higher-order functions heading:

The following code snippet:

let squareByFour f

f 4

> squareByFour square

Should be:

let squareByFour f =
f 4
squareByFour square

Errata Category: Typo

On page no: 49

The statement: We can check whether s1 contains 9

Should be: We can check whether s1 contains 1

 

Errata Category: Technical

On page no: 40

Under the Interesting functions in an array module heading:

The decription for the Array.zip a b function is Sorts the elements in array a in increasing order, see sortBy to use predicate

It should be: Zips the elements in array a together with elements in b, see zipBy to use predicate

Errata Category: Code

On page: 31

Under the Using functions and values in modules heading: 

In the code snippet:

module Module2 =

let Version() = 

""Version 1.0"

 

Should be

module Module2 =

let Version() = 

"Version 1.0"

Errata Category: Code

On page: 17 and 18

Under the Currying heading:

In the code snippet:

> sumBy2 4;;

val it : int = 5

> sumBy2 5;;

val it : int = 5

Should be:

> sumBy2 4;;

val it : int = 6

> sumBy2 5;;

val it : int = 7

Errata Category: Code

On page: 26

Under The entire program heading:

let filePath = @" table.csv"

Should be:

let filePath = @"table.csv"

Errata Category: Layout

On page: 39

This can be shortened further, for example, if you select the elements 

from the beginning to the element with index 2: array1.[..2] 

This section is the part of the text content and not the part of the code.

Please ignore the incorrect formatting.

Errata Category: Code

On page no: 37

The code snippet:

let toggle1 =
   match x with
   | Buy -> Sell
   | Sell -> Buy

Should be:

let toggle1 x = 
    match x with
    | Buy -> Sell
    | Sell -> Buy
In another code snippet:
Node of tree * tree
Should be:
Node of Tree * Tree

Errata Category: Code

On page no: 38

Under the Enumerations heading:

let col1 : Color = Color.Red

Should be:

let col1 : RGB = RGB.Red

 

Errata Category: Code

On page no: 46

After the paragraph: Minimum and maximum values of a sequence are found by Seq.minand Seq.max, respectively:

In the code snippet:

let seq1 = {1 .. 10}

Should be added.

Errata Category: Code

On page no:47

The following line in the code snippet appears twice:

> Seq.filter (fun elem -> elem > 3) seq1;;

val it : seq<int> = seq [4; 5; 6; 7; ...]

One of them should be removed.

Errata Category: Code

On page no: 57

The following code snippet:

let rec tailrecfact n acc =
match n with
| 0 -> acc
| _ -> trecfact (n - 1) (acc * n)
tailrecfact n 1

Should be:

let rec tailrecfact n acc =
 match n with
 | 0 -> acc
 | _ -> tailrecfact (n - 1) (acc * n)
  tailrecfact n 1

 

Errata Category: Code

On page no: 62

Under the Introducing generics heading:

The code indentation should be:

let genericListMaker<'T>(x, y, z) =
    let list = new List<'T>()
    list.Add(x)
    list.Add(y)
    list.Add(z)
    list

Errata Category: Technical

On page no: 87

As you can see, the range for the 8-bit signed integers is from -128 to -127

Should be: As you can see, the range for the 8-bit signed integers is from -128 to 127

Errata Category: Code

On page no: 96

Under the Calculating variance heading

The line in the code snippet:

let variance(values=

Should be:

let variance values = 

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

F# for Quantitative Finance +    Autodesk AutoCAD 2013 Practical 3D Drafting and Design =
50% Off
the second eBook
Price for both: £26.34

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Use Visual Studio as your main tool for writing F#
  • Utilize F# to aggregate data and calculate statistics
  • Plot and visualize data in F#
  • Learn about volatility, delta hedging, and volatility arbitrage
  • Understand basic numerical analysis and algorithm implementation
  • Model orders and market data together with basic pre-trade risk
  • Structure and write object-oriented code
  • Develop larger programs using F#
  • Explore automated trading systems and quantitative trading models

In Detail

F# is a functional programming language that allows you to write simple code for complex problems. Currently, it is most commonly used in the financial sector. Quantitative finance makes heavy use of mathematics to model various parts of finance in the real world. If you are interested in using F# for your day-to-day work or research in quantitative finance, this book is a must-have.

This book will cover everything you need to know about using functional programming for quantitative finance. Using a functional programming language will enable you to concentrate more on the problem itself rather than implementation details. Tutorials and snippets are summarized into an automated trading system throughout the book.

This book will introduce you to F#, using Visual Studio, and provide examples with functional programming and finance combined. The book also covers topics such as downloading, visualizing and calculating statistics from data.

F# is a first class programming language for the financial domain.

Approach

The approach is to guide you as a reader from the basics of functional programming and F# to more complex tasks using tutorials and a lot of code examples. As you gain more confidence through out the book, you will be able to modify and write your own code to solve various problems in finance.

Who this book is for

If you are a practitioner of quantitative finance, economics, or mathematics and wish to learn F#, then this book is for you. You may have a basic conceptual understanding of financial concepts and models, but no previous knowledge is expected.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software