Import options & loops for time series data
Afficher commentaires plus anciens
Hi! I have two question. The first is about data importing. Using the "Dati BTP e BOT" dataset, I would like to set the row 8 (it refers to variable "Maturity) and column A (from row 9) as datetime and other cells have to be numbers, but in the editor there aren't ways to change this values for cells in particulare (it's possible change the first row only). Any suggestion?
As second question, I extracted a cross section of "Dati BTP e BOT" as in "test 25ago2022" file. In this I estimate parametes of Nelson-Siegel model (it's a financial model, but this isn't the point) using the following code:
%% Import data from spreadsheet
% Script for importing data from the following spreadsheet:
%
% Workbook: C:\Users\William\Desktop\test 25ago2022.xlsx
% Worksheet: 25ago2022
%
% Auto-generated by MATLAB on 30-Aug-2022 12:38:18
%% Set up the Import Options and import the data
opts = spreadsheetImportOptions("NumVariables", 3);
% Specify sheet and range
opts.Sheet = "25ago2022";
opts.DataRange = "A2:C95";
% Specify column names and types
opts.VariableNames = ["CouponRate", "Maturity", "Prezzo"];
opts.VariableTypes = ["double", "datetime", "double"];
% Specify variable properties
opts = setvaropts(opts, "Maturity", "InputFormat", "");
% Import the data
tbl = readtable("C:\Users\William\Desktop\test 25ago2022.xlsx", opts, "UseExcel", false);
%% Convert to output type
CouponRate = tbl.CouponRate;
Maturity = tbl.Maturity;
Prezzo = tbl.Prezzo;
%% Clear temporary variables
clear opts tbl
Settle = repmat(datenum('25-ago-2022'),[94,1]);
Maturity = datenum(Maturity(:,1));
CleanPrice = Prezzo(:,1);
CouponRate = CouponRate(:,1);
Instruments = [Settle Maturity CleanPrice CouponRate];
PlottingPoints = datenum(Maturity(1,1)):1:datenum(Maturity(94,1));
Yield = bndyield(CleanPrice,CouponRate,Settle,Maturity);
NSModel = IRFunctionCurve.fitNelsonSiegel('Zero',datenum('25-ago-2022'),Instruments,'InstrumentBasis',3,'InstrumentEndMonthRule',0);
NSModel.Parameters
SvenssonModel = IRFunctionCurve.fitSvensson('Zero',datenum('25-ago-2022'),Instruments);
SvenssonModel.Parameters
figure1 = figure('WindowState','maximized','Color',[1 1 1]);
plot(PlottingPoints, getParYields(SvenssonModel, PlottingPoints),'r','Color',[0 0 0],'LineWidth',0.7)
hold on
scatter(Maturity,Yield,'black',Marker='*')
datetick('x')
xlabel('Scadenza','Interpreter','latex');
ylabel('Tasso di interesse','Interpreter','latex');
set(gca,'FontSize',15,'TickLabelInterpreter','latex')
Are there ways to use this code to estimate the parameters automatically for the entire time series and get the daily output as a dataset? Using the for construct is the solution probably but I'm sure I'd some problems in defining the "settle" variable.
I hope it's clear what I mean.
1 commentaire
dpb
le 30 Août 2022
"I would like to set the row 8 (it refers to variable "Maturity) and column A (from row 9) as datetime and other cells have to be numbers,"
We can't always have what we want...no, you can't have one row in a table be a different data class/type than the others unless the whole column is a cell array containing the various types in the cell. This is possible, but then makes using the table awkward at best because then must dereference the cell every time to get to the content within the cell.
The ideal solution would be to create a corollary variable for each that is the maturity date, coupon rate, etc., ...then you have all the data for everything but at the expense of memory for the axiliary variables.
Probably the better way with these data would be to create an auxiliary table that contains these data for each issue and retrieve it by name/code; whichever it is you're using as the primary reference. The issue name is extremely long and convoluted to use as a practical name but the code ID is non-mnemonic in order to know to which one is referring to; the names are just built up from the metadata, anyways, however, so lookup manually may not be an issue, anyways; you may just process them all and then spit out those of interest by the computed metric, maybe???
I don't understand the second question, sorry...you mean to process all series/issues, not just one, maybe?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!