Difference between revisions of "User-Defined Functions"
m (adding doc status category stub page) |
(Content taken from users guide) |
||
Line 1: | Line 1: | ||
[[Category:Doc Status D]] <!-- For Lumina use, do not change --> | [[Category:Doc Status D]] <!-- For Lumina use, do not change --> | ||
+ | |||
+ | You can create your own functions to perform calculations you use frequently. A function has one or more parameters; its definition is an expression that uses these parameters. You can specify that the function check the type or dimensions of its parameters, and control their evaluation by using various [[Function Parameter Qualifiers|parameter qualifiers]]. | ||
+ | |||
+ | A ''Library'' is a a collection of functions grouped in a library file to extend Analytica’s built-in functions for use for particular types of applications. Analytica is distributed with an initial set of libraries, accessed from the '''File''' menu with the '''Add Library...''' option. If you add a Library to a model, it will appear with its functions in the Definition menu, and these functions will appear almost the same as the built-in functions. | ||
+ | |||
+ | You may want to look at these libraries to see if they provide functions useful for your applications. You may also look at library functions as a starting point or inspiration for writing your own functions. | ||
+ | |||
+ | Analytica experts may create their own function libraries for particular domains. Other Analytica users can benefit from these libraries. | ||
+ | |||
+ | = Example function = | ||
+ | |||
+ | The following function, [[Capm]](), computes the expected return for a stock under the capital asset pricing model. | ||
+ | |||
+ | '''Parameters:''' (Rf, Rm, Beta : Numeric ) | ||
+ | '''Definition:''' Rf + Beta * (Rm - Rf) | ||
+ | |||
+ | '''Sample usage:''' You use the [[Capm]]() function in a definition in the same way you would use Analytica’s built-in functions. For example, if the risk free rate is 5%, the expected market return is 8%, and ''StockBeta'' is defined as the beta value for a given stock, we can find the expected return according to the capital asset pricing model as: | ||
+ | '''Stock_return:''' Capm(5%,8%,StockBeta) | ||
+ | This definition functions equally well when ''StockBeta'' is an array of beta values. In this case, the result will be an array of expected returns. |
Revision as of 05:36, 15 August 2007
You can create your own functions to perform calculations you use frequently. A function has one or more parameters; its definition is an expression that uses these parameters. You can specify that the function check the type or dimensions of its parameters, and control their evaluation by using various parameter qualifiers.
A Library is a a collection of functions grouped in a library file to extend Analytica’s built-in functions for use for particular types of applications. Analytica is distributed with an initial set of libraries, accessed from the File menu with the Add Library... option. If you add a Library to a model, it will appear with its functions in the Definition menu, and these functions will appear almost the same as the built-in functions.
You may want to look at these libraries to see if they provide functions useful for your applications. You may also look at library functions as a starting point or inspiration for writing your own functions.
Analytica experts may create their own function libraries for particular domains. Other Analytica users can benefit from these libraries.
Example function
The following function, Capm(), computes the expected return for a stock under the capital asset pricing model.
Parameters: (Rf, Rm, Beta : Numeric ) Definition: Rf + Beta * (Rm - Rf)
Sample usage: You use the Capm() function in a definition in the same way you would use Analytica’s built-in functions. For example, if the risk free rate is 5%, the expected market return is 8%, and StockBeta is defined as the beta value for a given stock, we can find the expected return according to the capital asset pricing model as:
Stock_return: Capm(5%,8%,StockBeta)
This definition functions equally well when StockBeta is an array of beta values. In this case, the result will be an array of expected returns.
Enable comment auto-refresher