C# for Financial Markets
Buy Rights Online Buy Rights

Rights Contact Login For More Details

  • Wiley

More About This Title C# for Financial Markets

English

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 is both 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, http://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.

English

Daniel J. Duffy has been working with numerical methods in finance, industry and engineering since 1979. He has written four books on financial models and numerical methods and C++ for computational finance and he has also developed a number of new schemes for this field. He is the founder of Datasim Education and has a PhD in Numerical Analysis from Trinity College, Dublin.

Andrea Germani was born in Lodi, Italy in 1975, where he currently lives. After graduating from the Bocconi University in Milano, he obtained the Certificate in Quantitative Finance in London under the supervision of Paul Wilmott. Since then he has been working as a trader in some of the major Italian banks, where he gained a deep knowledge of the financial markets. He also worked on valuation and pricing of equity and interest-derivatives, with a focus on the practical use of the models on the trading floor. He is active in training courses of Finance for students and practitioners.

English

List of Figures xxi

List of Tables xxv

Introduction 1

0.1 What Is This Book? 1

0.2 Special Features in This Book 1

0.3 Who Is This Book for and What Do You Learn? 2

0.4 Structure of This Book 2

0.5 C# Source Code 3

1 Global Overview of the Book 5

1.1 Introduction and Objectives 5

1.2 Comparing C# and C++ 5

1.3 Using This Book 6

2 C# Fundamentals 9

2.1 Introduction and Objectives 9

2.2 Background to C# 9

2.3 Value Types, Reference Types and Memory Management 10

2.4 Built-in Data Types in C# 10

2.5 Character and String Types 12

2.6 Operators 13

2.7 Console Input and Output 14

2.8 User-defined Structs 15

2.9 Mini Application: Option Pricing 16

2.10 Summary and Conclusions 21

2.11 Exercises and Projects 22

3 Classes in C# 25

3.1 Introduction and Objectives 25

3.2 The Structure of a Class: Methods and Data 25

3.3 The Keyword ‘this’ 28

3.4 Properties 28

3.5 Class Variables and Class Methods 30

3.6 Creating and Using Objects in C# 33

3.7 Example: European Option Price and Sensitivities 33

3.8 Enumeration Types 40

3.9 Extension Methods 42

3.10 An Introduction to Inheritance in C# 44

3.11 Example: Two-factor Payoff Hierarchies and Interfaces 46

3.12 Exception Handling 50

3.13 Summary and Conclusions 50

3.14 Exercises and Projects 51

4 Classes and C# Advanced Features 53

4.1 Introduction and Objectives 53

4.2 Interfaces 53

4.3 Using Interfaces: Vasicek and Cox-Ingersoll-Ross (CIR) Bond and Option Pricing 54

4.4 Interfaces in .NET and Some Advanced Features 61

4.5 Combining Interfaces, Inheritance and Composition 67

4.6 Introduction to Delegates and Lambda Functions 72

4.7 Lambda Functions and Anonymous Methods 76

4.8 Other Features in C# 77

4.9 Advanced .NET Delegates 80

4.10 The Standard Event Pattern in .NET and the Observer Pattern 87

4.11 Summary and Conclusions 91

4.12 Exercises and Projects 92

5 Data Structures and Collections 97

5.1 Introduction and Objectives 97

5.2 Arrays 97

5.3 Dates, Times and Time Zones 101

5.4 Enumeration and Iterators 105

5.5 Object-based Collections and Standard Collection Interfaces 107

5.6 The List Class 109

5.7 The Hashtable Class 110

5.8 The Dictionary<Key, Value> Class 111

5.9 The HashSet Classes 112

5.10 BitArray: Dynamically Sized Boolean Lists 114

5.11 Other Data Structures 114

5.12 Strings and StringBuilder 117

5.13 Some new Features in .NET 4.0 120

5.14 Summary and Conclusions 123

5.15 Exercises and Projects 123

6 Creating User-defined Data Structures 125

6.1 Introduction and Objectives 125

6.2 Design Rationale and General Guidelines 125

6.3 Arrays and Matrices 131

6.4 Vectors and Numeric Matrices 135

6.5 Higher-dimensional Structures 139

6.6 Sets 140

6.7 Associative Arrays and Matrices 142

6.8 Standardisation: Interfaces and Constraints 145

6.9 Using Associative Arrays and Matrices to Model Lookup Tables 152

6.10 Tuples 155

6.11 Summary and Conclusions 156

6.12 Exercises and Projects 156

7 An Introduction to Bonds and Bond Pricing 159

7.1 Introduction and Objectives 159

7.2 Embedded Optionality 160

7.3 The Time Value of Money: Fundamentals 160

7.4 Measuring Yield 166

7.5 Macauley Duration and Convexity 167

7.6 Dates and Date Schedulers for Fixed Income Applications 168

7.7 Exporting Schedulers to Excel 176

7.8 Other Examples 177

7.9 Pricing Bonds: An Extended Design 178

7.10 Summary and Conclusions 181

7.11 Exercises and Projects 181

8 Data Management and Data Lifecycle 185

8.1 Introduction and Objectives 185

8.2 Data Lifecycle in Trading Applications 185

8.3 An Introduction to Streams and I/O 186

8.4 File and Directory Classes 195

8.5 Serialisation Engines in .NET 199

8.6 The Binary Serialiser 203

8.7 XML Serialisation 204

8.8 Data Lifetime Management in Financial and Trading Applications 209

8.9 Summary and Conclusions 213

8.10 Exercises and Projects 213

9 Binomial Method, Design Patterns and Excel Output 215

9.1 Introduction and Objectives 215

9.2 Design of Binomial Method 216

9.3 Design Patterns and Classes 217

9.4 Early Exercise Features 232

9.5 Computing Hedge Sensitivities 233

9.6 Multi-dimensional Binomial Method 233

9.7 Improving Performance Using Pad´e Rational Approximants 236

9.8 Summary and Conclusions 238

9.9 Projects and Exercises 238

10 Advanced Lattices and Finite Difference Methods 241

10.1 Introduction and Objectives 241

10.2 Trinomial Model of the Asset Price and Its C# Implementation 241

10.3 Stability and Convergence of the Trinomial Method 246

10.4 The Black-Scholes Partial Differential Equation and Explicit Schemes 246

10.5 Implementing Explicit Schemes in C# 247

10.6 Stability of the Explicit Finite Difference Scheme 252

10.7 An Introduction to the Alternating Direction Explicit Method (ADE) 255

10.8 Implementing ADE for the Black-Scholes PDE 258

10.9 Testing the ADE Method 262

10.10 Advantages of the ADE Method 263

10.11 Summary and Conclusions 263

10.12 Appendix: ADE Numerical Experiments 263

10.13 Exercises and Projects 268

11 Interoperability: Namespaces, Assemblies and C++/CLI 271

11.1 Introduction and Objectives 271

11.2 Namespaces 271

11.3 An Introduction to Assemblies 273

11.4 Reflection and Metadata 276

11.5 C# and Native C++ Interoperability: How Is That Possible? 289

11.6 Using C# from C++ 293

11.7 Code Generation Using the Reflection API 298

11.8 Application Domains 304

11.9 Summary and Conclusions 309

11.10 Exercises and Projects 309

12 Bond Pricing: Design, Implementation and Excel Interfacing 311

12.1 Introduction and Objectives 311

12.2 High-level Design of Bond Pricing Problem 311

12.3 Bond Scheduling 312

12.4 Bond Functionality and Class Hierarchies 313

12.5 Calculating Price, Yield and Discount Factors: MathTools 317

12.6 Data Presentation and Excel Interop 319

12.7 Bond Data Management 321

12.8 Using the Excel Files 324

12.9 Summary and Conclusions 328

12.10 Exercises and Projects 328

13 Interpolation Methods in Interest Rate Applications 335

13.1 Introduction and Objectives 335

13.2 Interpolation and Curve Building: Basic Formula for Interpolator Tests 335

13.3 Types of Curve Shape 337

13.4 An Overview of Interpolators 338

13.5 Background to Interpolation 339

13.6 Approximation of Function Derivatives 341

13.7 Linear and Cubic Spline Interpolation 342

13.8 Positivity-preserving Cubic Interpolations: Dougherty/Hyman and Hussein 344

