Using Excel and VBA SECOND EDITION CHANDAN SENGUPTA WILEY John Wiley & Sons, Inc.
Contents About This Book CHAPTER 1 Introduction to Hnancial Analysis and Modeling 1 Steps in Creating a Model 5 How This Book Is Organized 9 xix Part One Excel for Financial Analysis and Modeling CHAPTER 2 Excel 2007 and the Previous Versions The New Features in Excel 2007 The New User Interface The Office Icon The Ribbon The Quick Access Toolbar (QAT) and Customizing It The Shortcut Menus and the Mini Toolbar Finding Some of the Old Tools and Dialog Boxes Other New Features PivotTable Table Professional Quality Charts Conditional Formatting AutoComplete for Entering Formulas One Integrated Function Library Styles and Themes A Much Larger Grid Page Layout View Consolidated Options New File Formats in Excel 2007 15 15 16 17 17 18 19 19 19 20 20 21 21 21 22 22 22 23 23 23 vii
CONTENTS CHAPTER 3 Excel Basics Improving Your Excel Skills Saving Your Workbooks Using Excel's Online Help Learning Excel Features The Basic Excel Features Keeping Your Workbooks and Related Files Organized Naming Workbooks and Worksheets Finding the Commands You Need Working with Worksheets Working with Rows, Columns, and Cells Using the Toolbars Using Keyboard Shortcuts Navigating the Worksheet Formatting Entering and Working with Formulas Using Paste Special Controlling the Worksheet View Using Undo and Redo Customizing the Excel Work Environment Controlling When Formulas Are Calculated Printing Creating Charts Working with More Than One Workbook Using the Scroll Lock 25 26 26 28 32 32 32 33 33 33 34 34 34 36 36 37 37 38 38 38 39 39 40 40 41 CHAPTER 4 Advanced Excel Features Copying Formulas Using Absolute and Relative Cell References Creating Names for Cells and Ranges Using Names in Formulas Al and R1C1 Reference Styles Using Comments in Cells Data Validation Controls Custom Number Formats Hiding and Protecting Custom Views Arrays and Array Formulas Outline 43 46 49 56 57 58 60 62 65 67 71 72 75
Contents ix CHAPTER 5 Making Oecisions and Looking Up Values Making Decisions Examples of Creating Decision-Making Formulas Looking Up Values Conditional Formatting 77 78 82 97 103 CHAPTER 6 Analyzing Databases The Mutual Fund Portfolio v Sorting Sorting on One Field Sorting Using Custom Lists Multiple Sort Filtering Filtering on a Single Column Filtering on Multiple Columns Combining Filtering and Sorting Tables Creating a Table Working with a Table Adding and Using a Total Row Removing Duplicate Data Rows from a Table Sorting and Filtering a Table Using Structured References with Tables PivotTable The Basic Structure of a Pivot Table Creating a Basic Pivot Table Formatting a Pivot Table Modifying Pivot Tables Grouping Fields Sorting and Filtering Pivot Tables Other Features of PivotTable 109 110 112 113 115 118 120 121 122 124 124 126 127 129 132 132 133 135 136 138 142 145 151 156 159 CHAPTER 7 Answering What-lf Questions Data Tables Scenario Manager 161 162 166 CHAPTER 8 Finding Iterative Solutions Circular Reference Goal Seek Solver 171 171 174 177
CONTENTS CHAPTERS CHAPTER 10 CHAPTER 11 Doing Statistics! Analysis Descriptive Statistics Frequency Distributions and Histograms Counting, Ranking, and Calculating Quantiles Normal Probability Distributions Random Numbers Statistical Tests Using the Hnancial Frictions Annuity Functions Investment Analysis Functions Bond Functions Depreciation Functions Other Useful Excel Functions Mathematical Functions Truncating and Rounding Numbers Logarithms Other Mathematical Functions Date and Time Functions Text Functions Information Functions 185 187 192 195 203 207 218 221 221 228 232 237 243 243 243 246 246 248 251 254 Part Two Financial Modeling Using EKcel CHAPTER 12 Building ted Excel Models and Debugging Them Attributes of Good Excel Models Documenting Excel Models Common Ways to Document Your Excel Model Debugging Excel Models Errors Excel May Find for You Errors You Will Have to Find Yourself Using Formula Auditing Tools for Debugging The Formula Auditing Tools Learning Modeling Using Excel The Four Learning Tracks 257 257 260 260 262 263 264 265 266 267 267 CHAPTER 13 Financial Statements Forecasting Review of Theory and Concepts Step 1: Understand the Expected Uses of the Model Step 2: Collect Historical Data 271 271 272 272
Contents Ki Step 3: Understand the Company's Plans and Develop a Comprehensive Set of Modeling Assumptions 273 Step 4: Build the Model and Debug It 275 Step 5: Improve the Model Based on Feedback 276 The Level of Detail in a Model 277 The Statement of Cash Flows 277 Free Cash Flow 279 Modeling Examples : 281 Model 1: Historical Financial Statements 281 Model 2: Common Size Statements 288 Model 3: Financial Indicators 290 Model 4: Financial Statement Forecasting with Unbalanced Balance Sheet 293 Model 5: Financial Statement Forecasting, Version 1 300 Model 6: Financial Statement Forecasting, Version 2 303 Model 7: Financial Statement Forecasting, Version 3 305 Model 8: Financial Statement Forecasting, Version 4 308 Model 9: Financial Statement Forecasting, Version 5 310 Model 10: Financial Statement Forecasting, Version 6 311 Model 11: Financial Statement Forecasting, Version 7 314 Model 12: Financial Statements Sensitivity Analysis 319 Model 13: Financial Statements Scenario Analysis 321 Model 14: Calculating Free Cash Flow 323 CHAPTER 14 Time Value of Money 327 Review of Theory and Concepts 327 Present and Future Values 327 Investment and Project Evaluation 333 Constant Annuities 334 Growing Annuities 338 Modeling Examples 341 Model 1: Effect of Compounding Frequency 342 Model 2: Constant Annuities 344
Xii CONTENTS Model 3: Growing Annuities 348 Model 4: Loan Amortization Table, Version 1 351 Model 5: Loan Amortization Table, Version 2 354 Model 6: Loan Amortization Table for Changing Interest Rate 356 Model 7: Loan Amortization Table for Changing Annual Payment 359 Model 8: The Condominium Project 361 CHAPTER 15 Hnancial Planning and Investments 305 Review of Theory and Concepts 365 Some Basic Issues 365 Saving and Investing for Retirement 368 Structuring Portfolios 371 Modeling Examples 372 Model 1: Return with Changing Reinvestment Rates 372 Model 2: Saving for Retirement 376 Model 3: Retirement Planning in Real Dollars 379 Model 4: Retirement Planning in Nominal Dollars 380 Model 5: Portfolio Structuring 385 CHAPTER 16 Analyzing Market History 389 Review of Theory and Concepts 389 Indexes 389 Measuring Returns 390 Risk 394 Modeling Examples 394 Model 1: Calculating Total Returns 394 Model 2: Comparing Returns on Several Assets 397 Model 3: Comparing Nominal and Real Growth of Investment 400 Model 4: Comparing Rolling Period Returns 402 CHAPTER 17 Bond Pricing and Duration 409 Review of Theory and Concepts 409 Key Characteristics of Bonds 409 Bond Valuation 411 Risks of Bond Investing 413 Bond Duration 414 The Yield Curve and Forward Rates 415
fc. Contents Xiii Modeling Examples 416 Model 1: Yield Curve and Forward Rates 416 Model 2: Bond Pricing Using Yield to Maturity 418 Model 3: Bond Pricing Using the Yield Curve 420 Model 4: Bond Duration and Its Dependence on Yield to Maturity 422 Model 5: Dependence of Bond Duration on Remaining Life 424 CHAPTER 18 Simulating Stock Prices 427 Review of Theory and Concepts 427 Generating Random Numbers 437 Modeling Examples 438 Model 1: Estimating a Stock's Volatility, Version 1 438 Model 2: Estimating a Stock's Volatility, Version 2 440 Model 3: Simulating Stock Prices 442 Model 4: Lognormal Distribution of Stock Prices 445 CHAPTER 19 Options and Option Portfolios 449 Review of Theory and Concepts 449 Option Basics and Terminology 449 Payoffs of Options at Expiration 451 The Black-Scholes-Merton Equation for Option Valuation 452 The Greek Letters 455 Valuing American Options 458 Option on Other Assets 459 Option Portfolios 459 Modeling Examples 460 Model 1: Option Payoffs at Expiration 460 Model 2: Profit of Option Portfolios at Expiration 462 Model 3: Profit of Option Portfolios at Expiration (Using Array Formulas) 466 Model 4: BSM Model and the Greek Letters 469 Model 5: Variation of Option Price with Stock Price 472 Model 6: Variation of Option Price with Volatility 476 Model 7: Variation of Delta with Time to Expiration 478 Model 8: Leverage of Options 481 Model 9: Profit of Options Portfolio at Any Time 483
xiv CONTENTS CHAPTER 20 Binomial Option Pricing Review of Theory and Concepts Modeling Examples Model 1: European Options on Stocks with Known Dividend Yield Model 2: American Options on Stocks Paying No Dividend Model 3: American Options on Stocks with Known Dividend Yields Model 4: American Options on Stocks with Known Dollar Dividends 487 487 491 491 495 498 500 Part Three VBA for Financial Modeling CHAPTER 21 Introduction to VBA Why Learn VBA? Understanding Programs Example of a VBA Model Running the Model Analyzing the Model The Order of Statements Recording Macros Using VBA's Help Finding Help in Excel 2007 Finding Help in Previous Versions of Excel The Strategy to Learn VBA Efficiently 505 506 509 510 511 512 519 520 524 524 524 526 CHAPTER 22 VBA Essentials The Visual Basic Editor The VBE Window Using the Project Explorer Window Using the Code Window Setting VBE Options Some Basics Entering Code Running Procedures Organizing Procedures in Modules Line Continuation Multiple Statements in One Line Adding Comments Indenting Code Lines 529 530 531 532 534 534 535 535 536 537 537 538 538 539
Contents XV CHAPTER 23 CHAPTER 24 Operators Working with Text The MsgBox Function The InputBox Function The Stop and End Statements Variables, Constants, and Arrays Naming Variables Changing Variable Names Data Types! Declaring Variables ' Scope of Variables Constants Arrays Objects, Properties, and Methods Objects Properties Methods Branching If Statements Select Case... End Select Statement GoTo Statement Looping For... Next Statement Do... Loop Statements Nested Loops For Each... Next Statement The Exit Statements With... End With Statement Using Built-in Functions Sub and Function Procedures Sub Procedures The Structure of Sub Procedures Using Sub Procedures Function Procedures The Advantages of Function Procedures The Structure of Function Procedures Using Function Procedures Debugging VBA Codes The Four Basic Types of Bugs The VBA Debugging Tools 540 541 542 544 545 545 546 547 547 549 550 553 553 557 558 560 560 561 561 565 566 567 567 569 571 572 573 573 574 577 577 577 578 582 582 583 584 589 590 591
XVI CONTENTS Part Four Financial Moddiig Using BA CHAPTER 25 How to Build Oood VBA Models Attributes of Good VBA Models Documenting VBA Models Learning Modeling Using VBA Sketching the VBA Code The Three Learning Tracks 597 597 601 603 603 604 CHAPTER 26 Time Vaiue of Mmney 607 Review of Theory and Concepts 607 Solving Problems by Iteration 607 Modeling Examples 611 Model 1: Loan Amortization Table, Version 1 612 Model 2: Loan Amortization Table, Version 2 619 Model 3: Loan Amortization Table, Version 3 626 Model 4: Loan Amortization Table, Version 4 630 Model 5: Loan Amortization Table Using Goal Seek 634 Model 6: Loan Amortization Table Using Arrays 638 Model 7: MyPmt Function 643 Model 8: Loan Amortization Table Using the Bisection Method 646 Model 9: Loan Amortization Table for Changing Interest Rate 653 Model 10: Loan Amortization Table for Changing Annual Payment 658 CHAPTER 27 Financial Planning and investments Modeling Examples Model 1: Saving for Retirement, Version 1 Model 2: Saving for Retirement, Version 2 Model 3: Retirement Planning in Nominal Dollars, Version 1 Model 4: Retirement Planning in Nominal Dollars, Version 2 Model 5: Portfolio Structuring 663 663 666 668 674 680 CHAPTER 28 Analyzing Market History Modeling Examples Model 1: Nominal and Real Growth of $1 Investment in Stocks 691 691 691
Contents XVII Model 2: Growth of $1 Investment in Different Assets 700 Model 3: Comparing Rolling Period Returns 706 CHAPTER 29 Simulating Stock Prices Modeling Examples Model 1: Estimating a Stock's Volatility Model 2: Simulating Stock Prices 717 717 717 719 CHAPTER 30 Options and Option Portfolios Modeling Examples Model 1: Profit of Options Portfolio at Expiration Model 2: Option Pricing Using the BSM Equations Model 3: Implied Volatility of Options Model 4: Profit of Options Portfolio at Any Time 725 725 725 730 734 736 CHAPTER 31 Binomial Option Pricing Modeling Examples Model 1: European Options on Stocks with Known Dividend Yield Model 2: American Options on Stocks Paying No Dividend Model 3: American Options on Stocks with Known Dividend Yields Model 4: American Options on Stocks with Known Dollar Dividends 741 741 741 745 748 750 APPENDIX A APPENDIX B APPENDIX C Keyboard Shortcuts for Excel VBA Quick Reference Excel and VBA Built-in Functions 755 757 759 About the CD-ROM Index 777 781