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 で Financial Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





