A surface chart of call option values shaded by vega is rendered. The X, Y, and Z axes represent Stock Price, Time, and Option Value respectively.
import com.imsl.chart3d.*; import com.imsl.chart.Colormap; import com.imsl.math.ZeroFunction; import com.imsl.stat.Cdf; import java.awt.Color; /** * Surface chart of call option value shaded by vega. */ public class SurfaceEx1 extends JFrameChart3D { /** * Creates new form CallOptionSurface */ public SurfaceEx1() { Chart3D chart = getChart3D(); chart.setTextFormat("0.0000"); AxisXYZ axis = new AxisXYZ(chart); axis.setAxisTitlePosition(axis.AXIS_TITLE_PARALLEL); axis.setTextFormat("0.0"); axis.getAxisX().getAxisTitle().setTitle("Stock Price"); axis.getAxisY().getAxisTitle().setTitle("Time"); axis.getAxisZ().getAxisTitle().setTitle("Option Value"); double strike = 20.0; double rate = 0.045; double sigma = 0.25; CallOption callOption = new CallOption(strike, rate, sigma); double minStock = 0.0; double maxStock = 2.0 * strike; double minTime = 0.0; double maxTime = 1.0; Surface surface = new Surface(axis, callOption, minStock, maxStock, minTime, maxTime); surface.setColorFunction(callOption); surface.setSurfaceType(Surface.SURFACE_TYPE_MESH | Surface.SURFACE_TYPE_NICEST); ColormapLegend colormapLegend = new ColormapLegend(chart, Colormap.RED_TEMPERATURE, -10., 60.); colormapLegend.setTitle("Vega"); colormapLegend.setTextFormat("0.00"); colormapLegend.setNumber(25); colormapLegend.setAutoscaleInput(colormapLegend.AUTOSCALE_WINDOW); colormapLegend.setAutoscaleOutput(colormapLegend.AUTOSCALE_NUMBER); this.setSize(375, 375); render(); } public class CallOption implements Surface.ZFunction, ColorFunction { private double strike, rate, sigma; /** * Compute call option value using the Black-Scholes formula. */ public CallOption(double strike, double rate, double sigma) { this.strike = strike; this.rate = rate; this.sigma = sigma; } public double f(double stock, double time) { double d1 = (Math.log(stock/strike)+(rate+0.5*sigma*sigma)*time)/(sigma*Math.sqrt(time)); double d2 = d1 - sigma*Math.sqrt(time); return stock*Cdf.normal(d1) - strike*Math.exp(-rate*time)*Cdf.normal(d2); } public double delta(double stock, double time) { double d1 = (Math.log(stock/strike)+(rate+0.5*sigma*sigma)*time)/(sigma*Math.sqrt(time)); return Cdf.normal(d1); } public double vega(double stock, double time) { double d1 = (Math.log(stock/strike)+(rate+0.5*sigma*sigma)*time)/(sigma*Math.sqrt(time)); return stock * Math.sqrt(time) * Cdf.normal(d1); } public Color color(double stock, double time, double optionValue) { double vega = vega(stock, time); double s = (vega + 10.0) / (60.0+10.); return Colormap.RED_TEMPERATURE.color(s); } } public static void main(String args[]) { new SurfaceEx1().setVisible(true); } }