
Foundations of Computational Finance with MATLAB
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Foundations of Computational Finance with MATLAB¯® is an introductory text for both finance professionals looking to branch out from the spreadsheet, and for programmers who wish to learn more about finance. As financial data grows in volume and complexity, its very nature has changed to the extent that traditional financial calculators and spreadsheet programs are simply no longer enough. Today's analysts need more powerful data solutions with more customization and visualization capabilities, and MATLAB provides all of this and more in an easy-to-learn skillset.
This book walks you through the basics, and then shows you how to stretch your new skills to create customized solutions. Part I demonstrates MATLAB's capabilities as they apply to traditional finance concepts, and PART II shows you how to create interactive and reusable code, link with external data sources, communicate graphically, and more.
* Master MATLAB's basic operations including matrices, arrays, and flexible data structures
* Learn how to build your own customized solutions when the built-ins just won't do
* Learn how to handle financial data and industry-specific variables including risk and uncertainty
* Adopt more accurate modeling practices for portfolios, options, time series, and more
MATLAB is an integrated development environment that includes everything you need in one well-designed user interface. Available Toolboxes provide tested algorithms that save you hours of code, and the skills you learn using MATLAB make it easier to learn additional languages if you choose to do so. Financial firms are catching up to universities in MATLAB usage, so this is skill set that will follow you throughout your career. When you're ready to step into the new age of finance, Foundations of Computational Finance with MATLAB provides the expert instruction you need to get started quickly.
More details
Other editions
Additional editions