13.9 The Akima Method 348

13.10 Hagan-West Approach 349

13.11 Global Interpolation 350

13.12 Bilinear Interpolation 352

13.13 Some General Guidelines, Hints and Tips 355

13.14 Using the Interpolators and Test Examples 357

13.15 Summary and Conclusions 367

13.16 Exercises and Projects 367

14 Short Term Interest Rate (STIR) Futures and Options 369

14.1 Introduction and Objectives 369

14.2 An Overview of Cash Money Markets 370

14.3 Sources of Risk in Money Market Transactions 370

14.4 Reference Rate and Fixings 371

14.5 STIR Futures 371

14.6 Pricing STIR Options 374

14.7 Generating International Monetary Market (IMM) Dates 378

14.8 List STIR Futures and STIR Futures Options 384

14.9 Putting It All Together: STIR versus OTC from a Trader’s Perspective 387

14.10 Summary and Conclusions 389

14.11 Exercises and Projects 389

15 Single-curve Building 393

15.1 Introduction and Objectives 393

15.2 Starting Definitions and Overview of Curve Building Process 393

15.3 Building Blocks 395

15.4 Introduction to Interest Rate Swap 397

15.5 The Curve Construction Mechanism 403

15.6 Code Design and Implementation 406

15.7 Console Examples 418

15.8 Summary and Conclusions 426

15.9 Exercises and Projects 427

15.10 Appendix: Types of Swaps 429

16 Multi-curve Building 431

16.1 Introduction and Objectives 431

16.2 The Consequences of the Crisis on Interest Rate Derivatives Valuation 431

16.3 Impact of Using OIS Discounting 436

16.4 The Bootstrapping Process Using Two Curves: Description of the Mechanism 437

16.5 Sensitivities 438

16.6 How to Organise the Code: A Possible Solution 439

16.7 Putting it Together, Working Examples 445

16.8 Summary and Conclusions 453

16.9 Exercises and Projects 453

16.10 Appendix: Par Asset Swap Spread and Zero Volatility Spread 455

17 Swaption, Cap and Floor 459

17.1 Introduction and Objectives: A Closed Formula World 459

17.2 Description of Instruments and Formulae 459

17.3 Multi-curve Framework on Cap, Floor and Swaption 467

17.4 Bootstrapping Volatility for Cap and Floor 469

17.5 How to Organise the Code in C#: A Possible Solution 474

17.6 Console and Excel Working Examples 481

17.7 Summary and Conclusions 490

17.8 Exercise and Discussion 491

18 Software Architectures and Patterns for Pricing Applications 493

18.1 Introduction and Objectives 493

18.2 An Overview of the GOF Pattern 494

18.3 Creational Patterns 496

18.4 Builder Pattern 496

18.5 Structural Patterns 499

18.6 Behavioural Patterns 500

18.7 Builder Application Example: Calibration Algorithms for Cap and Floor 502

18.8 A PDE/FDM Patterns-based Framework for Equity Options 504

18.9 Using Delegates to Implement Behavioural Design Patterns 509

18.10 A System Design for Monte Carlo Applications 510

18.11 Dynamic Programming in .NET 513

18.12 Summary and Conclusions 516

18.13 Exercises and Projects 517

19 LINQ (Language Integrated Query) and Fixed Income Applications 523

19.1 Introduction and Objectives 523

19.2 Scope of Chapter and Prerequisites 523

19.3 LINQ Query Operators 524

19.4 LINQ Queries and Initial Examples 526

19.5 Advanced Queries 531

19.6 A Numerical Example 533

19.7 Join and GroupJoin 535

19.8 Examples in Fixed Income Applications 540

19.9 LINQ and Excel Interoperability 549

19.10 Summary and Conclusions 557

19.11 Exercises and Projects 557

20 Introduction to C# and Excel Integration 561

20.1 Introduction and Objectives 561

20.2 Excel Object Model 561

20.3 Using COM Technology in .NET 561

20.4 Primary Interop Assemblies (PIA) 563

20.5 Standalone Applications 564

20.6 Types of Excel Add-ins 566

20.7 The IDTExtensibility2 Interface and COM/.NET Interoperability 569

