Hello,
I have been trying to convert fints functionality used in an existing code to timetable functionality as a future release will not support fints anymore.
I have replaced fints functions in the first attachment to timetable functions in the second attachment.
clear all
close all
dlGlobal;
load clnMktDataAll;
Data=mktData.h15;
Data(sum(isnan(Data),2)>=2,:) = [];
nonMsngH15=Data;
Data=mktData.ofIndDN ;
Data(sum(isnan(Data),2)>=4,:) = [];
nonMsngOFdn=Data;
Data=mktData.ofIndTAP ;
Data(sum(isnan(Data),2)>=4,:) = [];
nonMsngOFtap=Data;
Data=mktData.libor;
Data(sum(isnan(Data),2)>=8,:) = [];
nonMsngLibor=Data;
tsH15=fints(nonMsngH15(:,1),nonMsngH15(:,2:end));
tsOFtap=fints(nonMsngOFtap(:,1),nonMsngOFtap(:,3:end));
tsOFdn=fints(nonMsngOFdn(:,1),nonMsngOFdn(:,2:end));
tsLibor=fints(nonMsngLibor(:,1),nonMsngLibor(:,2:end));
newfts=merge(tsOFdn, tsOFtap, tsH15, tsLibor, 'DateSetMethod', 'intersection');
currSettle=newfts.dates;
clear newfts
The "fints" fuction used in the code above have been replaced with "timetable" in the code below.
clear all
close all
dlGlobal;
load clnMktDataAll;
Data=mktData.h15;
Data(sum(isnan(Data),2)>=2,:) = [];
nonMsngH15=Data;
TnonMsngH15=array2table(nonMsngH15);
th15=datetime(TnonMsngH15.nonMsngH151,'ConvertFrom','datenum');
ttH15=table2timetable(TnonMsngH15(:,2:end),'RowTimes',th15);
Data=mktData.ofIndDN ;
Data(sum(isnan(Data),2)>=4,:) = [];
nonMsngOFdn=Data;
TnonMsngOFdn=array2table(nonMsngOFdn);
tOFdn=datetime(TnonMsngOFdn.nonMsngOFdn1,'ConvertFrom','datenum');
ttOFdn=table2timetable(TnonMsngOFdn(:,2:end),'RowTimes',tOFdn);
Data=mktData.ofIndTAP ;
Data(sum(isnan(Data),2)>=4,:) = [];
nonMsngOFtap=Data;
TnonMsngOFtap=array2table(nonMsngOFtap);
tOFtap=datetime(TnonMsngOFtap.nonMsngOFtap1,'ConvertFrom','datenum');
ttOFtap=table2timetable(TnonMsngOFtap(:,3:end),'RowTimes',tOFtap);
Data=mktData.libor;
Data(sum(isnan(Data),2)>=8,:) = [];
nonMsngLibor=Data;
TnonMsngLibor=array2table(nonMsngLibor);
tLibor=datetime(TnonMsngLibor.nonMsngLibor1,'ConvertFrom','datenum');
ttLibor=table2timetable(TnonMsngLibor(:,2:end),'RowTimes',tLibor);
newTT = synchronize(ttOFdn,ttOFtap,ttH15,ttLibor);
currSettle=newTT.Time;
clear newTT
However, I have encountered other problems in replacing the fints functionality with the timetable functionality.
First problem is that, I would like to change the sub function of fints, 'merge', to 'synchronize,' which occurs to me that it is an equivalent sub-function in timetable, and I would like to keep the 'intersection' option for the replaced timetables as well. However, it appears that there is no option like 'intersection' for 'synchronize.' So my questions is, is there any way I can combine the timetable data only if the dates for the different timetable data overlap?(Just like using merge with intersection option.)
Second problem comes from the different formats in fints and timetable. I figured out that fints uses the array format, while timetable uses the table format. The problems takes place when using the loop functions to generate hiscurveAlgn, histCapVolAlgn, histSwpVolAlgn, currSettle, SwpVolSettle, CapVolSettle, TimeToMat, and Tickers. The original program was written to work out with the array format (fints format) and it runs into errors as the earlier part of the program is now written in the table format, not array format. I was wondering if you could correct these loops so that they can work out with table format to generate aforementioned output.
for k = 1:length(TimeToMat.ofIndDN)
tmp = num2str(TimeToMat.ofIndDN(k));
addnull=4-length(tmp);
tmp=[repmat('_', 1, addnull) tmp];
namesDN(k,:)= genvarname(tmp);
end
tsOFDN=fints(nonMsngOFdn(:,1),nonMsngOFdn(:,2:end), cellstr(namesDN));
for k = 2:length(TimeToMat.ofIndTAP)
tmp = num2str(TimeToMat.ofIndTAP(k));
addnull=6-length(tmp);
tmp=[repmat('_', 1, addnull) tmp];
namesTAP(k-1,:)= genvarname(tmp);
end
tsOFTAP=fints(nonMsngOFtap(:,1),nonMsngOFtap(:,3:end), cellstr(namesTAP));
newftsDN = tsOFDN(datestr(currSettle));
newftsTAP = tsOFTAP(datestr(currSettle));
newftsOF=merge(newftsDN, newftsTAP, 'DateSetMethod', 'intersection','SortColumns',0);
mktData.ofInd=[newftsOF.dates fts2mat(newftsOF)];
TimeToMat.ofInd=[TimeToMat.ofIndDN TimeToMat.ofIndTAP(2:end)];
tmpTypes=[origRateTypes {'EDHAlligned' 'EDMAlligned' 'EDUAlligned' 'EDZAlligned'}];
for idx=1:length(tmpTypes)
currtab=char(tmpTypes(idx));
s1= ['histCurveAlgn' '.' currtab];
s2= ['mktData' '.' currtab];
evalc([s1 '=NaN(size(currSettle,1), size(' s2 ',2)-1)']);
end
for jdx=1:length(currSettle);
for idx=1:length(tmpTypes)
currtab=char(tmpTypes(idx));
s1= ['histCurveAlgn' '.' currtab];
s2= ['mktData' '.' currtab];
evalc(['tmpIdx=find(' s2 '(:,1)==currSettle(jdx))']);
if length(tmpIdx)>0
evalc([s1 '(jdx,:)=' s2 '((tmpIdx),2:end)']);
end
clear tmpIdx;
end
end
Data=mktData.swaption7X;
Data(sum(isnan(Data),2)>4,:)=[];
SwpVolSettle=sortrows(Data(:,1));
for idx=1:length(swaptionTypes)
currtab=char(swaptionTypes(idx));
s1= ['histSwpVolAlgn' '.' currtab];
evalc([s1 '=NaN(length(SwpVolSettle),length(TimeToMat' '.' currtab '))' ]);
s2= ['mktData' '.' currtab];
for jdx=1:length(SwpVolSettle);
evalc(['tmpIdx=find(' s2 '(:,1)==SwpVolSettle(jdx))']);
if length(tmpIdx)>0
evalc([s1 '(jdx,:)=' s2 '((tmpIdx),2:end)']);
end
clear tmpIdx;
end
end
Data=mktData.strike1Vol;
Data(sum(isnan(Data),2)>4,:)=[];
CapVolSettle=sortrows(Data(:,1));
for idx=1:length(capTypes)
currtab=char(capTypes(idx));
s1= ['histCapVolAlgn' '.' currtab];
evalc([s1 '=NaN(length(CapVolSettle),length(TimeToMat' '.' currtab '))' ]);
s2= ['mktData' '.' currtab];
for jdx=1:length(CapVolSettle);
evalc(['tmpIdx=find(' s2 '(:,1)==CapVolSettle(jdx))']);
if length(tmpIdx)>0
evalc([s1 '(jdx,:)=' s2 '((tmpIdx),2:end)']);
end
clear tmpIdx;
end
end
In summary, I would like to replace merge with synchronize but keep the intersection option.
And I would like the loops in the program to work out with the table format, which now only work out with the array format.
Thank you for your answer and time in advance.
PS. The Program was written by Alex Bogin on 10/17/18.