
Usual operations on time series are enclosed in the definition of the class.
It concerns, for instance, binary operators between time series, like +, -, * or
unary transformation like exp, log, power, moving average/median, ...
Some important points should be noted:
References:
- NbbUtilities.dll
- NbbTs.dll
Code:
using Nbb.TimeSeries.SimpleTS;
...
double[] data = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
TS s1 = new TS(TSFrequency.Monthly, 2000, 0, data);
TS s2 = new TS(TSFrequency.Monthly, 2001, 0, data);
TS s3 = new TS(TSFrequency.Monthly, 2000, 2, data);
TS s4 = new TS(TSFrequency.Quarterly, 2000, 0, data);// usual binary operators.
TS emptysum = s1 + s2;
TS invaliddiff = s1 - s4; // invaliddiff is null
TS validprod = s1 * s3; // validprod is defined between (2000,2) and (2000, 9). validprod.Values={3, 8, 15, ...}// concatenation
TS chain = s2.Update(s1);// unary transformations
double[] weights=new double[]{0.25, 0.25, 0.5};
TS ma = s1.MovingAverage(weights, false, false);
TS log = s2.Log();
// Transformation of an existing series.
log.Values.Exp();
// complex operation
TS x = s4.Lag(2) * chain.ChangeFrequency(TSFrequency.Quarterly, Nbb.TimeSeries.TSAggregationType.Max, false);
References:
- NbbUtilities.dll
- NbbTs.dll
Code:
Imports Nbb.TimeSeries
Imports Nbb.TimeSeries.SimpleTS...
Dim data() As Double
data = New Double() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Dim s1 As New TS(TSFrequency.Monthly, 2000, 0, data)
Dim s2 As New TS(TSFrequency.Monthly, 2001, 0, data)
Dim s3 As New TS(TSFrequency.Monthly, 2000, 2, data)
Dim s4 As New TS(TSFrequency.Quarterly, 2000, 0, data)
Dim emptysum As TS
Dim invaliddiff As TS
Dim validprod As TS
Dim chain As TS
Dim weights() As Double
Dim ma As TS
Dim log As TS
Dim x As TS'usual binary operators.
emptysum = s1 + s2
invaliddiff = s1 - s4 'invaliddiff is null
validprod = s1 * s3 'validprod is defined between (2000,2) and (2000, 9). validprod.Values={3, 8, 15, ...}
'concatenation
chain = s2.Update(s1)'unary transformations
weights = New Double() {0.25, 0.25, 0.5}
ma = s1.MovingAverage(weights, False, False)
log = s2.Log()'Transformation of an existing series.
log.Values.Exp()'complex operation
x = s4.Lag(2) * chain.ChangeFrequency(TSFrequency.Quarterly, Nbb.TimeSeries.TSAggregationType.Max, False)
You can download an XLS file with the example code here (requires the installation off the last full package with the COM interfaces (10/2006)).
References:
- nbbutilities.tlb
- nbbts.tlb
Code:
'Ts construction
Dim s1 As NbbTs.TS
Dim s2 As NbbTs.TS
Dim s3 As NbbTs.TS
Dim s4 As NbbTs.TS
Dim dc1 As New NbbTs.TSDataCollector
Dim dc2 As New NbbTs.TSDataCollector
Dim dc3 As New NbbTs.TSDataCollector
Dim dc4 As New NbbTs.TSDataCollector
Dim i As Integer
For i = 2 To 11
dc1.AddObservation Cells(i, 1), Cells(i, 2)
dc2.AddObservation Cells(i, 4), Cells(i, 5)
dc3.AddObservation Cells(i, 7), Cells(i, 8)
dc4.AddObservation Cells(i, 10), Cells(i, 11)
Next i
Set s1 = dc1.Make(TSFrequency_Undefined, TSAggregationType_None)
Set s2 = dc2.Make(TSFrequency_Undefined, TSAggregationType_None)
Set s3 = dc3.Make(TSFrequency_Undefined, TSAggregationType_None)
Set s4 = dc4.Make(TSFrequency_Undefined, TSAggregationType_None)
'Ts operations
Dim emptysum As NbbTs.TS
Dim invaliddiff As NbbTs.TS
Dim validprod As NbbTs.TS
Dim chain As NbbTs.TS
Dim log As NbbTs.TS
Dim x As NbbTs.TS
'usual binary operators.
Set emptysum = s1.Plus(s2)
Set invaliddiff = s1.Minus(s4) ' invaliddiff is null
Set validprod = s1.Times(s3) 'validprod is defined between (2000,2) and (2000, 9). validprod.Values={3, 8, 15, ...}
'concatenation
Set chain = s2.Update(s1)
'unary transformations
Set log = s2.log()
'Transformation of an existing series.
Set x = s4.Lag(2).Times(chain.ChangeFrequency(TSFrequency_Quarterly, TSAggregationType_Max, False))