Book Image

Clojure for Finance

By : Timothy Washington
Book Image

Clojure for Finance

By: Timothy Washington

Overview of this book

<p>Clojure is a dynamic programming language with an emphasis on functional programming. Clojure is well suited to financial modeling as it is a functional programming language. Such languages help developers work with high-level mathematical abstractions without having to implement low-level code that handles the arithmetic operations.</p> <p>Starting with the importance of representing data and calculations effectively, this book will take you all the way to being competent in financial analytics and building financial applications.</p> <p>First, we introduce the notions of computation and finance, which will help you understand Clojure's utility to solve real-world problems in many domains, especially finance. Next, we will show you how to develop the simple-moving-average function by using the more advanced partition Clojure data transformation function. This function, along with others, will be used to calculate and manipulate data.</p> <p>You will then learn to implement slightly more complicated equations, how to traverse data, and deal with branching and conditional dispatch. Then, the concept of side-effecting and its various approaches are introduced, along with the strategy of how to use data as the interface to other systems. Finally, you will discover how to build algorithms while manipulating and composing functions.</p>
Table of Contents (16 chapters)
Clojure for Finance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Surveying the function landscape


In order to accomplish everything we've spoken about so far, let's take a step back and explore some functions to traverse data, branching, and conditional dispatch, and other first order functions. The Clojure cheatsheet is a good location for a bird's-eye view of different categories of functions. Their official documentation can be found at http://clojure.org/cheatsheet.

Traversing data

Recursion in computer science is a technique where a function continuously calls itself until some decision point is reached (you can read more about this technique at https://en.wikipedia.org/wiki/Recursion_(computer_science)). This is useful when the same block of code needs to be run against successive or iterative contexts.

The reduce function is used when we have a finite list that we need to collect or fold up into a result value.

Clojure also has the repeatedly function, which continuously calls a function with no arguments. There's also iterate, which is a single argument...