Book Image

F# for Quantitative Finance

By : Johan Astborg
Book Image

F# for Quantitative Finance

By: Johan Astborg

Overview of this book

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 (17 chapters)
F# for Quantitative Finance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding F# Interactive


F# Interactive is a way of executing parts of a program interactively. Doing this enables you as a programmer to explore parts of the code and how it behaves. You will have a more dynamic feel for writing code. It's also more fun. F# Interactive is a REPL for F#. This means, it will read the code, evaluate it, and then print out the result. It will then do this over and over again. It's much like a command line, where the code is executed and the result is displayed to the user.

To execute a code in F# Interactive, have a look at the following steps:

  1. Select the source code you are interested in and press Alt + Enter.

  2. You can write a simple line of code that will just print a string to the REPL's output window:

    printfn "Hello World, from F"
  3. It's also possible to right-click on the selected code and choose Execute In Interactive.

    When executing the code using the Interactive mode, the result is shown in the F# Interactive Evaluation window below the code editor. It is also possible, and sometimes preferable to enter snippets into the Interactive window like the following example illustrates.

  4. Enter the following line in the F# Interactive window and press Enter:

    printfn "Hello World, from F#";;
  5. This will be evaluated to the following in the REPL:

    > printfn "Hello World, from F#";;
    Hello World, from F#
    val it : unit = ()

    Using double semicolons (;;) after the line will terminate the input and enable you to just hit the Enter key, they are required if you type directly into the terminal window.

  6. If you want to cancel the evaluation, it's possible to right-click on and then select Cancel Interactive Evaluation, or simply press Ctrl + Break.