Code covered by the BSD License  

Highlights from
Financial Seminar Demos

Financial Seminar Demos

by

 

02 Mar 2004 (Updated )

Demos commonly used at The MathWorks financial modeling seminars.

blsvis(varargin)
function varargout = blsvis(varargin)
% BLSVIS M-file for blsvis.fig
%      BLSVIS, by itself, creates a new BLSVIS or raises the existing
%      singleton*.
%
%      H = BLSVIS returns the handle to a new BLSVIS or the handle to
%      the existing singleton*.
%
%      BLSVIS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in BLSVIS.M with the given input arguments.
%
%      BLSVIS('Property','Value',...) creates a new BLSVIS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before blsvis_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to blsvis_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help blsvis

% Last Modified by GUIDE v2.5 15-Aug-2002 13:54:17

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @blsvis_OpeningFcn, ...
                   'gui_OutputFcn',  @blsvis_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before blsvis is made visible.
function blsvis_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to blsvis (see VARARGIN)

% Choose default command line output for blsvis
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes blsvis wait for user response (see UIRESUME)
% uiwait(handles.figure1);

view(3)
grid on
xlabel('Stock Price ($)');
ylabel('Time (months)');
zlabel('Gamma');
title('Call Option Sensitivity Measures');

colorbar('horizontal')

set(handles.rotatemen,'checked','off')

% --- Outputs from this function are returned to the command line.
function varargout = blsvis_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes during object creation, after setting all properties.
function strike_CreateFcn(hObject, eventdata, handles)
% hObject    handle to strike (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function strike_Callback(hObject, eventdata, handles)
% hObject    handle to strike (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of strike as text
%        str2double(get(hObject,'String')) returns contents of strike as a double


% --- Executes during object creation, after setting all properties.
function vol_CreateFcn(hObject, eventdata, handles)
% hObject    handle to vol (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function vol_Callback(hObject, eventdata, handles)
% hObject    handle to vol (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of vol as text
%        str2double(get(hObject,'String')) returns contents of vol as a double


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

filenum = get(handles.datafile,'value');
% filedes = get(handles.datafile,'string');

if filenum == 2;
   file = 'blsdata2';
else
   file = 'blsdata1';
end

Range = [];
Color = [];
j=[];
ZVal=[];
load(file)

strikep = get(handles.strike,'string');
strikep = str2num(strikep);

vol = get(handles.vol,'string');
vol = str2num(vol);

ZVal = blsgamma(NewRange, strikep*Pad, vol*Pad, Newj, 0.35*Pad);
Color = blsdelta(NewRange, strikep*Pad, vol*Pad, Newj, 0.35*Pad);

% ax = findobj(gcf,'type','axes');
% set(ax,'vis','on')

cla
mesh(Range, j, ZVal, Color);
xlabel('Stock Price ($)');
ylabel('Time (months)');
zlabel('Gamma');
title('Call Option Sensitivity Measures');
axis([min(Range) max(Range) 1 max(j)  -inf inf]);

%set(gca, 'box', 'on');
cbar = colorbar('horiz');
a = findobj(gcf, 'type', 'axes');
set(get(cbar, 'xlabel'), 'string', 'Delta');

% --- Executes during object creation, after setting all properties.
function datafile_CreateFcn(hObject, eventdata, handles)
% hObject    handle to datafile (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on selection change in datafile.
function datafile_Callback(hObject, eventdata, handles)
% hObject    handle to datafile (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns datafile contents as cell array
%        contents{get(hObject,'Value')} returns selected item from datafile


% --------------------------------------------------------------------
function viewmen_Callback(hObject, eventdata, handles)
% hObject    handle to viewmen (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function rotatemen_Callback(hObject, eventdata, handles)
% hObject    handle to rotatemen (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

rotonoff = get(hObject,'checked');

if strcmp(rotonoff,'on')
    rotate3d off
    set(hObject,'checked','off')
else
    rotate3d on
    set(hObject,'checked','on')
end
    

Contact us