TAILIEUCHUNG - Lecture Financial modeling - Topic 5: Advanced topics in VBA/User-defined functions for use in financial applications

In this chapter students obtain the programming skills needed to write financial VBA programs which require the use of loops, conditional statements, and matrix operations. This topic will describe: Dim statements and option explicit, debugging, data types (as object), the use of functions in functions, for loops and nested loops, arrays and option base 1. | 1 Topic: 5 Advanced Topics in VBA/User-Defined Functions for Use in Financial Applications Financial Modeling L. Gattis Learning Objective Students obtain the programming skills needed to write financial VBA programs which require the use of loops, conditional statements, and matrix operations 2 3 References Financial Modeling 3rd Edition by Simon Benninga Ch. 34: Array Functions and Formulas Ch. 36: User Defined Functions with VBA Ch. 37: VBA Types and Loops Advanced VBA Topics Dim Statements and Option Explicit Debugging Data Types (As Object) The use of functions in functions For Loops and Nested Loops Arrays and Option Base 1 4 VBA Variables Variables can be parameters or can be created in the program . Function CAPM (rf,rm,beta) MRP = (rm-rf) CAPM = rf+beta*mrc End Function MRP is an internal variable Variables do not need to be “declared” in VBA 5 Typo Option Explicit and Dim Statement OPTION EXPLICIT is a VBA statement that is typed at the top of a module (before functions or macros) requires internal variable by declared using a DIM statement for all module programs Why use OPTION EXPLICIT and DIM? Makes programs easier to read Makes programs easier to debug 6 reset 7 Function Types Function types You can specify the variable type (. integer) by using the reserved word “as” the default type is variant (includes all types) Why specify types? Makes program run faster and uses less memory Your function will only return variables of that type Makes the program code more reader-friendly if the reader knows the expected variable type Makes debugging easier 7 What is the advantage of specifying type? 8 Default Type Debugging Suggestions Always know the solution to a problem before you code so you can test the program Use Option Explicit and Dim statements Use comment lines to describe function, variables, calculations, assumptions 9 Functions in Functions You can use functions within functions ., Makes program code more modular Can share code across .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.