Frequency conversions

<< Click to Display Table of Contents >>

Navigation:  Details >

Frequency conversions

Previous pageReturn to chapter overviewNext page

In general, Gekko tries to be relatively lax if the user indicates a time period in one frequency, but the timeseries involved have different frequency. For instance, if the user tries PRT <2010m2 2020m5> x!q;, where x!q is a quarterly timeseries. Which quarters should be printed, when the period is indicated as starting in February 2010 and ending in May 2020...?

A method that is often used for doing such conversions is G.ConvertDateFreqsToAllFreqs(). This method is not intended to be fast, but it inputs two GekkoTime variables (cf. here), and converts them to all frequencies at once. Currently, that means frequencies a, q, m, d, u. The method returns an object that contains pairs of dates in all these frequencies. To do this, the method calls the following:

//annual
GekkoTime.ConvertFreqs(EFreq.A, t1, t2, ref allFreqsHelper.t1Annual, ref allFreqsHelper.t2Annual);
//quarterly
GekkoTime.ConvertFreqs(EFreq.Q, t1, t2, ref allFreqsHelper.t1Quarterly, ref allFreqsHelper.t2Quarterly);
//... 

//... and so on

//... 

 

The method GekkoTime.ConvertFreqs() actually performs the conversions, and for annual frequency, it is called with EFreq.A, the start and end period (two GekkoTime objects), and the results (also two GekkoTime objects) end up in allFreqsHelper.t1Annual and allFreqsHelper.t2Annual, respectively (which is later on returned).

The method GekkoTime.ConvertFreqs() is quite central here, and there are quite a lot of rules regarding how to convert from one frequency to another. For instance, if we are converting a start period 2010 (annual) to monthly, the monthly period will become 2010m1 (January), but if we are converting a daily period 2010m2d15 (February 15) to monthly, the monthly period will become 2010m2, just skipping the day info. This is relatively straightforward, and the hardest cases are for instance converting 2010m2 to quarterly. Here, we try to include the month in the quarter, so that we use 2010q1 (which includes February).

There are a lot of these rules because there are 5 different frequencies (and therefore 5*(5 - 1) = 20 different conversions), but the code is pretty easy to understand.