Can't colour a 3D map?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Walter Roberson
le 5 Fév 2014
By default surf() already colors according to Z axis value.
2 commentaires
Walter Roberson
le 5 Fév 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.
Voir également
Catégories
En savoir plus sur Blue dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!