日期处理


% Trdmnt 'YYY-MM' Categorical类型转为 yyyymm 数值型 
TRDCnmont = TRD_Cnmont(TRD_Cnmont.Markettype ==5,:);
TRDCnmont.ym = datestr(string(TRDCnmont.Trdmnt),'yyyy-mm');
TRDCnmont.ym = year(TRDCnmont.ym)*100 + month(TRDCnmont.ym);
TRDCnmont = TRDCnmont(:,[12 5]); % 重新排列数据列顺序

% 绘图前横坐标
Index = Index(Index.ym(:)>=201103 & Index.ym(:) <=202112,:);
yyyymm = Index.ym;
yyyymm(:,2) = floor(yyyymm(:,1)./100); % 年yyyy
yyyymm(:,3) = mod(yyyymm(:,1), 100);   % 月mm
dates = datenum([yyyymm(:,2:3),ones(size(yyyymm,1),1)]);
% 
figure;
plot(dates,Index(:,2),'LineWidth',2);
ax = gca;
ax.XTick = dates(1:24:end);
datetick('x','yyyy','keepticks')
xlabel('ym');
ylabel('Avg lambda');
axis tight;
recessionplot;
title('1996:01-2021:12')
posted @ 2022-08-28 23:14  Rae的笔记本  阅读(36)  评论(0)    收藏  举报