Difference between revisions of "Analytica User FAQs/Expressions - How to"

 
Line 1: Line 1:
= Analytica Expression FAQs =
 
 
 
(In progress -- two things need to occur.  Common questions need to be collected here and organized, and then answers need to be added.  Feel free to contribute to either aspect)
 
(In progress -- two things need to occur.  Common questions need to be collected here and organized, and then answers need to be added.  Feel free to contribute to either aspect)
  
== Array Abstraction ==
+
= Array Abstraction =
  
 
* How do I access a single row of an array?
 
* How do I access a single row of an array?
Line 10: Line 8:
 
* How do I aggregate an array from a fine grain index (e.g., days) to a coarser index (e.g., months)?  
 
* How do I aggregate an array from a fine grain index (e.g., days) to a coarser index (e.g., months)?  
  
== Distributions ==
+
= Distributions =
  
 
* How do I generate independent distributions across an index, for example, so that Noise := Normal(0,1) is independent for each time point t?
 
* How do I generate independent distributions across an index, for example, so that Noise := Normal(0,1) is independent for each time point t?
Line 18: Line 16:
 
* [[How to Fit a Distribution to Data|How do a fit a distribution to historical data?]]
 
* [[How to Fit a Distribution to Data|How do a fit a distribution to historical data?]]
  
== User-Defined Functions ==
+
= User-Defined Functions =
  
 
* How do I create my own User-Defined function?
 
* How do I create my own User-Defined function?
Line 24: Line 22:
 
* How do I create a custom distribution function?
 
* How do I create a custom distribution function?
  
== How do I model X (Depreciation)? ==
+
= How do I model XXX? =
  
* Depreciation (offset in time)?
+
=== How do I model Depreciation (offset in time)? ===
 
To model depreciation, two inputs are required:  
 
To model depreciation, two inputs are required:  
 
1) a schedule of spend to be depreciated
 
1) a schedule of spend to be depreciated
Line 54: Line 52:
 
== What does Analytica use to represent missing values? ==
 
== What does Analytica use to represent missing values? ==
  
Analytica has no special MissingValue constant.
+
Analytica has no special MissingValue constant.  The constant [[Null]] typically serves that purpose.
  
I would recommend using Null. However, because Analytica does not interpret this (or any other constant) as meaning a missing value, you will need to insert appropriate conditional logic to deal with the missing values in the appropriate fashion. For example:
+
Several common functions that operate over arrays, but not all functions, will ignore [[Null]] values. For example, [[Sum]], [[Product]], [[Max]], [[Min]], [[Average]], etc.  This treatment of [[Null]] by these functions is relatively recent -- starting with 4.0 -- and we've been enhancing the remaining functions with successive releases.  Currently there still remain several built-in functions that do not ignore [[Null]], such as many statistical functions, and your own UDFs may not ignore nulls.  You may also desire a different treatment of missing values than just ignoring the values. To deal with these cases, you will need to insert appropriate conditional logic to deal with the missing values in the appropriate fashion. For example:
  
Sum( MaybeMissing(x), I )
+
:Variance( MaybeMissing(x), I )
  
Product( MaybeMissing(x,1), I )
+
:Cumulate( MaybeMissing(x,1), I )
  
 
where
 
where
Function MaybeMissing( x ; defX : optional )
+
:Function MaybeMissing( x ; defX : optional )
 
+
:Definition: if x=Null then if IsNotSpecified(defX) then 0 else defX else X
Definition: if x=Null then if IsNotSpecified(defX) then 0 else defX else X
+

Revision as of 07:12, 7 August 2008

(In progress -- two things need to occur. Common questions need to be collected here and organized, and then answers need to be added. Feel free to contribute to either aspect)

Array Abstraction

  • How do I access a single row of an array?
  • How do I represent a square matrix?
  • How do I re-index an array, exchanging one index, I, for another of the same length, J?
  • How do I aggregate an array from a fine grain index (e.g., days) to a coarser index (e.g., months)?

Distributions

  • How do I generate independent distributions across an index, for example, so that Noise := Normal(0,1) is independent for each time point t?
  • How do I define a chance variable so that its uncertainty is correlated with an existing chance variable?

User-Defined Functions

  • How do I create my own User-Defined function?
  • How do I create a custom distribution function?

How do I model XXX?

How do I model Depreciation (offset in time)?

To model depreciation, two inputs are required: 1) a schedule of spend to be depreciated 2) a depreciation schedule

For this example, the index time is 10 year series with a constant startYear=2008 time:=sequence (startYear,startYear+9,1)

Example depreciation schedule is a 5yr MACRS depreciation schedule entered as a variable: Table(time)(.2,.32,.192,.1152,.1152,.0576,0,0,0,0)

SpendOverTime is a variable indexed by time with the capital spend amounts as desired: table(time)(0,0,111,0,0,0,0,0,0,0)

Create a user defined function: Function_Depreciation, Parameters: (SpendOverTime,DepreciationSchedule), Definition: index depr_years = copyindex(time); var deprStartyr:=time; sum(if time-depr_years+1<1 then 0 else slice(SpendOverTime,time,Depr_years-startYear+1)*slice(depreciationSchedule,time,time-depr_years+1),depr_years)

Then create a depreciation test variable to check the result Variable: DepreciationTest definition: function_Depreciation(spendOverTime,DepreciationSchedule)

What does Analytica use to represent missing values?

Analytica has no special MissingValue constant. The constant Null typically serves that purpose.

Several common functions that operate over arrays, but not all functions, will ignore Null values. For example, Sum, Product, Max, Min, Average, etc. This treatment of Null by these functions is relatively recent -- starting with 4.0 -- and we've been enhancing the remaining functions with successive releases. Currently there still remain several built-in functions that do not ignore Null, such as many statistical functions, and your own UDFs may not ignore nulls. You may also desire a different treatment of missing values than just ignoring the values. To deal with these cases, you will need to insert appropriate conditional logic to deal with the missing values in the appropriate fashion. For example:

Variance( MaybeMissing(x), I )
Cumulate( MaybeMissing(x,1), I )

where

Function MaybeMissing( x ; defX : optional )
Definition: if x=Null then if IsNotSpecified(defX) then 0 else defX else X
Comments


You are not allowed to post comments.