Calculations

Calculations

Node structure

The structure of nodes determine calculations in fvmb. So a parent node will reflect the sum (or average or …) of all of its subnodes. The parent will calculate this sum by adding all the subnodes but note that you can mark a node to be subtracted from the total for example. A typical use is to create a node called Expenses and then to add subnodes called Employement and Water and Lights to it for example. Here expenses will reflect the sum of its subnodes.

Total nodes

Then there are total nodes. Whereas parent nodes sum the subnodes, a total node will sum all the peer nodes that come before it. A typical use case is to add Sales and Cost of Sales items to a document. Then add a total node. The total node will reflect the total of the preceding two nodes, so it will initially add Sales and Cost of Sales. Now mark Cost of Sales as a Subtract me node and the total will be Sales less Cost of Sales or Gross Profit. Next add an Expenses node as described earlier and below that a new total node call Net Profit. This total will be the previous total, Gross Profit with Expenses added to it. Again mark Expenses as a Subtract Me and the Net Profit will be reflected correctly.

A lot of models can be constructed just by using the correct node structure, but fvmb also offers a powerful calculation engine. It can calculate critical values of numerous statistical distributions, fit OLS and ARIMA models, perform non-linear optimisations or fit FFT or HP Filters.

Calculations

There are two types of calculations in fvmb - data and regular. These two are treated the same, ie a formula entered as a data formula will be calculated in the exact same way that a regular formula will be. However, they are used for different purposes and executed at different times.

Data

A data calculation is used to download data from an external source or to perform a long running and once off calculation task, such as fitting and forecasting an ARIMA model.

Data calculations never run automatically. They can only be run when you click on the download button. Then all the data calculations are displayed and you can e.g. disable some of them to only run a portion. This is especially helpful of you have a few ARIMAs but only want to update one or two of them.

Data calculations also run in isolation from one another. So a data calculation can not use other variables when calculating.

Regular

A regular calculation is updated each time the document changes so it need to finish quickly. To force an update, or to cancel a long running calculation that is underway, touch the sum (∑) button.

Regular calculations have access to other variables, but only to preceding ones. You need to keep this in mind when constructing a document. A calculation can only use say GDP if GDP was defined earlier in the hierarchy than itself.

Functions

There are more than 250 functions available. You can program loops, perform matrix calculations, calculate the gamma function or fit HP filters.

fvmb uses the same formula parser as its sister app fdm. For more information and to see the syntax as well as code snippets and examples, please visit the fdm website.

Basics

Any calculation you enter for a node should return a time series of observations. These will be displayed as the values of the node.

Fixed data

One of the simplest ways in which you can do this is through the observe function, for example

observe( dateIndex( 2020, 12, 31 ), 1, 2, 3, 4 )

will return four values; 1, 2, 3 and 4; loaded in the last bar or time slot of 2020 and then in the first three time slots of 2021.

Indexing

Time series can be indexed as shown below. This is for a calculation performed in the quarterly frequency.

x = observe( dateIndex( 2020, 12, 31 ), 1, 2, 3, 4 );

x[ dateIndex( 2020, 1, 1 ) ] = 1;

I = dateIndex( 2020, 3, 1 );

x[ I ] = 1;
x[ I + 1 ] = 1;

# Now x's observations have been replaced by four 1's

Lags and leads

A time series can be lagged (or led) as shown below.

yoy = ( CPI - CPI(-12) / CPI(-12);    # Monthly yoy figure

Advanced

There are many more advanced calculations available. These are discussed in depth on the fdm website where there are code snippets and video tutorials on how to use it.