Person
ED MCCARTHY is a journalist, prolific finance writer, and MathWorks Certified MATLAB® Associate. His articles have appeared in Bloomberg Wealth Manager, CFA Institute Magazine, Institutional Investor, Financial Planning, Journal of Accountancy, and the Journal of Financial Planning. He is also author of The Financial Advisor's Analytical Toolbox and Fast Forward MBA in Personal Finance.
Content
Introduction xiii
Why You Should Read This Book xiii
The Intended Reader xiv
Why MATLAB®? xiv
How to Use This Book xvi
Font Conventions xvi
About the Author xvii
MathWorks Information xviii
References xviii
Part I MATLAB Conventions and Basic Skills 1
Chapter 1 Working with MATLAB® Data 3
1.1 Introduction 3
1.2 Arrays 3
1.2.1 Numerical Arrays 4
1.2.2 Math Calculations with Scalars,Vectors, and Matrices 10
1.2.3 Statistical Calculations on Vectors and Matrices 16
1.2.4 Extracting Values from Numerical Vectors and Matrices 19
1.2.5 Counting Elements 26
1.2.6 Sorting Vectors and Matrices 28
1.2.7 Relational Expressions and Logical Arrays 31
1.2.8 Dealing with NaNs (Not a Number) 35
1.2.9 Dealing with Missing Data 39
1.3 Character Arrays 40
1.3.1 String Arrays 44
1.4 Flexible Data Structures 46
1.4.1 Cell Arrays 47
1.4.2 Structure ("struct") Arrays 49
1.4.3 Tables 51
References 60
Further Reading 60
Chapter 2 Working with Dates and Times 61
2.1 Introduction 61
2.2 Finance Background: Why Dates and Times Matter 61
2.2.1 First Challenge: Day Count Conventions 62
2.2.2 Second Challenge: Date Formats 63
2.3 Dates and Times in MATLAB 64
2.3.1 Datetime Variables 64
2.3.2 Date Conversions 73
2.3.3 Date Generation Functions with Serial Number Outputs 79
2.3.4 Duration Arrays 83
2.3.5 Calendar Duration Variables 86
2.3.6 Date Calculations and Operations 89
2.3.7 Plotting Date Variables Introduction 94
References 95
Chapter 3 Basic Programming with MATLAB® 97
3.1 Introduction 97
3.1.1 Algorithms 101 97
3.1.2 Go DIY or Use Built-In Code? 98
3.2 MATLAB Scripts and Functions 99
3.2.1 Scripts 99
3.2.2 Developing Functions 106
3.2.3 If Statements 112
3.2.4 Modular Programming 115
3.2.5 User Message Formats 121
3.2.6 Testing and Debugging 124
References 127
Chapter 4 Working with Financial Data 129
4.1 Introduction 129
4.2 Accessing Financial Data 129
4.2.1 Closing Prices versus Adjusted Close Prices for Stocks 130
4.2.2 Data Download Examples 131
4.2.3 Importing Data Interactively 133
4.2.4 Automating Data Imports with a Script 138
4.2.5 Automating Data Imports with a Function 140
4.2.6 Importing Data Programmatically 147
4.3 Working with Spreadsheet Data 154
4.3.1 Importing Spreadsheet Data with Import Tool 154
4.3.2 Importing Spreadsheet Data Programmatically 154
4.4 Data Visualization 156
4.4.1 Built-In Plot Functions 156
4.4.2 Using the Plot Tools 158
4.4.3 Plotting with Commands 159
4.4.4 Other Plot Tools 162
4.4.5 Built-In Financial Charts 173
References 176
Part II Financial Calculations with MATLAB 177
Chapter 5 The Time Value of Money 179
5.1 Introduction 179
5.2 Finance Background 180
5.2.1 Future Value with Single Cash Flows 180
5.2.2 Future Value with Multiple Cash Flows 185
5.2.3 Present Value with Single Cash Flows 187
5.2.4 Present Value with Multiple Variable Cash Flows 188
5.3 MATLAB Time Value of Money Functions 189
5.3.1 Future Value of Fixed Periodic Payments 190
5.3.2 Future Value of Variable Payments 191
5.3.3 Present Value of Fixed Payments 193
5.3.4 Present Value of Variable Payments 194
5.4 Internal Rate of Return 197
5.5 Effective Interest Rates 198
5.6 Compound Annual Growth Rate 198
5.7 Continuous Interest 200
5.8 Loans 200
References 202
Chapter 6 Bonds 203
6.1 Introduction 203
6.2 Finance Background 204
6.2.1 Bond Classifications 204
6.2.2 Bond Terminology 205
6.3 MATLAB Bond Functions 206
6.3.1 US Treasury Bills 206
6.3.2 Bond Valuation Principles 208
6.3.3 Calculating Bond Prices 209
6.3.4 Calculating Bond Yields 212
6.3.5 Calculating a Bond's Total Return 214
6.3.6 Pricing Discount Bonds 216
6.4 Bond Analytics 216
6.4.1 Interest Rate Risk 217
6.4.2 Measuring Rate Sensitivity 219
6.4.3 Yield Curves 227
6.5 Callable Bonds 229
References 231
Further Reading 231
Chapter 7 Dealing with Uncertainty and Risk 233
7.1 Introduction 233
7.2 Overview of Financial Risk 234
7.3 Data Insights 234
7.3.1 Visualizing Data 235
7.3.2 Basic Single Series Plots 237
7.3.3 Basic Multiple Series Plots 237
7.3.4 Adding Plot Customization 238
7.3.5 Histograms 239
7.3.6 Measures of Central Location 241
7.3.7 Measures of Data Dispersion 243
7.4 Data Relationships 249
7.4.1 Covariance and Correlation 251
7.4.2 Correlation Coefficients 252
7.5 Creating a Basic Simulation Model 253
7.6 Value at Risk (VaR) 258
References 261
Further Reading 262
Chapter 8 Equity Derivatives 263
8.1 Introduction 263
8.2 Options 264
8.2.1 Option Quotes 265
8.2.2 Market Mechanics 266
8.2.3 Factors in Option Valuation 267
8.3 Option Pricing Models 268
8.3.1 Arbitrage 269
8.3.2 Binomial Option Pricing 270
8.3.3 Black-Scholes 274
8.4 Options' Uses 276
8.4.1 Hedging 277
8.4.2 Speculation and Leverage 277
8.4.3 Customizing Payoff Profiles 278
8.5 Appendix: Other Types of Derivatives 279
8.5.1 Commodity and Energy 279
8.5.2 Credit 279
8.5.3 Exotic Options 280
References 281
Further Reading 281
Chapter 9 Portfolios 283
9.1 Introduction 283
9.2 Finance Background 283
9.3 Portfolio Optimization 285
9.4 MATLAB Portfolio Object 286
9.4.1 Object-Oriented Programming (OOP) 286
9.4.2 A Basic Example 287
9.4.3 Using Data Stored in a Table
Format 294
References 296
Chapter 10 Regression and Time Series 297
10.1 Introduction 297
10.2 Basic Regression 297
10.2.1 Understanding Least Squares 300
10.2.2 Model Notation 301
10.2.3 Fitting a Polynomial with polyfit and polyval 303
10.2.4 Linear Regression Methods 305
10.3 Working with Time Series 308
10.3.1 Step 1: Load the Data (Single Series) 308
10.3.2 Step 2: Create the FTS Object 309
10.3.3 Step 3: Using FTS Tools 311
References 314
Appendix 1 Sharing Your Work 315
A1.1 Introduction 315
A1.2 Publishing a Script 316
A1.2.1 Publishing with Code Sections 317
A1.2.2 futureValueCalc3 319
A1.2.3 Formatting Options 321
A1.2.4 Working with Live Scripts 322
A1.2.5 Editing and Control 325
References 326
Appendix 2 Reference for Included MATLAB® Functions 327
Index 335
Introduction
Why You Should Read This Book
If you're planning a career in corporate or investment finance or already working in one of those areas, you're probably proficient with financial calculators and spreadsheets. Those technologies have proven their value, and it's likely they will remain essential tools for many years. (I still use a 30-year-old Hewlett Packard 12C calculator regularly and it works perfectly, albeit a bit slower than newer models.)
But the nature of data and analytics are changing, and those changes are influencing financial analysis and management. Traditional financial data still drive decisions, but those data are being supplemented by increasing volumes of nontraditional information and new computational tools. Consider these headlines from recent years, which are just a small sample of the articles on these themes:
- "Stop Using Excel, Finance Chiefs Tell Staffs" (Wall Street Journal, 1/22/1017)
- "The Quants Run Wall Street Now" (Wall Street Journal, article series in May 2017)
- "At New Digital Lenders, Math Rules" (New York Times, 1/19/2016)
- "Leveraging Data to Own the Engaged Customer" (Utility Analytics, 11/4/2015)
- "The Morning Ledger: The Rising Profile of Financial Planning and Analysis" (Wall Street Journal, 12/22/2015)
- "How Computers Trawl a Sea of Data for Stock Picks" (Wall Street Journal, 4/1/2015)
- "As Big Data and AI Take Hold, What Will It Take to Be an Effective Executive?" (Wall Street Journal, 1/23/2015)
I believe this paradigm shift requires a new approach to financial analysis and management. Specifically, finance professionals must supplement their calculators and spreadsheets with more flexible and powerful computational platforms. These platforms can work with the new data models while still providing the tools needed for traditional financial analysis. As the headlines suggest, remaining competitive in financial analysis and management will require an understanding of and skill with computational finance. This knowledge will allow you to access data from multiple sources, develop customized financial analytics, and then distribute your tools and findings across a variety of platforms.
The Intended Reader
Transitioning to the new paradigm is a challenge, though, because it means learning about computational finance. Other authors have addressed this topic, but they focused on advanced material for readers who combine extensive math, statistics, programming, and finance backgrounds, such as financial engineers and academics.
In contrast, I wrote this book for readers seeking an introductory text that links traditional finance material to the MATLAB computational platform. This includes upper-level undergraduate finance students, graduate students, finance practitioners, and those with STEM backgrounds seeking to learn about finance. My assumption is that your background will be: (1) A business student or finance professional who is comfortable with finance theory but has modest computer programming experience beyond spreadsheets, or (2) A STEM student or professional who has a more extensive programming background but less experience with finance.
I'm also assuming you have completed first courses in linear algebra and statistics and will have access to MATLAB and the required MATLAB Toolboxes. Many universities have MATLAB licenses, but if you must buy the software, it's very inexpensive for students, and the MATLAB Home edition makes it readily affordable for nonacademic users. (Pricing details are available on the mathworks.com site.)
Why MATLAB®?
That's a fair question, because there are a host of programming languages being used in finance. But there's a question-and-answer dialogue I've seen numerous times on web message boards for quantitative and computational finance that helps answer the question. It goes something like this:
Q. I'm thinking of getting into quantitative finance (or applying to a quant educational program) and need advice on programming languages. Should I start with MATLAB or Python? R or S? C++ or Java?
A. Yes.
The answer is a bit snarky, so the respondent usually explains that learning a programming language is not a one-and-done lifetime proposition. People change employers during their careers and the new employer might emphasize a different language. Computer technologies and programming languages evolve, too, and it's necessary to keep up with those changes, as those of us who started programming with punched cards and card readers can attest.
I have no business affiliation with The MathWorks but I believe the MATLAB software is well-suited for an introduction to computational finance for several reasons:
- It's an integrated development environment that combines a code editor, compiler, debugger, interpreter, and graphics capability in a well-designed graphical user interface.
- It's relatively easy to develop basic MATLAB skills. Of course, it takes time and effort to learn any computer language but the program's consistent syntax usage and extensive documentation improve user productivity.
- The finance-related MATLAB Toolboxes provide access to multiple financial functions running tested algorithms, which can save many programming hours and much frustration. Additional MATLAB Toolboxes can make it easier to move into other areas, such as big data analytics, as well.
- MATLAB is used in numerous financial firms, other industries, and over 5,000 universities. If you're a student, your school probably has a MATLAB license.
- Prices for students and educators have always been low, and several years ago The MathWorks began offering inexpensive personal licenses.
- Users can access multiple training and support channels through general and specialized books, online and live training courses, and formal and informal (community) support resources. I've completed several of the online training programs offered by The MathWorks, and they were very good.
- Finally, I believe the knowledge and skills developed in learning MATLAB make it easier to subsequently learn other programming languages.
How to Use This Book
Part I introduces the MATLAB syntax and how to use the program. If you're new to MATLAB or need a review, start with those chapters. For a deeper introduction, you can supplement that material with the resources online The MathWorks offers, including the no-cost MATLAB Onramp course at matlabacademy.mathworks.com. That course uses an interactive format and takes about two hours to complete. Other online tutorials can be found at www.mathworks.com/support/learn-with-matlab-tutorials.html. If you have the time and funds, the MATLAB Fundamentals course is an excellent in-depth introduction.
Part II demonstrates how MATLAB can be used as a computational platform in finance. The material in Chapter 5, "The Time Value of Money," has general applications throughout the remaining chapters, so I suggest reviewing that material. The text reviews the underlying finance material being discussed in each chapter and includes suggestions for further reading.
Finally, practice using the program interactively or programmatically by entering commands in the MATLAB Command window as you work through the examples. Learning to use software is somewhat like learning to drive. Reading a book on safe driving gives you an intellectual perspective but it makes driving sound deceptively easy. Coding-like getting behind the steering wheel and pulling into high-speed traffic for the first time-is best experienced hands-on. Fortunately, writing code is a lot less nerve-wracking than highway driving.
Font Conventions
The book uses several different font styles to help you distinguish the material:
Bold: Function names, reserved keywords, matrices, and vectors
Monospaced italic: Command window inputs. Example:
x = 7 Monospaced: MATLAB output and responses. Example:
x = 7 Monospaced starting with %: Code comment lines that do not execute
Normally spaced lines starting with %: Text comments
About the Author
I have worked as a freelance finance writer since the mid-1980s, and during that time I have written for many of the financial service industry's leading publications. These include Bloomberg Wealth Manager, CFA Institute Magazine, Institutional Investor online, Financial Planning, Journal of Accountancy, and the Journal of Financial Planning. Earlier in my career I published a technology book for financial advisors, The Financial Advisor's Analytical Toolbox (Irwin), and one for consumers, Fast Forward MBA in Personal Finance (Wiley). I have also written numerous print and web articles for custom publishers and many of the largest U.S. and international financial services firms. My primary experience as a writer and the focus for many of my articles has been explaining complex finance topics and technologies to readers.
My first exposure to MATLAB was in the mid-1990s when I was doing research for my first book, which included a discussion of the software's financial modeling capabilities. My use of the program intensified while I was...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.