Vision Class: TimeSeries
Overview
TimeSeries objects are used to track information for a particular data item over time. Some items, such as company sales and earnings may be tracked at regular intervals. Other information, such as ratings, will change at irregular intervals over time. The TimeSeries class has been designed to work effectively in all these cases.
The TimeSeries class is an indirect subclass of the Collection class which is also a superclass of the classes List and IndexedList. Instances of the class TimeSeries consist of a collection of objects that are accessed either by date or as a set. A TimeSeries is updated by adding date-object pairs.
The TimeSeries class has been optimized to organize and query large sets of data. A large number of the messages defined for this class have been written in Vision and can therefore be modified and expanded as needed. As always, you can define any number of new messages for the class.
The TimeSeries class is a direct subclass of IndexedCollection:
Object | Function | EnumeratedFunction | Collection | IndexedCollection |-- IndexedList |-- TimeSeries
TimeSeries Basics
A TimeSeries is similar to an IndexedList that is always indexed by a date. TimeSeries objects are available in two distinct forms in Vision:
- As properties created with the define: message.
- As stand-alone objects.
The expression:
Currency define: 'tsProperty' ;creates a new time series property for the class Currency. The expression:
Named Currency USD :tsPropertyretrieves this property for the US currency as a TimeSeries object. The expression:
!newTS <- TimeSeries new ;creates a stand-alone TimeSeries object. The expression:
newTSretrieves this object.
These two forms of TimeSeries object respond identically to the same set of messages. They differ only in the manner in which they are accessed. Recall that you need to place the : character in front of the property name to access the full TimeSeries object associated with the property. In this case the message :tsProperty returns the TimeSeries object. Stand-alone TimeSeries objects do not require the initial : character. This difference is described further in a later section.
The message count returns the number of points in a time series. For example:
Named Currency USD :tsProperty count printNL ; newTS count printNL ;Initially a TimeSeries contains 0 elements. The asOf:put: message is used to update a TimeSeries:
Named Currency USD :tsProperty asOf: 9501 put: 10.1 ; Named Currency USD :tsProperty asOf: 9502 put: 12.3 ; Named Currency USD :tsProperty asOf: 9503 put: 9.7 ; Named Currency USD :tsProperty count printNL ;or
newTS asOf: 960515 put: 3.4 ; newTS count printNL ;
The property tsProperty for the US currency contains 3 points. The variable newTS now refers to a TimeSeries containing 1 point.
The value of the "put:" parameter can be any object. If desired, you can store objects from different classes within a single TimeSeries. The dates in a time series can be regular or irregular. Each instance in a class can have different points represented in a time varying property.
When you ask for the value of a time series property, by default you access the value that was most recently updated on or before the current date. For example:
Named Currency USD tsProperty printNL ;returns the value 9.7 which represents the most recent value in the time series. The asOf: message is used to access a specific point in the TimeSeries. For example:
Named Currency USD :tsProperty asOf: 9502 . printNL ;retrieves and displays the value 12.3. A TimeSeries responds to the asOf: message by accessing the value of the series that was in effect on or before the date supplied as the parameter. The parameter should be a Date object or an integer equivalent.
Pictorially, the tsProperty time series for the US currency can be viewed as a time line of three values:
10.1 12.3 9.7 ___|_____|_____|__________|__________|___ | | | | | 1/31/95 | 2/28/95 3/31/95 4/30/95 | 2/15/95If you request data as of a date that is not in the time series, the value on or before that date will be returned. For example:
Named Currency USD :tsProperty asOf: 950215 . printNL ;returns the value 10.1. Since no value is explicitly stored on February 15, 1995, the first value prior to this date is returned. In this case, the value is the value as of 1/31/95, the first value to the left of 2/15/96 in the time line. If your "as of" date is earlier than the first available date, the value NA will be returned. For example:
Named Currency USD :tsProperty asOf: 94 . printNL ;returns the value NA, since there is no time point on or before this date. If your "as of" date is later than the last available date, the value of the last point in the time series is returned.
The message displayAll can be sent to a a TimeSeries to display all its points. For example:
Named Currency USD :tsProperty displayAll ;displays:
1/31/1995 10.10 2/28/1995 12.30 3/31/1995 9.70If you send this message to the Canadian currency:
Named Currency CAD :tsProperty displayAll ;you should not see any values since this property has not been updated for this currency.
The firstDate and lastDate messages are used to determine the first and last dates for which information has been stored in a TimeSeries. For example:
Named Currency USD :tsProperty firstDate printNL ; Named Currency USD :tsProperty lastDate printNL ;
When you store a value into a time series as of a specific date, the value is assumed to go into effect on that date. It remains in effect until a value is stored at a later date. The messages effectiveDateAsOf: and nextDateAsOf: are used to determine the interval over which a value is in effect. For example:
Named Currency USD :tsProperty effectiveDateAsOf: 950215 .returns the date 1/31/95 and:
Named Currency USD :tsProperty nextDateAsOf: 950215 .returns the date 2/28/95. This indicates that the value you are retrieving for February 15, 1995 was really stored on January 31, 1995 and next updated on February 28, 1995.
The on: message provides an alternative to the asOf: message which only returns a value if the value is actually stored on the date supplied as a parameter. If no value is stored on the date, the value NA is returned.
The delete: message is used to delete a value as of a specific date. For example:
Named Currency USD :tsProperty delete: 9503 .deletes this point from the time series, leaving a time series with 2 points.
Since the TimeSeries class is a subclass of Collection, messages such as do:, send:, select:, groupedBy:, sortUp:, decileDown:, and extendBy: are available to TimeSeries objects as well. Within the block supplied as the parameter, all messages are sent to each element in the recipient time series. When the recipient is a TimeSeries object, the magic word ^date is rebound to the specific date being analyzed. For example:
Named Currency USD :tsProperty do: [ ^date print: 15 ; #- display date of element printNL ; #- print value of element ] ;displays:
1/31/1995 10.10 2/28/1995 12.30 3/31/1995 9.70
The toList message can be used to convert a TimeSeries into a standard List object. For example:
Named Currency USD :tsProperty toList at: 1 .returns the value 10.1 which is the first value positionally after the TimeSeries has been converted to a List. Note that once the time series has been converted to a list, the specific ^date values are not available.
The Default Date and DateRanges
Date objects play an important role in accessing and updating time-series data. Dates (or integer equivalents) are the parameters for the asOf: and asOf:put: messages define for the TimeSeries class.
When a message retrieves data stored in a time-varying property, it accesses the data as of a specific date. By default, this date is the current date. The evaluate: message is sent to a Date or an Integer that can be converted to a date and is used to change the default date. The parameter to this message is a block. All messages within the block that access time series properties will access the values as of this date. For example:
950315 evaluate: [ Named Currency CAD usExchange printNL ] ;In this case, the exchange rate is accessed as of March 15, 1995. The magic word ^date refers to this evaluation date. For example:
950315 evaluate: [ ^date print: 15 ; Named Currency CAD usExchange printNL ; ] ;This example displays the date 3/15/1995 followed by the exchange rate as of that date.
The "as of" logic is used to retrieve time varying data within a ^date evaluate: block. If the evaluation date is earlier than the first available date for a time varying item, the value NA is returned. If there is no explicit data available for the evaluation date, the most recent value before that date is retrieved.
You can change the default date within the evaluate: block. For example:
950315 evaluate: [ ^date print: 15 ; Named Currency CAD usExchange printNL ; ^date + 5 businessDays evaluate: [ ^date print: 15 ; Named Currency CAD usExchange printNL ] ; ] ;This example displays the date 3/15/1995 followed by the exchange rate for that date. It then displays the date and exchange rate for the date 5 business days later than the original date.
If you do not explicitly override it, Vision uses the current date as the default date. The message ^today can be used to specify the current date. For example, the expressions:
Named Currency CAD usExchange print; Named Currency CAD :usExchange asOf: ^today . print; ^today evaluate: [ Named Currency CAD usExchange print; ] ;are all equivalent and return the Canadian exchange rate as of the current date.
Note: The evaluate: message changes the time context of the block but does not change the recipient object like the do: message. In other words, the magic word ^date is rebound by the evaluate: message but the magic word ^self is not.
Several of the TimeSeries messages have variations designed to use the default date including:
General Message | Default Date Equivalent |
asOf: put: | put: |
effectiveDateAsOf: | effectiveDate |
nextDateAsOf: | nextDate |
Instead of supplying an explicit date as a parameter, the messages in the second column use the current value of ^date as the date. For example:
9511 evaluate: [ Named Currency CAD :usExchange put: 2.1 ] ;is equivalent to:
Named Currency CAD :usExchange asOf: 9511 put: 2.1 ;
The evaluate: message works with DateRange objects as well as with Dates. For example, to access the Canadian exchange rate for each month-end date in 1995, use:
9501 to: 9512 by: 1 monthEnds . evaluate: [ ^date print: 15 ; Named Currency CAD usExchange printNL ; ] ;The supplied block prints the evaluation date and the exchange rate for each date in the date range. Starting with the initial date, Vision increments the evaluation date by the date range's offset until the ending date is crossed. When the starting date is earlier than the ending date, Vision decrements the evaluation date by the offset provided. Any time varying data accessed within the block will be retrieved "as of" the current evaluation date in the range.
Lags and Leads
The lag: message is used to return the value of the recipient time series as of a date derived relative to the current evaluation date. This derived date is defined as: ^date - offset, where offset is the DateOffset object supplied as the parameter to the lag: message. For example:
Currency define: 'tsProperty' ; Named Currency USD :tsProperty asOf: 9501 put: 10.1 ; Named Currency USD :tsProperty asOf: 9502 put: 12.3 ; Named Currency USD :tsProperty asOf: 9503 put: 9.7 ; 9502 evaluate: [ Named Currency USD :tsProperty lag: 1 monthEnds . printNL ; ] ;In this example, the evaluation date is 9502. Sending the lag: 1 monthEnds message to the time series is a request to access the data as of the prior month-end date. In this case, the January 31, 1995 value of 10.1 is retrieved and displayed.
The lead: message is used to return the value of the recipient time series as of a date derived relative to the current evaluation date. This derived date is defined as: ^date + offset.
Suppose you wanted to compute the change in value between two points in time. For example:
Named Currency USD do: [ (:tsProperty asOf: 9503) - (:tsProperty asOf: 9502) printNL:10 ; ] ;The message changeLag: provides a more streamlined way for requesting the same information. The expression could be rewritten using:
9503 evaluate: [ Named Currency USD :tsProperty changeLag: 1 monthEnds . printNL ; ] ;The messages pctChangeLag:, changeLead:, and pctChangeLead: work in a similar fashion.
Extracting Subsets
Since the TimeSeries class is a subclass of Collection, you can use the select: message to restrict the time series to dates within a specific range. For example:
Currency define: 'tsProperty' ; Named Currency USD :tsProperty asOf: 9501 put: 10.1 ; Named Currency USD :tsProperty asOf: 9502 put: 12.3 ; Named Currency USD :tsProperty asOf: 9503 put: 9.7 ; Named Currency USD :tsProperty select: [ ^date > 9501 asDate ] . do: [ ^date print: 15 ; printNL ] ;The messages from:to:, from:, and to: have been defined to return a new TimeSeries object which is the subset of the recipient:
#-- Retrieve data from 9502 on Named Currency USD :tsProperty from: 9502 . do: [ ^date print: 15 ; printNL ] ; #-- Retrieve data before 9503 on Named Currency USD :tsProperty to: 9502 . do: [ ^date print: 15 ; printNL ] ; #-- Retrieve data between two dates Named Currency USD :tsProperty from: 9501 to: 9502 . do: [ ^date print: 15 ; printNL ] ;
The message extractForDateRange: returns a new TimeSeries object that contains a point for each value in the DateRange supplied as the parameter. For example:
!dr <- 9412 to: 9504 by: 1 monthEnds ; !extract <- Named Currency USD :tsProperty extractForDateRange: dr ; extract displayAll ;displays
: 12/31/1994 NA 01/31/1995 10.10 02/28/1995 12.30 03/31/1995 9.70 04/30/1995 9.70The variable extract contains a TimeSeries object with a point for each date in dr. Since there was no data prior to 1/31/95, an NA value is returned for 12/31/94. Since there was no data after 3/31/95, the 3/31 value is returned for 4/30.
Collection Message Summary
Since the TimeSeries class is a subclass of Collection, all messages defined for the Collection class are available to TimeSeries objects as well. A subset of these messages are documented in Vision Class: Collection and are summarized below.
- Collection Basics
- count
- do:
- basicDo:
- send:
- basicSend:
- extendBy:
- basicExtend:
- collect:
- numberElements
- linkElements
- do:
- Sorting and Ranking Collections
- sortUpBy:then:
- sortDownBy:then:
- rankUp:
- rankDown:
- rankDown:usingCollector:
- rankUp:usingCollector:
- sortDownBy:then:
- Grouping Collections
- groupedBy:
- groupedByString:
- groupedBy:in:
- groupedBy:intersect:
- groupedBy:union:
- groupedBy:usingCutoffs:
- groupedByCriteria:
- groupPrintUsing:
- mgroupedBy:
- groupedByString:
- Collection Computation Messages
- average
- average:
- average:withWeights:
- compound
- compound:
- correlate:with:
- gMean
- gMean:
- harmonicMean
- harmonicMean:
- harmonicMean:withWeights:
- max
- max:
- median
- median:
- min
- min:
- mode
- mode:
- product
- product:
- rankCorrelate:with:
- regress:
- stdDev
- stdDev:
- total
- total:
- average:
- Intra-List Messages
- decileUp:
- decileDown:
- quintileUp:
- quintileDown:
- percentileUp:
- percentileDown:
- tileUp:tiles:
- tileDown:tiles:
- decileUp:using:
- decileDown:using:
- quintileUp:using:
- quintileDown:using:
- percentileUp:using:
- percentileDown:using:
- tileUp:using:tiles:
- tileDown:using:tiles:
- runningTotal:
- runningAverage:
- normalize:
- weightedDecile:
- weightedQuintile:
- decileDown:
- Inter-List Messages
- isEquivalentTo:
- union:
- union:using:
- intersect:
- intersect:using:
- exclude:
- exclude:using:
- difference:
- union:
- Inquiry Messages
- all:
- any:
- excludesElement:
- includesElement:
- any:
Additional TimeSeries Messages
You can redefine Collection messages and define new messages directly for the TimeSeries class. You can define any number of new methods and constants. You cannot define and update properties for TimeSeries objects.
The following messages are used to update TimeSeries objects:
Message | Definition | Sample |
asOf:put: | Update recipient as of date in parameter1 with object in parameter2, inserting a new date if necessary | ts asOf: 95 put: 10 . |
put: | Update recipient as of ^date with object in parameter, inserting a new date if necessary | ts put: 10 . |
asOf:assign: | Change recipient as of date in parameter1 with object in parameter2 | ts asOf: 95 assign: 10 . |
<- | Change recipient as of ^date with object in parameter | ts <- 10 |
updateWith: | Update recipient as of ^date if parameter is different from current value | ts updateWith: 10 . |
delete: | Delete parameter date from recipient | ts delete: 95 asDate |
deleteAllPoints | Delete all points from recipient | ts deleteAllPoints |
deleteColumnForDate: | Delete all points for all instances in recipient's cluster as of parameter | ts deleteColumnForDate: 95 asDate . |
deleteColumn | Delete all points for all instances in recipient's cluster as of ^date | ts deleteColumn |
The following messages retrieve basic characteristics about TimeSeries objects:
Message | Definition | Sample |
count | Number of points in recipient | ts count |
firstDate | Date of first point in recipient | ts firstDate |
lastDate | Date of last point in recipient | ts lastDate |
effectiveDate | Effective date as of ^date in recipient | ts effectiveDate |
effectiveDateAsOf: | Effective date as of parameter date in recpient | ts effectiveDateAsOf: 95 asDate . |
nextDate | Next date after ^date in recipient | ts nextDate |
nextDateAsOf: | Next date after parameter date in recpient | ts nextDateAsOf: 95 asDate . |
displayAll | Display all date-value pairs in recipient | ts displayAll |
displayAllChanges | Display all date-value pairs in recipient that represent a change in value | ts displayAllChanges |
The following messages are used to retrieve specific values from TimeSeries objects:
Message | Definition | Sample |
asOf: | Return value in recipient as of parameter date | ts asOf: 95 . |
on: | Return value in recipient stored exactly on parameter date | ts on: 95 . |
lag: | Return value in recipient as of ^date - parameter | ts lag: 3 days . |
lead: | Return value in recipient as of ^date + parameter | ts lead: 3 days . |
value | Return value in recipient as of ^date | ts value |
latest | Return value in recipient as of ^today | ts latest |
firstObservation | Return first value in recipient | ts firstObservation |
lastObservation | Return last value in recipient | ts lastObservation |
The following messages are used to extract specific subsets from TimeSeries objects:
Message | Definition | Sample |
from:to: | Return new time series with date-values from recipient corresponding the dates between parameters | ts from: 94 to: 95 . |
from: | Return new time series with date-values from recipient corresponding the dates on or after parameter | ts from: 95 . |
to: | Return new time series with date-values from recipient corresponding the dates on or before parameter | ts to: 95 . |
extractForDateRange: | Return new time series with date-values from recipient for each date in parameter | ts extractForDateRange: drange . |
extractExactValuesForDateRange: | Return new time series with date-values from recipient for each date in parameter; if value does not exist on exact date, return default value for that date | ts extractExactValuesForDateRange: drange . |
The following messages are used to perform computations with TimeSeries objects:
Message | Definition | Sample |
+ | Add parameter to recipient | ts1 + ts2 |
- | Subtract parameter from recipient | ts - 3 |
* | Multiple recipient by parameter | ts * ts |
/ | Divide recipient by parameter | ts / 3 |
aveForDateRange: | Extract date range indicated by parameter from recipient and compute average | ts aveForDateRange: drange . |
cGrow | Compute compound growth for recipient's values | ts cGrow |
cGrowForDateRange: | Extract date range indicated by parameter from recipient and compute compound growth | ts cGrowForDateRange: drange . |
changeLag: | Compute change in value between ^date and ^date - parameter | ts changeLag: 1 months . |
changeLead: | Compute change in value between ^date and ^date + parameter | ts changeLead: 3 days . |
gMeanForDateRange: | Extract date range indicated by parameter from recipient and compute geometric mean | ts gMeanForDateRange: drange . |
lsGrow | Compute least squares growth of recipient's values | ts lsGrow |
lsGrowForDateRange: | Extract date range indicated by parameter from recipient and compute least squares growth | ts lsGrowForDateRange: drange . |
maxForDateRange: | Extract date range indicated by parameter from recipient and compute maximum | ts maxForDateRange: drange . |
medianForDateRange: | Extract date range indicated by parameter from recipient and compute median | ts medianForDateRange: drange . |
minForDateRange: | Extract date range indicated by parameter from recipient and compute minimum | ts minForDateRange: drange . |
modeForDateRange: | Extract date range indicated by parameter from recipient and compute mode | ts modeForDateRange: drange . |
pctChangeLag: | Compute percent change in value between ^date and ^date - parameter | ts pctChangeLag: 5 days . |
pctChangeLead: | Compute percent change in value between ^date and ^date + parameter | ts pctChangeLead: 3 months . |
productForDateRange: | Extract date range indicated by parameter from recipient and compute product | ts productForDateRange: drange . |
stdDevForDateRange: | Extract date range indicated by parameter from recipient and compute standard deviation | stdDevForDateRange: |
totalForDateRange: | Extract date range indicated by parameter from recipient and compute total | ts totalForDateRange: drange . |
TimeSeries and Methods
As you have seen, time varying properties are evaluated relative to a default date represented by the magic word ^date. Methods that directly or indirectly reference time varying properties will also evaluate as of the current evaluation date. For example,, suppose you define a time varying property representing a currency's exchange rate and a method that doubles this value:
#-- Define a time varying property Currency define: 'exchangeRate' ; #-- Define a method to double the value Currency defineMethod: [ | doubleIt | exchangeRate * 2 ] ; #-- Populate some values Named Currency USD :exchangeRate asOf: 93 put: 1.2 ; Named Currency USD :exchangeRate asOf: 94 put: 2.3 ; Named Currency USD :exchangeRate asOf: 95 put: 3.4 ; #-- Display data over range of dates Named Currency USD do: [ 93 to: 95 by: 1 yearEnds . evaluate: [ ^date print: 15 ; #-- print the evaluation date exchangeRate print ; #-- print value of ts doubleIt printNL ; #-- print value of calculation ] ; ] ;You should see the result:
12/31/1993 1.20 2.40 12/31/1994 2.30 4.60 12/31/1995 3.40 6.80Notice that both the time series property and the method that references this property are both automatically evaluated as of each date in the range. In this program, there is no obvious difference between the exchangeRate message and the doubleIt message even though one refers to a time series property and the other refers to a method. When Vision evaluates a method as of a date, all data required by the method is accessed as of that date. As a result, you usually do not need to know whether the message being sent is a method or a property.
Messages such as asOf: also work with methods. For example:
Named Currency USD :doubleIt asOf: 94 .In this case, all data required by the doubleIt method is accessed as of 12/94. Many messages work interchangeably with time series and methods including: asOf:, lag:, changeLag:, pctChangeLag, extractForDateRange: and aveForDateRange:. Certain operations are only meaningful in conjunction with pure time series data. For example:
Named Currency USD :doubleIt displayAlldisplays:
*** Message Is Not A Time Series *** Defined As: ===> [|doubleIt| exchangeRate * 2 ]Since doubleIt is not really a time series and can be evaluated as of any point in time, you cannot display all its values. Instead, the displayAll message displays the definition of the method.
A method is a program that can be evaluated as of any date. Actual data is stored in a time series, whereas no data is actually stored in a method. Therefore messages such as asOf:put: are only meaningful for time series. For example:
Named Currency USD :doubleIt asOf: 93 put: 1000 ;generates the warning:
>>> Selector 'asOf:put:' Not Found <<<Similarly the messages count, firstDate, lastDate, effectiveDate, and nextDate are only meaningful for actual TimeSeries objects.
To determine if an object is a method or time series, print out its value. If it is a method, Vision will display the method definition; otherwise the message aTimeSeries will be displayed. For example:
"---> exchangeRate" printNL ; Named Currency USD :exchangeRate printNL ; "---> doubleIt" printNL ; Named Currency USD :doubleIt printNL ;
The message extractForDateRange: can be used to convert a method into a time series with values for each point in the date range. For example:
!dr <- 94 to: 95 by: 1 yearEnds ; Named Currency USD :doubleIt extractForDateRange: dr . displayAll ;The message extract:for: is used to evaluate a block for an object over a date range, returning a TimeSeries object. For example:
94 to: 95 by: 1 yearEnds . extract: [ usExchange ] for: Named Currency CADreturns a time series of two year-end exchange rates for the Canadian currency.
TimeSeries and Properties
TimeSeries objects are available in two distinct forms in Vision:
- As properties created with the define: message.
- As stand-alone objects.
The expression:
Currency define: 'tsProperty' ;creates a new time series property for the class Currency. The expression:
Named Currency USD :tsPropertyretrieves this property for the US currency as a TimeSeries object. The expressions:
!newTS <- TimeSeries new ;and
!newTS <- Named Currency USD :tsPropety extractForDateRange: (88 to: 90 by 1 years) ;both create stand-alone TimeSeries objects. The expression:
newTSretrieves this object. These two forms of TimeSeries object respond identically to the same set of messages. They differ only in the manner in which they are accessed.
By default, a property is evaluated as of the current date. To access the time series itself, you need to place the : character in front of the property name. In this case the message :tsProperty returns the TimeSeries object which respond to all the time series messages. The stand-alone TimeSeries objects respond to time series messages by default. In other words, they do not require the initial : character. The value message is sent to a time series to evaluate it as of the current date. This message is automatically sent when you access a property without the initial :. It is required if you want a stand-alone time series to return one of its values.
Some examples should help clarify these distinctions:
#-- define property and stand-alone time series Currency define: 'tsProperty' ; !newTS <- TimeSeries new ; #-- populate values Named Currency USD :tsProperty asOf: 88 put: 880 ; Named Currency USD :tsProperty asOf: 89 put: 890 ; Named Currency USD :tsProperty asOf: 90 put: 900 ; newTS asOf: 9501 put: 1 ; newTS asOf: 9502 put: 2 ; #-- Print the most recent value Named Currency USD tsProperty print ; newTS value printNL ; #- need value #--- Print the 1989 value Named Currency USD :tsProperty asOf: 89 . print ; #- need : 89 evaluate: [ Named Currency USD tsProperty print ] ; newTS asOf: 89 . print ; #- no : 89 evaluate: [ newTS value printNL ] ; #- need value #-- Count the elements in the time series Named Currency USD :tsProperty count print ; #- need : newTS count printNL ; #- no :
High Frequency TimeSeries
Prior to release 6 of Vision, only values of the class Date could be used to index a TimeSeries object. This constraint was relaxed in release 6 which has been provided to new users and available as an upgrade since January 1998.
A new abstract class, Time, containing the two subclasses LowResolutionTime and HighResolutionTime have been added to the database to support higher resolution time indexing. Instances of LowResolutionTime can record timestamps to the micro-second (i.e., 1e-6, 0.000001 seconds) and instances of HighResolutionTime can record timestamps to the femto-second (i.e., 1e-15, 0.000000000000001 seconds).
Creating a high frequency time series requires that you supply an extra parameter indicating the resolution you wish when you create the property. For example, to define a property for tracking real-time prices at security, you could use the expression:
Security define: 'rtPrice' withTimeIndex: LowResolutionTime ;You can continue to use the asOf:put: message to update high frequency time series. The first parameter can be supplied in the form:
yyyymmdd.hhmmssssto include both the date and time components. For example, to update IBM's price as of 3:03 pm on April 14, 2000, use:
Named Security IBM :rtPrice asOf: 20000414.1503 put: 102.25 ;You can continue to use the asOf: message to access a high frequency time series. For example:
#-- get the most recent price Named Security IBM rtPrice printNL ; #-- get the price as of 4pm on 4/14/2000 Named Security IBM :rtPrice asOf: 20000414.16 . printNL ; #-- get the end of date price on 4/14/2000 Named Security IBM :rtPrice asOf: 20000414 . printNL ;You can continue to use the standard Collection messages such as do: to access the entire time series:
Named Security IBM :rtPrice do: [ ^date print ; printNL ; ] ;
When a time series object is indexed by time, it responds to the messages hours, minutes, and seconds as well as the messages year, month, and day. For example:
Named Security IBM :rtPrice do: [ ^date asDate print: 12 ; ^date hours print ; ^date minutes print; ^date seconds print ; printNL ; ] ;
The asNumber message can be sent to a Time object to convert it into a decimal number where the integer portion of the number represents the date in YYYYMMDD format and the decimal portion of the number represents the time component in HHMMSSSS format. The message formatAsTimeStamp can be sent to a Time object to format the date and time components in a standard way.
The messages countSecondsTo:, countMinutesTo:, and countHoursTo: can be used to compute the nubmer of seconds, minutes, or hours between two time points.
Related Topics
- Messages
- Class XRef
- The Collection Classes
- The Date Class
- Using TimeSeries
- The Collection Classes
- Creating Dates and DateOffsets
- Dates and TimeSeries Data
- Date Arithmetic
- The DateRange Class
- When to Iterate
- Clustering Issues
- Vision Tutorial: Using TimeSeries
- Technical Paper: Time is not a Time Series
- Technical Paper: Sets Do More Than Select
- Class XRef