Example function
Here is a simple example of a user-defined function, Capm. It computes the expected return for a stock under the capital asset pricing model:
A function looks a lot like a Variable, with an Identifier, Title, Units, Description, and Definition. The main differences is that it has a
Parameters attribute. Function Capm has three parameters, «rf», «rm», and «beta». The parameter qualifier, Number
(after the parameters and ":"), says that it expects that each parameter should be a number (or an array of number). If not, it will give a error message during evaluation.
The Definition parameter can contain any expression, which uses the parameters, «rf», «rm», and «beta». The expression computes the value to be returned.
You use (or "call") the Capm() function in a definition of a variable, or other function, in the same way you would use a built-in function. For example, if the risk free rate is 5%, the expected market return is 8%, and variable StockBeta
contains the beta value for a given stock, you can use the function to calculate the expected return according to the capital asset pricing model:
Variable Stock_return: Capm(5%, 8%, StockBeta)
Like built-in functions, user-defined functions (usually) support full Intelligent when StockBeta
-- or any parameter -- is an array of numbers. The result is an array of expected returns.
See Also
- Function calls and parameters
- Parameter qualifiers
- Function parameter qualifiers
- User-Defined Functions
Enable comment auto-refresher