For time series, RATS can handle automatically the following types of (regular) date schemes:

For the last two categories, or for the first two if any calculations need to be done based upon the actual days covered, RATS uses a perpetual calendar which is valid for dates from 1800 on using the Gregorian calendar, so 1900 and 2100 aren't leap years, 2000 is. The actual coding used internally starts with a theoretical Jan 1, 0001 as day 1. This is the RATS "Julian" code for a date. The function %JULIAN(T) will return that value for an entry, so

cal(q) 1960:1

disp %julian(1970:1)

will show 719252, which would be the day number for 31 March 1970 (last day of 1970Q1—the "date" of an entry is the last day covered) if the Gregorian calendar had been in place since Jan 1, 0001. The advantage of a Julian date system is that you can tell how many days separate two entries by subtracting their Julian values. Spreadsheets use a similar system, though in a somewhat confusing way. The first widely used spreadsheet program (Lotus 1-2-3, which created WKS files) used a Julian system starting with Jan 1, 1900, except it had 1900  (incorrectly) as a leap year. Excel offered two different schemes: for compatibility one based in 1900 with the Lotus bug, and another based in 1904, which avoids it. Two different XLS or XLSX files can display the same dates on the screen, while actually having different underlying values. (While the RATS system theoretically extends back to the year 1, it actually is only correct back to the adoption of the Gregorian calendar, which varies from country to country. For most countries, daily or weekly data into the 1800's will be handled properly).

To handle data with irregular dates (so that, for instance, Monday follows Thursday if Friday is missing), you need a full mapping of entries to Julian dates. If the data file has a usable date field, you can use the JULIAN option on DATA to pull that in and assign it to a series. (This doesn't have to be the name of the column of dates on the file, and, in fact, the column of dates doesn't need a label anyway). You then use CALENDAR with the option JULIAN to feed that series in as the mapping series for entries to and from dates.

open data "stocks.xlsx"

data(format=xlsx,org=columns,julian=date) 1 4566 price $

   simple_return log_return log_price


If, instead, the data file has separate year, month and day fields, you can use the %JULIANFROMYMD function to compute the RATS Julian codes from those:

open data djia.txt

data(format=free,org=columns) 1 18940 year month day logret logrange close low high


* The data are daily with holiday skips. This maps the year, month,

* day information to provide the dates.



Or, if you have irregular dates with a single series with the year-month-day information coded in decimal form (such as 19931115), you can use the %JULIANFROMCODED function. For instance, in the following the series DATE has values like 500104 for Jan 4, 1950. (RATS always assumes that 2 digit years mean 1900's.)

open data 5092.out

data(format=free,org=columns) 1 10875 date weekday d1 d2 d3 vol spret c8 c9