Reverse order of X axis
이전 댓글 표시
Hi everybody, I'm trying to plot the price of an option against time to expiration time in days (in positive integer ofc). But I need to reverse the time. More specifically, I have 15 daily prices so what I did was building a vector from 0 to 15 and use flipr to reverse the order of my raw vector but it doesn't work because also the price of the option was reversed.
Exp = [0:15]; %days to expiration
P = rand(1,15); %fake daily prices
plot(Exp,P) %is all reversed not just the days to expiration
I also tried with set Xdir as follows
Exp = [0:15]; %days to expiration
P = rand(1,15); %fake daily prices
plot(Exp,P)
set(gca, 'Xdir', 'reverse') %again is all reversed not just the days to expiration
Does anyone have a solution to this issue?
Thanks a lot in advace,
Best,
Marco.
댓글 수: 9
Let's say that P started at 10 for Exp of 0 and increased to 30 for Exp=15. What would you like the data and x axis tick marks to look like?
Exp = 0:15; % Days to expiration
P = linspace(10, 30, length(Exp)); % Fake daily prices increasing
plot(Exp,P, 'b.-')
% set(gca, 'Xdir', 'reverse') %again is all reversed not just the days to expiration
Marco Piazza
2022년 6월 23일
편집: Marco Piazza
2022년 6월 23일
Image Analyst
2022년 6월 23일
OK, so the 15 would be at the left and 0 at the right. But the Exp that goes with 15 is 30. So do you want that at the left too? If you just reverse the tickmarks, then the value of Exp at the "0" tickmark will be the value of Exp that is associated with 15.
Marco Piazza
2022년 6월 23일
편집: Marco Piazza
2022년 6월 23일
Image Analyst
2022년 6월 23일
I'm still confused, as that would be confusing and not match up with the data.
Please give some monotonic data that shows price and days to expiration. Not random numbers, but something like I did. So Exp is days to expiration, and the P vector is the price at the corresponding element. Like for element 1, price is 100 and Exp is 0, for element #2 price is 110 and Exp is 4 days, or whatever. I think having the random numbers in there is making it difficult to see what's being plotted and whether it's flipped left-to-right or not.
Jan
2022년 6월 23일
@Marco Piazza: This is not twitter. We do not use # before the tags.
Exp = 0:15; % Days to expiration
P = linspace(10, 30, length(Exp)); % Fake daily prices increasing
y=plot(Exp,P, 'b.-');
ax=xticklabels;
xticklabels(flip(ax))
Marco Piazza
2022년 6월 24일
편집: Marco Piazza
2022년 6월 24일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





