Can't colour a 3D map?
10 views (last 30 days)
Show older comments
Please help, I have got the 3D graph, and I want to colour it according to its Z-axis value.
%------------------------------------------------------------------------------------------------------
%Function:
function C = bs ( Interest, Volatility, Stock, StrikePrice, TimeToMaturity )
d1 = (log(Stock ./ StrikePrice) + (Interest + (Volatility .^ 2) ./ 2) .* TimeToMaturity) ./ (Volatility .* sqrt(TimeToMaturity));
d2 = (log(Stock ./ StrikePrice) + (Interest - (Volatility .^ 2) ./ 2) .* TimeToMaturity) ./ (Volatility .* sqrt(TimeToMaturity));
C = normcdf(d1) .* Stock - normcdf(d2) .* StrikePrice .* exp(-Interest .* TimeToMaturity);
end
%------------------------------------------------------------------------------------------------------
%Code:
stock = 0 : 0.01 : 1100;
time = 0/52 : 1/52 : 9/52;
[X, Y] = meshgrid(stock, time);
Z = bs(0.05, 1.13, X, 800, Y);
surf(X, Y, Z)
colormap hsv
colorbar
xlabel('Stock Price')
ylabel('Time')
zlabel('Option Price')
grid on
%------------------------------------------------------------------------------------------------------
Thank you very much!
0 Comments
Answers (1)
Walter Roberson
on 5 Feb 2014
By default surf() already colors according to Z axis value.
2 Comments
Walter Roberson
on 5 Feb 2014
Sorry I do not have the Stats toolbox to test the code with.
Does the same problem occur if you leave out the "colormap" command?
Is your surface showing up flat? If it is then your Z might be constant.
See Also
Categories
Find more on Blue in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!