C# for Financial Markets
eBook - ePub

C# for Financial Markets

  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

C# for Financial Markets

Book details
Book preview
Table of contents
Citations

About This Book

A practice-oriented guide to using C# to design and program pricing and trading models

In this step-by-step guide to software development for financial analysts, traders, developers and quants, the authors show both novice and experienced practitioners how to develop robust and accurate pricing models and employ them in real environments. Traders will learn how to design and implement applications for curve and surface modeling, fixed income products, hedging strategies, plain and exotic option modeling, interest rate options, structured bonds, unfunded structured products, and more. A unique mix of modern software technology and quantitative finance, this book isboth timely and practical. The approach is thorough and comprehensive and the authors use a combination of C# language features, design patterns, mathematics and finance to produce efficient and maintainable software.

Designed for quant developers, traders and MSc/MFE students, each chapter has numerous exercises and the book is accompanied by a dedicated companion website, www.datasimfinancial.com/forum/viewforum.php?f=196&sid=f30022095850dee48c7db5ff62192b34, providing all source code, alongside audio, support and discussion forums for readers to comment on the code and obtain new versions of the software.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access C# for Financial Markets by Daniel J. Duffy, Andrea Germani in PDF and/or ePUB format, as well as other popular books in Business & Finance. We have over one million books available in our catalogue for you to explore.

Information

Publisher
Wiley
Year
2013
ISBN
9781118502839
Edition
1
Subtopic
Finance
1
Global Overview of the Book
1.1 INTRODUCTION AND OBJECTIVES
The main goal of this book is to show how to design software systems for financial derivatives products using the object-oriented language C#. We have chosen C# for a number of reasons and we would like to explain the rationale behind this choice:
  • C# is relatively easy to learn (certainly when we compare it to C++). This means that it can be learned by traders, quants and other finance professionals who do not necessarily spend all their waking hours designing and implementing software systems. For example, people with a background in VBA will find the transition to C# much easier than the transition from VBA to C++. Furthermore, in many cases developer productivity levels in C# can be four times as high as with C++.
  • The .NET framework and C# offer the developer a range of functionality that he or she can use in financial applications. This is realised by the features in the language itself and by the libraries in the framework. We shall discuss these libraries and we shall also see in the rest of this book how they are used to create robust and flexible applications.
  • It is possible to create interoperable applications that consist of a mixture of C#, C++ and VBA code and that communicate with Excel and real-time data servers. In other words, it is possible to create .NET applications that can communicate with non .NET code and it is also possible to create non .NET applications that can communicate with .NET code.
  • Usability levels are high. Furthermore, developers do not have to worry about manual memory management as this is taken care of by garbage collection mechanisms resident in the .NET framework.
  • C# and the .NET framework contain libraries that allow developers to create multi-threaded applications that run on shared memory multi-core processors.
  • Many .NET libraries have been designed in such a way that they can be used and adapted to suit new developer needs. In particular, it is easy to use and apply design patterns in C# applications.
In this book we discuss each of these topics in detail.
1.2 COMPARING C# AND C++
C# is a descendant of the C programming language (K&R 1988). It is worth pausing for a moment to consider whether it is better (in some sense) to develop new applications in C# and or C++. In order to help the reader determine how to choose between C# and C++, we discuss the problem from three perspectives:
  • P1: The skills and knowledge of those engineers developing applications.
  • P2: The type of application and related customer wishes.
  • P3: The technical and organisational risks involved in choosing a given language.
