Can't colour a 3D map?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 5 de Feb. de 2014
By default surf() already colors according to Z axis value.
2 comentarios
Walter Roberson
el 5 de Feb. de 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.
Ver también
Categorías
Más información sobre Blue en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!