Documentation Center

  • Trial Software
  • Product Updates

merge

Merge multiple financial time series objects

Syntax

newfts = merge(fts1, fts2)
newfts = merge(fts1, fts2, ..., ftsx)
newfts = merge(fts1, fts2, ..., ftsx, 'PARAM1', VALUE1, 'PARAM2',
VALUE2, ...)

Arguments

fts1,
fts2, ...

Comma-separated list of financial time series objects to merge.

    Note   Multiple Financial Time Series objects can be merged at once. The merged objects must appear in a comma separated list before the optional inputs. The order of the inputs is significant.

'DateSetMethod'

(Optional) Merge method. Valid merge values are:

'union': (Default) Returns the combined values of all merged objects.

'intersection': Returns the values common to all merged objects.

RefObf: Maps all values to a reference time contained in a Financial Time Series object (RefObj) or vector of date numbers.

'DataSetMethod'

(Optional) Merge method. Valid merge values are:

'closest': (Default) Returns data based on the order of the inputs. However, the first missing data point (NaN value) of a date will be replaced by the closest non-NaN data point that appears on the same date of subsequent merged objects.

'order': Returns data based strictly on the order of the inputs.

'SortColumns'

(Optional) Sorts columns. Valid merge values are:

True/1: Sorts the columns based on the headers (series names). The headers are sorted in alphabetical order.

False/0: Columns are not sorted.

Description

newfts = merge(fts1, fts2, ..., ftsx, 'PARAM1', VALUE1, 'PARAM2', VALUE2', ...) merges multiple financial time series objects. The optional parameter and value pair argument specifies the values contained in the output financial time series object ftsout.

Examples

expand all

Create Three Financial Time Series Objects and Merge into a Single Object

Create three financial time series objects and merged into a new time series object t123.

dates = {'jan-01-2001'; 'jan-02-2001'; 'jan-03-2001'; ...
         'jan-04-2001'; 'jan-06-2001'};
data = [1; 1; 1; 1; 1];
t1 = fints(dates, data);

dates = {'jan-02-2001'; 'jan-03-2001'; 'jan-04-2001';
         'jan-05-2001'};
data = [2; 2; 2; 2];
t2 = fints(dates, data);

dates = {'jan-03-2001'; 'jan-04-2001'; 'jan-05-2001';
         'jan-06-2001'};
data = [3; 3; 3; 3];
t3 = fints(dates, data);

t123 = merge(t1, t2, t3)
 
t123 = 
 
    desc:   ||  || 
    freq:  Unknown (0)

    'dates:  (6)'    'series1:  (6)'
    '01-Jan-2001'    [            1]
    '02-Jan-2001'    [            1]
    '03-Jan-2001'    [            1]
    '04-Jan-2001'    [            1]
    '05-Jan-2001'    [            2]
    '06-Jan-2001'    [            1]

If you change the order of input time series, the output may contain different data when duplicate dates exist. Here, for example, is the result of using the same three time series defined above but with the order changed.

merge(t3, t2, t1)
 
ans = 
 
    desc:   ||  || 
    freq:  Unknown (0)

    'dates:  (6)'    'series1:  (6)'
    '01-Jan-2001'    [            1]
    '02-Jan-2001'    [            2]
    '03-Jan-2001'    [            3]
    '04-Jan-2001'    [            3]
    '05-Jan-2001'    [            3]
    '06-Jan-2001'    [            3]

t123 contains all 1's except on '05-Jan-2001' because t1 appears first in the list of inputs and takes precedence. The same logic can be applied to t321. By changing the order of inputs, you can overwrite old financial time series data with new data by placing the new time series ahead of the old one in the list of inputs to the merge function.

Merge Financial Time Series Objects with Different Headers (Series Names)

Merge time series objects with different headers into a new time series object t45.

dates = {'jan-01-2001'; 'jan-02-2001'; 'jan-03-2001'; ...
'jan-04-2001'; 'jan-06-2001'};
data = [1; 1; 1; 1; 1];
t4 = fints(dates, data, 'ts4');

dates = {'jan-02-2001'; 'jan-03-2001'; 'jan-04-2001'; 'jan-05-2001'};
data = [2; 2; 2; 2];
t5 = fints(dates, data, 'ts5');

t45 = merge(t4, t5)
 
t45 = 
 
    desc:   || 
    freq:  Unknown (0)

    'dates:  (6)'    'ts4:  (6)'    'ts5:  (6)'
    '01-Jan-2001'    [        1]    [      NaN]
    '02-Jan-2001'    [        1]    [        2]
    '03-Jan-2001'    [        1]    [        2]
    '04-Jan-2001'    [        1]    [        2]
    '05-Jan-2001'    [      NaN]    [        2]
    '06-Jan-2001'    [        1]    [      NaN]

Merge Two Financial Index Series and Keep Intersecting Dates

Merge two index series into the final merged object (t12) and keep the intersecting dates.

dates = {'jan-01-2001'; 'jan-02-2001'; 'jan-03-2001'; 'jan-04-2001'; 'jan-06-2001'};
data = [1; 1; 1; 1; 1];
t1 = fints(dates, data,'A')

dates = {'jan-02-2001'; 'jan-03-2001'; 'jan-04-2001'; 'jan-05-2001'};
data = [2; 2; 2; 2];
t2 = fints(dates, data,'B')

t12 = merge(t1, t2,'DateSetMethod','Intersection')
 
t1 = 
 
    desc:  (none)
    freq:  Unknown (0)

    'dates:  (5)'    'A:  (5)'
    '01-Jan-2001'    [      1]
    '02-Jan-2001'    [      1]
    '03-Jan-2001'    [      1]
    '04-Jan-2001'    [      1]
    '06-Jan-2001'    [      1]

 
t2 = 
 
    desc:  (none)
    freq:  Unknown (0)

    'dates:  (4)'    'B:  (4)'
    '02-Jan-2001'    [      2]
    '03-Jan-2001'    [      2]
    '04-Jan-2001'    [      2]
    '05-Jan-2001'    [      2]

 
t12 = 
 
    desc:   || 
    freq:  Unknown (0)

    'dates:  (3)'    'A:  (3)'    'B:  (3)'
    '02-Jan-2001'    [      1]    [      2]
    '03-Jan-2001'    [      1]    [      2]
    '04-Jan-2001'    [      1]    [      2]

See Also

|

Was this topic helpful?