Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo
F# for Quantitative Finance

Book Description

An introductory guide to utilizing F# for quantitative finance leveraging the .NET platform

  • 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#

  • 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.

    Table of Contents

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