You are previewing Clojure for Finance.
O'Reilly logo
Clojure for Finance

Book Description

Leverage the power and flexibility of the Clojure language for finance

About This Book

  • Apply the Clojure programming language in financial analytics and to build financial applications

  • Work with high-level mathematical abstractions without having to implement low-level code for financial operations.

  • This is a practical tutorial that takes you through real-world examples of financial analytics and applications with Clojure

  • Who This Book Is For

    If you’re a finance professional who is currently using VBA (Excel) to perform financial calculations and quantitative analysis, and would like to use Clojure instead to improve their efficiency, then this book is for you.

    Basic knowledge of financial concepts is essential. Basic programming knowledge would also be an added advantage.

    What You Will Learn

  • Quickly and effectively represent data and calculations using Clojure

  • Use Clojure’s basic language tools such as laziness, immutability, and firstclass functions to solve real-world problems

  • Explore mathematical derivatives to generate different wave forms

  • Get acquainted with the advanced approaches to calculating and transforming data, and building algorithms

  • Use Clojure's functions to access, update, and compose data structures

  • Be introduced to the concept of sideeffecting behavior and the different ways to handle it

  • Compose simple and exponential functions together to get a buy or sell signal

  • In Detail

    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.

    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.

    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.

    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.

    Style and approach

    This book is a practical step-by-step tutorial that provides a basic overview of the concepts but focuses on providing the skills required to analyze data.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Clojure for Finance
      1. Table of Contents
      2. Clojure for Finance
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        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. Orientation – Addressing the Questions Clojure Answers
        1. Notions of computation
        2. Notions of finance
        3. Concrete types of computation
        4. Tooling
        5. A first look at Clojure's core functions
          1. Primitives
          2. Collections
        6. Summary
      9. 2. First Principles and a Useful Way to Think
        1. Modeling stock price activity
        2. Function evaluation
        3. First-class functions
        4. Lazy evaluation
        5. Basic Clojure functions and immutability
        6. Namespaces and creating our first function
          1. The Read-Eval-Print-Loop
        7. Basic data structures
          1. Macros and more in-depth data transformation
          2. Elaborating our equation
        8. Summary
      10. 3. Developing the Simple Moving Average
        1. Perception and representation
        2. Knowing the data input
        3. Knowing the data output
        4. Reasoning about the equation needed to achieve our output
        5. Understanding Vars and bindings
        6. Working with lazy sequences
        7. Implementing our equation
        8. Destructuring
        9. Summary
      11. 4. Strategies for Calculating and Manipulating Data
        1. Our first refactor – the price list
        2. The exponential moving average
        3. The Bollinger Bands
        4. Summary
      12. 5. Traversing Data, Branching, and Conditional Dispatch
        1. Our second refactor – the generate prices function
        2. Polynomial expressions
        3. A sine wave
        4. Stitching the pieces together
        5. Surveying the function landscape
          1. Traversing data
          2. Branching and conditional dispatch
        6. First order functions
        7. Applying functions
        8. Summary
      13. 6. Surveying the Landscape
        1. Scalar data types
        2. Numbers and precision
        3. A review of collections
        4. Data transformation patterns and principles
        5. Clojure's model of state and identity
        6. Introducing side effects
        7. Concurrency and parallelism
        8. Type systems
        9. Comparing Clojure with object orientation
        10. Comparing Clojure with FP and strong typing
        11. Summary
      14. 7. Dealing with Side Effects
        1. Simple writing
        2. Extensible Data Notation
        3. Devising a persistence strategy
        4. Consuming from a data stream
        5. Using a componentized architecture
        6. Summary
      15. 8. Strategies for Using Macros
        1. Simple reading
        2. Functions for querying a system
          1. An example of a regular expression
          2. A basic lookup
          3. Flattening structures
          4. A more expressive lookup
          5. A simple query language
          6. Variable argument functions
          7. The :pre and :post function conditions
          8. The juxt higher order function
        3. Separate OR AND lookups
        4. Deriving a query language using macros
        5. Summary
      16. 9. Building Algorithms – Strategies to Manipulate and Compose Functions
        1. Structuring our data for further analysis
        2. A third refactor of the analytic functions
        3. Signals using moving averages
        4. The Relative Strength Index
        5. Bollinger Band signals
        6. Summary
      17. Index