20.8 Data Visualisation in Excel 570

20.9 Conclusion and Summary 578

20.10 Exercises and Projects 579

21 Excel Automation Add-ins 581

21.1 Introduction and Objectives 581

21.2 COM Overview 581

21.3 Creating Automation Add-ins: The Steps 583

21.4 Example: Creating a Calculator, Version 1 585

21.5 Example: Creating a Calculator, Version 2 588

21.6 Versioning 590

21.7 Working with Ranges 590

21.8 Volatile Methods 590

21.9 Optional Parameters 591

21.10 Using VBA with Automation Add-ins 592

21.11 Summary and Conclusions 593

21.12 Exercises and Projects 594

22 C# and Excel Integration COM Add-ins 595

22.1 Introduction and Objectives 595

22.2 Preparations for COM Add-ins 595

22.3 The Interface IDTExtensibility2 596

22.4 Creating COM Add-ins: The Steps 596

22.5 Utility Code and Classes 597

22.6 Using Windows Forms 600

22.7 Example: Creating a COM Add-in 601

22.8 Debugging and Troubleshooting 603

22.9 An Introduction to Excel-DNA 603

22.10 Excel COM Interoperability and Rate Multi-curve 615

22.11 Conclusion and Summary 622

22.12 Exercises and Projects 622

23 Real-time Data (RTD) Server 625

23.1 Introduction and Objectives 625

23.2 Real-time Data in Excel: Overview 625

23.3 Real-time Data Function 626

23.4 Example 627

23.5 The Topic Class and Data 629

23.6 Creating an RTD Server 631

23.7 Using the RTD Server 631

23.8 Testing and Troubleshooting the RTD Server 632

23.9 Conclusion and Summary 632

23.10 Exercises and Projects 632

24 Introduction to Multi-threading in C# 635

24.1 Introduction and Objectives 635

24.2 Processes 636

24.3 Using ProcessStartInfo to Redirect Process I/O 637

24.4 An Introduction to Threads in C# 638

24.5 Passing Data to a Thread and between Threads 641

24.6 Thread States and Thread Lifecycle 644

24.7 Thread Priority 650

24.8 Thread Pooling 651

24.9 Atomic Operations and the Interlocked Class 652

24.10 Exception Handling 653

24.11 Multi-threaded Data Structures 654

24.12 A Simple Example of Traditional Multi-threading 659

24.13 Summary and Conclusions 661

24.14 Exercises and Projects 661

25 Advanced Multi-threading in C# 665

25.1 Introduction and Objectives 665

25.2 Thread Safety 666

25.3 Locking Mechanisms for Objects and Classes 667

25.4 Mutex and Semaphore 673

25.5 Notification and Signalling 676

25.6 Asynchronous Delegates 679

25.7 Synchronising Collections 681

25.8 Timers 682

25.9 Foreground and Background Threads 684

25.10 Executing Operations on Separate Threads: the BackgroundWorker Class 685

25.11 Parallel Programming in .NET 687

25.12 Task Parallel Library (TPL) 691

25.13 Concurrent Data Structures 694

25.14 Exception Handling 701

25.15 Shifting Curves 702

25.16 Summary and Conclusions 704

25.17 Exercises and Projects 704

26 Creating Multi-threaded and Parallel Applications for Computational Finance 707

26.1 Introduction and Objectives 707

26.2 Multi-threaded and Parallel Applications for Computational Finance 707

26.3 Fork and Join Pattern 709

26.4 Geometric Decomposition 711

26.5 Shared Data and Reader/Writer Locks: Multiple Readers and Multiple Writers 715

26.6 Monte Carlo Option Pricing and the Producer–Consumer Pattern 719

26.7 The StopWatch Class 726

26.8 Garbage Collection and Disposal 727

26.9 Summary and Conclusions 730

26.10 Exercises and Projects 730

A1 Object-oriented Fundamentals 735

A2 Nonlinear Least-squares Minimisation 751

A3 The Mathematical Background to the Alternating Direction Explicit (ADE) Method 765

A4 Cap, Floor and Swaption Using Excel-DNA 789

Bibliography 805

Web References 812

Index 815

loading