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

Getting started with Visual Studio


We will start by introducing Visual Studio as the main tool of choice for this book. Although it's possible to use the standalone F# compiler and your favorite editor, you will most likely be more productive using Visual Studio 2012, as we will do throughout this book.

F# has been a part of Visual Studio since 2010. We will use the latest version of Visual Studio and F# throughout this book. This will enable us to use the latest functionality and enhancements available in Visual Studio 2012 and F# 3.0.

F# is open source, which means you can use it on any supported platform; it's not bound to Microsoft or Visual Studio. There is good support in other IDEs, such as MonoDevelop, which will run on Linux and Mac OS X.

Note

For more information about F# and the F# Software Foundation, visit http://fsharp.org.

Creating a new F# project

Create a new project in Visual Studio for F#, which is to be used in this guide to explore the basics, as shown in the following sections.

Creating a new project in Visual Studio

Using the following steps, we can create a new project in Visual Studio:

  1. To create your first F# project, open Visual Studio 12 and navigate to File | New | Project, then, from the menu select New Project.

  2. Now you will see the New Project window appear. Select F# in the left panel and then select F# Application. You can name it anything you like. Finally, click on OK.

  3. Now you have created your first F# application, which will just print the arguments passed to it.

Understanding the program template

Let's have a brief look at the program template generated by Visual Studio.

If you run this program, which will just print out the arguments passed to it, you will see a terminal window appear.

The [<EntryPoint>] function in the preceding screenshot is the main function, which tells Visual Studio to use that particular function as the entry point for the program executable. We will not dig any deeper into this program template for now, but we will come back to this in the last three chapters when we'll build the trading system.

Adding an F# script file

We will use an F# script file after having looked at the standard program template instead of exploring the basics of the language in a more interactive fashion. You can think of F# script files as notebooks, where you have executable code that you can explore in pieces in an incremental style:

  1. Add the F# script file by right-clicking on the Solution Explorer to the right of the code editor.

  2. Then navigate to Add | New Item…, as shown in the following screenshot:

  3. You can name the script file anything you like, such as GettingStarted.fsx.

Now that we have set up the basic project structure in Visual Studio, let's continue and explore F# Interactive.