Difference between revisions of "Example function"

m
 
(2 intermediate revisions by the same user not shown)
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 />
  
__TOC__
+
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:
  
 +
:[[File:example_function_1.png|600px]]
  
The following function, [[Capm]], 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]], <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.
  
:[[File:example_function_1.png|400px]]
+
The [[Definition]] parameter can contain any expression, which uses the parameters, «rf», «rm», and «beta». The expression computes the value to be returned.
  
==Parameters==
+
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:
  
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 the parameters are numbers.
+
:<code>Variable Stock_return: Capm(5%, 8%, StockBeta)</code>
  
==Description==
+
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.
 
 
The description says what the function returns and what its parameters mean.
 
 
 
==Definition==
 
 
 
The definition is an expression that uses its parameters, «rf», «rm», and «beta», and evaluates to the value to be returned.
 
 
 
==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 <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>
 
 
 
The function works equally well when <code>StockBeta</code> is an array of beta values — or if any parameter is an array — 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.