We discuss each perspective in turn. First, C++ is a huge multi-paradigm language and it supports the modular, object-oriented and generic programming models. It is based on the C language and it would seem that it is the language of choice for many pricing, hedging and risk applications. It is not an easy language to learn. There are many books that discuss C++ and its syntax but there are surprisingly few that discuss how to apply C++ to finance and even to other application domains. C#, on the other hand is a relatively new language and it supports the object-oriented and generic programming models, but not the modular programming model. This implies that everything must be an object or class in C#.
In general, C# is much easier to learn than C++. It shields the developer from many of the low-level details seen in C++, in particular the pointer mechanism, memory management and garbage collection. In short, the C# developer does not have to worry about these details because they are automatically taken care of. This is a mixed blessing because there are situations where we wish to have full control of an object's lifecycle. C++ is a vendor-neutral language (it is an ISO standard) while C# was originally developed by Microsoft for its Windows operating system.
Perspective P2 is concerned with the range of applications to which C++ or C# can be applied, how appropriate C++ and C# are for these applications and how customer wants and needs determine which language will be most suitable in a particular context. In general, customers wish to have applications that perform well, are easy to use and easy to extend. On the issue of performance, C++ tends to be more efficient than C# and tests have shown that in general C++ applications are 20% faster than the corresponding applications in C#. This difference may or may not be a critical factor in determining whether C++ is more suitable than C# in a particular context.
To compare the two languages from the perspective of developer productivity, we first need to define what we are measuring. C# has many libraries that the developer can use, thus enhancing productivity. C++, on the other hand does not have such libraries and they must be purchased as third-party software products. In particular, user-interface software for C# is particularly easy to use while in C++ the developer must use libraries such as MFC, QT or OWL, for example. In general, we conclude that productivity levels are much higher in C# than in C++.
Finally, perspective P3 is concerned with the consequences and risks to the organisation after a choice has been made for a particular language. C++ is a large and difficult language, it takes some time to master and C++ applications tend to be complex and difficult to maintain. However, C++ is an ISO standard.
1.3 USING THIS BOOK
This book represents the joint work of Andrea Germani (trader/quant) and Daniel J. Duffy (numerical analyst/software designer). The focus of this book reflects the backgrounds of the authors and the objectives that they had when they first had the idea in a Milan ristorante all those years ago (or so it seems) to write a practical book that would appeal to traders and to quants who work in the financial markets. The outcome is what you have in your hands. It contains 26 chapters that are logically grouped into major categories dealing with C# syntax, .NET libraries, Excel integration, multi-threading and parallel programming and applications to fixed-income products such as caps, floors, swaps and swaptions that we price and for which we calculate rate sensitivities. We also discuss the pricing of equities using lattice and PDE/finite difference methods. It is clear that this book is not just about C# syntax alone but it is a complete introduction to the design and implementation of C# applications for financial markets. We employ object-oriented, generic and functional programming models to create flexible and efficient software systems for finance professionals. The book has a dedicated forum at www.datasimfinancial.com.
We have provided source code at the above site for all examples and applications that are discussed in the book. We recommend that you review the code, run it and extend it to suit your particular circumstances.
2
C# Fundamentals
2.1 INTRODUCTION AND OBJECTIVES
The goal of this chapter is to introduce the C# language. We concentrate on fundamental issues such as built-in data types, memory management and basic console input and output. Of particular importance is the distinction between value types and reference types, how they are created, compared and finally removed from memory.
Without further ado, we deliver the extremely popular “Hello World” program:
 using System; // Use the System namespace (Console etc.) // HelloWorld class. Every C# program has at least one class public class HelloWorld { // Each Main method must be enclosed in a class // C# programs start in this Main() method public static void Main() { // Write string to console Console.WriteLine("Hello world!"); } } 
