Hello,
I am currently trying to plot some kind of term structure of Value at Risk estimates and I am struggling to fit the xticks correctly. My code correctly displays 500 days with the approriate spaces between the "days", but I don't get how to match my datapoints (6 in total) to the right period (i. e. 10 days estimate to 10 days point, 30 days estimate to 30 days point and so on). I tried a different approach with datetime, but then it is impossible to just display days and not specific dates.
TermStructure = [VaR1D; VaR10D; VaR30D; VaR125D; VaR1Y; VaR2Y]
x = linspace(0,500,length(TermStructure))
plot(x, TermStructure)
xticks([1 10 30 125 250 500])
Thanks a lot in advance for any suggestions.
Leo

 채택된 답변

dpb
dpb 2021년 2월 7일
편집: dpb 2021년 2월 7일

0 개 추천

x=[1 10 30 125 250 500];
plot(x,sort(randi(40,[6,1])),'*-')
xticks(0:100:500)
will duplicate the above with the addition of a marker at the datapoints instead of just the line segments. Salt to suit...

추가 답변 (1개)

dpb
dpb 2021년 2월 7일
편집: dpb 2021년 2월 7일

0 개 추천

"with datetime, but then it is impossible to just display days and not specific dates."
Au contraire, good buddy!
tt=array2timetable(rand(100,1),'RowTimes',datetime(date)+days(linspace(0,500)).'); % make up something
>> head(tt)
ans =
8×1 timetable
Time Var1
____________________ _______
07-Feb-2021 00:00:00 0.16931
12-Feb-2021 01:12:43 0.78235
17-Feb-2021 02:25:27 0.34228
22-Feb-2021 03:38:10 0.54597
27-Feb-2021 04:50:54 0.55591
04-Mar-2021 06:03:38 0.20465
09-Mar-2021 07:16:21 0.59334
14-Mar-2021 08:29:05 0.93012
>> figure; plot(tt.Time,tt.Var1) % and plot it
>> hAx=gca; % get axes handle
>> hAx.XAxis.TickLabelFormat % display default time axes format
ans =
'MMM u'
>> hAx.XAxis.TickLabelFormat='dd'; % set to days, two digits
yields
This time scale happens to have default tick spacing at beginnings of months so all are day one, but it shows only the day.
You may be wanting a duration here, not a date if is elapsed days since some point.
Then again, it isn't clear to me what "match my datapoints (6 in total) to the right period" really means, either; if it is that you have a set of calculations (6?) to some calculated time frame over which those were calculated, you may not want a time axes at all but simply an ordinal plot with labels to match the period lengths.
TermStructure = randi(300,[6,1]);
x=categorical({'1Day'; '10Days'; '30Days; '125Days'; '1Year'; '2Years'}, ...
{'1Day'; '10Days'; '30Days'; '125Days'; '1Year'; '2Years'},'ordinal',1));
plot(x, TermStructure)

댓글 수: 5

Leonard Meyer
Leonard Meyer 2021년 2월 7일
This might be what I'm looking for, but can you tell me what exactly you are doing in the line with "make something up"? I get the error, that you cannot plot timetables or something. I always struggle with anything related to datetime...
Thanks a lot so far!
Adam Danz
Adam Danz 2021년 2월 7일
It's not clear to me what the goal is or the type of data you're working with.
Do you want durations along the x axis? What determines those durations?
Leonard Meyer
Leonard Meyer 2021년 2월 7일
I definitely don't want a simple ordinal plot, since that defies the correct time proportions.
"You may be wanting a duration here, not a date if is elapsed days since some point". Elapsed days since day 0 would be it, I think.
I attached an excel solution below, but I would prefer it to be done in Matlab for future projects as well!
Leonard Meyer
Leonard Meyer 2021년 2월 7일
I'd like to plot 6 values for the Value at risk, that have been calculated via monte carlo simulation and refer to a specific time horizon each (10 days, 30 days...). So the x-axis should just have those 500 days with the correct proportions for the respective VaR estimates. I hope that makes it clearer, thanks again!
dpb
dpb 2021년 2월 7일
"what exactly you are doing in the line with "make something up"
Just created a dummy timetable with one variable over a time period of 100 entries spread out over 500 days. It was so had something to use in plot command below.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 2월 7일

편집:

dpb
2021년 2월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by