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
Marco Piazza 2022년 6월 23일
편집: Marco Piazza 2022년 6월 23일
Hi and thank for your answer. I just need to reverse the order of days: exactly like your graph but with decreasing days from 15 to 0. When I tried, I always got a graph with reversed prices to (in your example from 30 to 10).
Image Analyst
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
Marco Piazza 2022년 6월 23일
편집: Marco Piazza 2022년 6월 23일
Yes, this is exactly what I need. I need days to expiration and NOT days from expiration.
Image Analyst
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.
I'll try to be clearer with a practical example using your previous codes.
Exp = 0:15; % Days to expiration
P = linspace(10, 30, length(Exp)); % Fake daily prices increasing
plot(Exp,P, 'b.-')
In this specific case at day 0 the price of the option (or anything else) is 10, the 5th day the price is 15 and so on... To make the graph more comprehensible (since I'm talking about expiration time) I need to reverse the days (from 15 to 0) and this is what I tried
Exp = 0:15; % Days to expiration
P = linspace(10, 30, length(Exp)); % Fake daily prices increasing
plot(Exp,P, 'b.-')
set(gca,'Xdir','reverse')
As you can see, the order of the X axis changed but the associated values are still the same.
In this case (since we are creating our own prices series) i could get what I need just doing this
Exp = 0:15; % Days to expiration
P = linspace(10, 30, length(Exp)); % Fake daily prices increasing
plot(Exp,P, 'b.-')
set(gca,'Xdir','reverse')
But in my "real" case the prices are ofc given, and I cannot change the order. Also applying fliplr to one between prices or days the same problem occur.
PS: I know it is not easy to undestand without my data but I hope this time I made my self more clear. Thanks again.
Marco
Jan
Jan 2022년 6월 23일
@Marco Piazza: This is not twitter. We do not use # before the tags.
Something like this @Marco Piazza?
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
Marco Piazza 2022년 6월 24일
편집: Marco Piazza 2022년 6월 24일
Yes man, this what exactly what I ment. Thanks a lot, and thanks to all of you!!! Anserw the question so that I can accept it!!!!

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

 채택된 답변

Dyuman Joshi
Dyuman Joshi 2022년 6월 24일

1 개 추천

Building on @Image Analyst's comment, reversing the x-tick labels
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))

댓글 수: 2

Marco Piazza
Marco Piazza 2022년 6월 24일
Thank man, it worked!
Dyuman Joshi
Dyuman Joshi 2022년 6월 24일
You are welcome!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2022년 6월 23일

댓글:

2022년 6월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by