In this case we have created a class called HelloWorld containing a method called Main() which is the entry point to the program. We explain this (and more extended) syntax in the rest of this chapter.
We are assuming that the reader has knowledge of programming in some object-oriented language, in particular what classes and objects are, some knowledge of data types and basic exception handling. For those readers with minimal programming experience and who need to learn fundamental C# syntax, please consult a book on C#, for example Albahari 2010. In this chapter we deliver a simple C# class that implements the Black Scholes equation. For an introduction to object-oriented programming, see Appendix 1.
2.2 BACKGROUND TO C#
C# is a modern object-oriented language developed by Microsoft Corporation. Many of the features have their equivalents in other languages such as Java, C++ and C. Those readers who know one or more of these languages should find it easy to learn the fundamental syntax of C# and to start writing small applications in a matter of days or weeks. For C++ developers the transition to C# is relatively painless because the syntax of C++ and C# is similar and we do not have to worry about heap-based memory management in C# because this is taken care of by the garbage collector in the runtime system. For Java developers, the transition to C# is also relatively straightforward, although C# has support for generic classes and interfaces since .NET 2.0 while generics appeared relatively recently in Java and they may not be familiar to all Java developers. Finally, those developers who are familiar with C++ template programming should have little difficulty in learning and applying C# generics.
2.3 VALUE TYPES, REFERENCE TYPES AND MEMORY MANAGEMENT
Our discussion of C# begins with an introduction to memory and its relationship to objects and data. We restrict the scope at the moment to stack and heap memory regions. Briefly, stack memory is fixed and defined at compile-time while heap memory is dynamic and is defined at run-time. In C# we distinguish between two categories of data types. First, a value type variable is created on the stack and it is popped off the stack when it goes out of scope. The variable contains the value. Variables of this type are passed by value (in other words, a copy of the variable is made) and it is copied when it is assigned to other variables. Examples of value types are intrinsic (built-in) types and user-defined structs that we shall discuss in detail in later sections. Second, a reference type variable data is created on the heap. Thus, reference type variables are not copied and it is possible to define several variables that reference the same object in memory. Objects, strings and arrays are reference d...

Table of contents

  1. Cover
  2. Title Page
  3. Copyright
  4. About the Authors
  5. Series
  6. List of Figures
  7. List of Tables
  8. Dedication
  9. Introduction
  10. Chapter 1: Global Overview of the Book
  11. Chapter 2: C# Fundamentals
  12. Chapter 3: Classes in C#
  13. Chapter 4: Classes and C# Advanced Features
  14. Chapter 5: Data Structures and Collections
  15. Chapter 6: Creating User-defined Data Structures
  16. Chapter 7: An Introduction to Bonds and Bond Pricing
  17. Chapter 8: Data Management and Data Lifecycle
  18. Chapter 9: Binomial Method, Design Patterns and Excel Output
  19. Chapter 10: Advanced Lattices and Finite Difference Methods
  20. Chapter 11: Interoperability: Namespaces, Assemblies and C++/CLI
  21. Chapter 12: Bond Pricing: Design, Implementation and Excel Interfacing
  22. Chapter 13: Interpolation Methods in Interest Rate Applications
  23. Chapter 14: Short Term Interest Rate (STIR) Futures and Options
  24. Chapter 15: Single-curve Building
  25. Chapter 16: Multi-curve Building
  26. Chapter 17: Swaption, Cap and Floor
  27. Chapter 18: Software Architectures and Patterns for Pricing Applications
  28. Chapter 19: LINQ (Language Integrated Query) and Fixed Income Applications
  29. Chapter 20: Introduction to C# and Excel Integration
  30. Chapter 21: Excel Automation Add-ins
  31. Chapter 22: C# and Excel Integration COM Add-ins
  32. Chapter 23: Real-time Data (RTD) Server
  33. Chapter 24: Introduction to Multi-threading in C#
  34. Chapter 25: Advanced Multi-threading in C#
  35. Chapter 26: Creating Multi-threaded and Parallel Applications for Computational Finance
  36. Appendix 1: Object-oriented Fundamentals
  37. Appendix 2: Nonlinear Least-squares Minimisation
  38. Appendix 3: The Mathematical Background to the Alternating Direction Explicit (ADE) Method
  39. Appendix 4: Cap, Floor and Swaption Using Excel-DNA
  40. Bibliography
  41. Web References
  42. Index
  43. End User License Agreement