Difference between revisions of "Example function"

m
m
 
Line 3: Line 3:
 
<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. 
+
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:
 
 
__TOC__
 
 
 
 
 
This function, [[Capm]], computes the expected return for a stock under the capital asset pricing model:
 
  
 
:[[File:example_function_1.png|600px]]
 
:[[File:example_function_1.png|600px]]
  
===Parameters===
+
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]], <code>Number</code> (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.
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===
 
 
 
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===
+
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 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:
+
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 <code>StockBeta</code> 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:
  
:<code>Stock_return: Capm(5%, 8%, StockBeta)</code>
+
:<code>Variable Stock_return: Capm(5%, 8%, 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.
+
Like built-in functions, user-defined functions (usually) support full Intelligent when <code>StockBeta</code> -- or  any parameter -- is an array of numbers. The result is an array of expected returns.
  
 
==See Also==
 
==See Also==

Latest revision as of 17:32, 24 January 2019


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:

Example function 1.png

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


Comments


You are not allowed to post comments.