Difference between revisions of "Example function"
m |
m |
||
Line 2: | Line 2: | ||
[[Category: Functions]] | [[Category: Functions]] | ||
<breadcrumbs>Analytica User Guide > User-defined Functions and Libraries > {{PAGENAME}}</breadcrumbs><br /> | <breadcrumbs>Analytica User Guide > User-defined Functions and Libraries > {{PAGENAME}}</breadcrumbs><br /> | ||
+ | |||
+ | Here is a simple example of a user-defined function. | ||
__TOC__ | __TOC__ | ||
− | + | This function, [[Capm]], computes the expected return for a stock under the capital asset pricing model: | |
− | :[[File:example_function_1.png| | + | :[[File:example_function_1.png|600px]] |
− | ==Parameters== | + | ===Parameters=== |
− | It has three [[Function calls and parameters|parameters]], «rf», «rm», and «beta». The [[parameter qualifiers|parameter qualifier]] <code>Number</code> says that it expects that | + | It has three [[Function calls and parameters|parameters]], «rf», «rm», and «beta». The [[parameter qualifiers|parameter qualifier]] <code>Number</code> says that it expects that three parameters should be numbers (or arrays of numbers). If not, it will give a error message during evaluation. |
− | ==Description== | + | ===Description=== |
− | The description | + | The description is documentation explaining what the function returns and what its parameters mean. |
− | ==Definition== | + | ===Definition=== |
− | The definition is an expression that uses its parameters, «rf», «rm», and «beta», and | + | The definition is an expression that uses its parameters, «rf», «rm», and «beta», and computes the value to be returned. |
− | ==Sample usage== | + | ===Sample usage=== |
− | You use the [[Capm]]() function in a definition in the same way you would use | + | You use the [[Capm]]() function in a definition in the same way you would use any built-in function. For example, if the risk free rate is 5%, the expected market return is 8%, and <code>Stock-Beta</code> is defined as the beta value for a given stock, we can find the expected return according to the capital asset pricing model as: |
:<code>Stock_return: Capm(5%, 8%, StockBeta)</code> | :<code>Stock_return: Capm(5%, 8%, StockBeta)</code> | ||
− | The function works equally well when <code>StockBeta</code> | + | The function works equally well when <code>StockBeta</code> -- or any parameter -- is an array of numbers. The result is an array of expected returns. |
==See Also== | ==See Also== |
Revision as of 03:11, 21 March 2018
Here is a simple example of a user-defined function.
This function, Capm, computes the expected return for a stock under the capital asset pricing model:
Parameters
It has three parameters, «rf», «rm», and «beta». The parameter qualifier Number
says that it expects that three parameters should be numbers (or arrays of numbers). If not, it will give a error message during evaluation.
Description
The description is documentation explaining what the function returns and what its parameters mean.
Definition
The definition is an expression that uses its parameters, «rf», «rm», and «beta», and computes the value to be returned.
Sample usage
You use the Capm() function in a definition in the same way you would use any built-in function. For example, if the risk free rate is 5%, the expected market return is 8%, and Stock-Beta
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)
The function works equally well 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