Products & Services Solutions Academia Support User Community Company

Learn more about Financial Toolbox   

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' or 'u': (Default) Returns the combined values of all merged objects.

'intersection' or 'i': 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

Example 1. Create three financial time series objects and merge them into a single object.

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)

ans = 
 
    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]%

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.

Example 2. Merging time series objects with different headers (series names).

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]

See Also

horzcat, vertcat

  


Free Interactive Computational Finance CD

View demos and recorded presentations led by industry experts.

Now On Demand
Network with industry peers and learn the latest applications of the leading software product for computational finance.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS