Clear Filters
Clear Filters

Combining financial time series

3 views (last 30 days)
mctaff
mctaff on 1 Nov 2016
Edited: mctaff on 1 Nov 2016
Hello!
I'm struggling somewhat with the capability of the inbuilt financial time series object. I have two financial time series, covering the same start/end date range, however it is likely data may be missing from one, or both series. Is there any sensible way I can rebaseline the two series against the union of the date range?
e.g.
fts1 has values for 01/01, 02/01, 03/01, 04/01, 06/01... but has no data for 05/01
fts2 has values for 01/01, 02/01, 04/01, 05/01, 06/01... but has no data for 03/01
I want to rebase the two series, so they both cover the entire date sequence, i.e. 01/01, to 06/01 inclusive
I'm current doing some messy manipulations along the lines of:
  • merge the two series - gives me the dates I want, but the data is rubbish, as missing data in one series will be filled with data from the other - not good!
  • create a NaN fints object, using an appropriately sized NaN matrix, with the extracted dates and column names from the merged matrix
  • remerge one series with the NaN series - now I get the data I want in there, against the full date range
  • use fillts(..., 'zero') - fills in blanks in the data with previous value
repeat the last 2 steps, with the other series.
... but I'm sure there must be a cleaner way to do this!
Here's the code:
columnNames = fieldnames(fts1, 1)';
tempFts = merge(fts1, fts2, 'SortColumns', '0');
tempData = nan(length(tempFts), length(columnNames));
datetimes = getfield(tempFts, 'dates') + getfield(tempFts, 'times');
tempFts = fints(datetimes, tempData, columnNames);
i1 = fillts(merge(tempFts, fts1, 'SortColumns', '0'), 'zero');
i2 = fillts(merge(tempFts, fts2, 'SortColumns', '0'), 'zero');

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!