All New Wilmott Jobs Board                     (g)

C# in Financial Markets What are the Advantages, the Trading Perspective?

C# in Financial Markets What are the Advantages, the Trading Perspective?

Andrea Germani, Daniel J. Duffy March 2013

In this blog the authors discuss some of the advantages of C# in computational finance from the perspective of the application developer and trader. As a language, it offers the user-friendliness of VBA and Excel integration on the one hand and the efficiency and object-oriented features of C++ on the other hand. This – together with .NET libraries – suggest that developer productivity levels will be high and that you can write efficient and robust code. These conclusions have been borne out in practical applications. We now discuss some of the features in C# and in the .NET Framework that support our claims. To this end, we base our discussion on the ISO 9126 standard that is a classification consisting of orthogonal characteristics that describe the quality of software products. In this case we discuss how these characteristics are realised in C#.

. Functionality: this is the capability to satisfy user needs. The .NET Framework is suitable for a wide range of applications due to its support for OOP and generic programming models. The .NET libraries have native support for containers, data classes for database (ADO.NET) and XML interoperability as well as LINQ (Language Integrated Query) that allows the developer to perform SQL-like queries on in-memory data structures. The framework is secure because all memory management is taken care of by the garbage collector. This last feature has the advantage that the developer does not have to worry about memory leaks, dangling pointers and other scary things.

. Interoperability: this subcharacteristic of Functionality is concerned with the ability of a system to interact with other (predefined) software. The .NET Framework supports a multi-language programming model. This means that you can use a number of languages (such as C#, VB.NET and F#) in a given program and compile them into a single executable file. It is also very easy to create Excel worksheet and COM add ins in C#. Finally, interoperability with native C++ code is also possible in combination with Microsoft’s Managed C++ compiled. In other words, we can wrap existing C++ legacy code in the .NET development environment. In one sense, we can say that C# is a one-stop shop.

. Reliability: this is the capability that a system maintains a given level of performance over a given period of time. In the current case we say that .NET uses managed code which entails that access to resources is organised by the Common Language Runtime (CLR). In particular, the CLR has a garbage collector that executes as part of your program, reclaiming memory for objects that are no longer referenced. Furthermore, C# is a type-safe language. This means that instances (objects) of types can interact only through protocols that they define. In other words, there is no danger of comparing apples and oranges as it were.

. Usability: this characteristic refers to the effort that is needed in order to use (as developer) a software system. C++ and Java developers tend to find C# easy to learn. Typically, you can become competent in the language within weeks. Of course, learning how to use the .NET libraries take some time. The use of Intellisense speeds up the development process.

. Efficiency: this characteristic refers to the level of performance and the amount of resources that are needed in order to achieve the performance. C# code can be compiled to native code and the just-in-time compiler (JIT) ensures that the code is fast. Furthermore, C# supports multithreading and .NET has the Task Parallel Library (TPL) that can improve the speedup of code that is amenable to parallelisation. The perennial discussion on whether C# is faster than C++ is not the central issue in our opinion.

. Maintainability: refers to the effort that is needed to make specific modifications to code in the system. Once a software system has started to gain a foothold with users you will find that the stability, testability and analysability of the code base become more important. The OOP and GP – if applied in an appropriate fashion – promote the maintainability of your code.

Conclusions We have found that C# and the .NET Framework to be a suitable development environment for finance. They offer tools and libraries that provide the optimal mix of number crunching ability (similar to C and C++), libraries for data processing and Excel interoperability (similar to VBA), resulting in measurable advantages for front office productivity.

Summary of Advantages of C# and the .NET Framework

1) Many native .NET classes, for example containers.

2) Advanced libraries, for example LINQ, multithreading and ADO.NET.

3) Easy to interface to MS Office, in particular Excel.

4) East Web and database connection.

5) No memory management issues.

6) You delegate to MS developers who create and optimise new classes for us.

7) One-stop shop; major advances in developer productivity levels.

8) A suitable development environment for computational finance and trading applications.

We discuss C# and its applications to computational finance in the recently published book “C# for Financial Markets” by Daniel J. Duffy and Andrea Germani. Published by John Wiley and Sons Chichester 2013.

Web site

http://www.datasimfinancial.com/forum/viewforum.php?f=196&sid=71dedd579d000d4c807a505c0763c6a2

Which C++ Book is Applicable

It is important at this stage for me to put on record that my first C++ book (2004) is for those who already know C++ while the new one (2006) (you can see it in the Wilmott bestseller list) is for those who have not (necessarily knowedge of C++ (also no C assumed). I would hope that the latter is a A-Z. The 2 books complement each other.

This is an important distinction and potenial readers should be aware of this.

These books are in the Wilmott bookshop.

Comparing the Object-Oriented Paradigm and the Generic Paradigm for QF Applications

C++ is one of the most popular languages for the development of software systems for Quantitative Finance. It is more than 25 years old and it supports the modular, object-oriented paradigm (OOP) and the generic paradigm (GP) in the form of C++ template functions and classes. Most developers are familiar with OOP but a smaller percentage of these developers use C++ templates to design and implement efficient, portable and robust software. There are a number of reasons for this situation some of which are that the syntax of C++ templating can be difficult to understand and second the idea of designing software components using C++ has not been given full justice in the literature. Using templates to design components is similar to how hardware is designed. For example, think about the hardware ports on your laptop; it provides services to other hardware entities and it requires services from other hardware entities. In a similar vein, we are designing the Monte Carlo engine based on similar principles; it consists of a number of plug and socket components. For example, an SDE component provides a set of interfaces for defining and accessing the mathematical description of a stochastic differential equation. It requires data and parameters from a GUI screen, database system and real-time data feed systems. Continuing, a component ‘FDM’ that approximates the solution of a stochastic differential equation requires the services from SDE and provides services such as discrete paths and other statistics to other components, for example an Excel application. In this sense we build large applications using interoperable building blocks. This idea is called policy-based design using C++ templates.

Comparing C# and C++: which one should I go for in QF?

C# - as well as other object-oriented languages such as C++ – is a descendent of the C programming language (K&R 1988). It is worthwhile to pause and consider whether it is better (in some sense) to develop new applications in C# or C++ (incidentally, it is possible to create .NET applications using a combination of C# and C++ but this topic is outside of the current ‘blog’). 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 QF applications P2: The type of application and related customer wishes P3: The technical, organizational risks involved when we choose 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; we liken it to a beast that must be tamed and cajoled. Furthermore, even though there are many books that discuss C++ and its syntax there are surprisingly very few books that discuss how to apply C++ to QF. To this end, one of the authors (Daniel J. Duffy) has written two books that fill this gap (see Duffy 2004, Duffy 2006). 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# which may not be to everyone’s liking. Not everything is, or needs to be an object. In general, C# is much easier to learn than C++. It shields the developer from many of the low-level syntax that we see in C++, in particular the dreaded 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 by the garbage collector. This is a mixed blessing in general because there are situations where we wish to have full control of an object’s lifecycle. It is surprising to us that C++ is not in more widespread use in the universities and places of learning given the fact that many of the investment banks in the City, Wall Street and other financial centres throughout the world may explicitly ask for C++ experience from potential employees. C++ is a vendor-neutral language (it is an ISO standard) while C# was originally developed by Microsoft for its Windows operating system. We now discuss perspective P2. This perspective is concerned with the range of applications that C++ or C# can be applied to, how appropriate they are to 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 C++ applications are 20% faster than the corresponding applications in C# in general. This difference may or may not be a critical factor in determining whether C++ is more suitable than C# in a particular context. We now compare the two languages from the perspective of developer productivity. In order to answer this question we 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 or OWL, for example. In general, we conclude that productivity levels are much higher in C# than in C++. In some cases we have seen a three-fold productivity gain, all things being taken into account. Finally, perspective P3 is concerned with the consequences and risks to the organization 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. By the way, this latter problem is not the fault of C++ but it is caused by bottom-up programming mentality and a premature implementation before a proper design was carried out. On the other hand, C++ will be with us forever and this implies that C++ code that works now will still function in 20 years time. With C# the situation is different. It is restricted to the Windows platform (in principle) and it may be superseded by some other language in the future. Of course, it may evolve into a language that will be embraced by both Linux and Windows programmers alike. Time will tell.

Introduction to C++ for Quants

This book will hopefully fill the gap with my first C++ where I assumed that the reader already had knowledge of C++.

This book introduces the reader to the C++ programming language and how to use it to write applications in quantitative finance (QF) and related areas. No previous knowledge of C or C++ is required. - experience with VBA, Matlab or other programming language is sufficient. The book adopts an incremental approach; starting from basic principles then moving on to advanced complex techniques and then to real-life applications in financial engineering. There are five major parts in the book:

C++ fundamentals and object-oriented thinking in QF Advanced object-oriented features such as inheritance and polymorphism Template programming and the Standard Template Library (STL) An introduction to GOF design patterns and their applications in QF Applications

The kinds of applications include binomial and trinomial methods, Monte Carlo simulation, advanced trees, partial differential equations and finite difference methods.

This book contains a CD with all source code and many useful C++ classes that you can use in your own applications. Examples, test cases and applications are directly relevant to QF.

This book is acompanion to Daniel J. Duffy’s book Financial Instrument Pricing using C++ (Wiley 2004, 0470855096)