function varargout = blscalculator(varargin)
% blscalculator MATLAB code for blscalculator.fig
% blscalculator, by itself, creates a new blscalculator or raises the existing
% singleton*.
%
% H = blscalculator returns the handle to a new blscalculator or the handle to
% the existing singleton*.
%
% blscalculator('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in blscalculator.M with the given input arguments.
%
% blscalculator('Property','Value',...) creates a new blscalculator or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before blscalculator_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to blscalculator_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 blscalculator
% Last Modified by GUIDE v2.5 13-Oct-2010 17:17:35
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @blscalculator_OpeningFcn, ...
'gui_OutputFcn', @blscalculator_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(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 blscalculator is made visible.
function blscalculator_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 blscalculator (see VARARGIN)
% Choose default command line output for blscalculator
handles.output = hObject;
handles.price=str2double(get(handles.edit1,'String')) ;%returns contents of edit1 as a double
handles.strike=str2double(get(handles.edit2,'String')) ;%returns contents of edit2 as a double
handles.time=str2double(get(handles.edit3,'String')) ;%returns contents of edit3 as a double
handles.volatility=str2double(get(handles.edit4,'String')) ;%returns contents of edit4 as a double
handles.rate=str2double(get(handles.edit5,'String'));% returns contents of edit5 as a double
handles.yield=str2double(get(handles.edit6,'String'));% returns contents of edit6 as a double
handles.sensative=get(handles.popupmenu2,'Value');%returns contents of popupmenu2 as a double
handles.strategy=get(handles.popupmenu1,'Value');%returns contents of popupmenu1 as a double
[handles.Call,handles.Put]=pricing(handles);
plot_fcn(handles);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes blscalculator wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = blscalculator_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 on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.strategy = get(hObject, 'Value');
[handles.Call,handles.Put]=pricing(handles);
plot_fcn(handles)
guidata(gcbo,handles)
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.price= str2double(get(hObject,'String'));% returns contents of edit1 as a double
[handles.Call,handles.Put]=pricing(handles);
plot_fcn(handles);
guidata(gcbo,handles)
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.strike=str2double(get(hObject,'String'));% returns contents of edit2 as a double
[handles.Call,handles.Put]=pricing(handles);
plot_fcn(handles);
guidata(gcbo,handles);
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.time=str2double(get(hObject,'String')) ;%returns contents of edit3 as a double
[handles.Call,handles.Put]=pricing(handles);
plot_fcn(handles);
guidata(gcbo,handles);
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.volatility= str2double(get(hObject,'String'));% returns contents of edit4 as a double
[handles.Call,handles.Put]=pricing(handles);
plot_fcn(handles);
guidata(gcbo,handles);
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.rate=str2double(get(hObject,'String'));% returns contents of edit5 as a double
[handles.Call,handles.Put]=pricing(handles);
plot_fcn(handles);
guidata(gcbo,handles);
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
handles.sensative = get(hObject, 'Value');
[handles.Call,handles.Put]=pricing(handles);
plot_fcn(handles);
guidata(gcbo,handles);
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.yield=str2double(get(hObject,'String'));% returns contents of edit6 as a double
[handles.Call,handles.Put]=pricing(handles);
plot_fcn(handles);
guidata(gcbo,handles);
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function [Call,Put]=pricing(handles)
[pr1,t1]=meshgrid(linspace(0.9*handles.price,1.1*handles.price,30),handles.time:-1/365:0);
switch handles.sensative
case 1
[Call,Put]=blsprice(pr1,handles.strike...
,handles.rate,t1,handles.volatility,handles.yield);
zlabel(handles.axes1,'Price');
case 2
[Call,Put]=blsdelta(pr1,handles.strike...
,handles.rate,t1,handles.volatility,handles.yield);
zlabel(handles.axes1,'Delta');
case 3
Call=blsgamma(pr1,handles.strike...
,handles.rate,t1,handles.volatility,handles.yield);
Put=Call;
zlabel(handles.axes1,'Gamma');
case 4
[Call,Put]=blstheta(pr1,handles.strike...
,handles.rate,t1,handles.volatility,handles.yield);
zlabel(handles.axes1,'Volatility');
case 5
Call=blsvega(pr1,handles.strike...
,handles.rate,t1,handles.volatility,handles.yield);
Put=Call;
zlabel(handles.axes1,'Vega');
end
function plot_fcn(handles)
pr=linspace(0.9*handles.price,1.1*handles.price,30);
t=handles.time:-1/365:0;
switch handles.strategy;
case 1 % User selects Call.
handles.sh1=surf(handles.axes1,pr,t',handles.Call);
title(handles.axes1,'Call');
view(handles.axes1,[-37.5 -30]);
axis([min(pr) max(pr) min(t) max(t)]);
xlabel(handles.axes1,'Underlying Price');
ylabel(handles.axes1,'time');
rotate3d on
case 2 % User selects Put.
handles.sh1=surf(handles.axes1,pr,t',handles.Put);
title(handles.axes1,'Put');
view(handles.axes1,[-37.5 -30]);
axis([min(pr) max(pr) min(t) max(t)]);
xlabel(handles.axes1,'Underlying Price');
ylabel(handles.axes1,'time');
rotate3d on
case 3 % User selects Butterfly.
[Call,~]=butterfly(handles);
handles.sh1=surf(handles.axes1,pr,t',Call);
axis([min(pr) max(pr) min(t) max(t)]);
xlabel(handles.axes1,'Underlying Price');
ylabel(handles.axes1,'time');
title(handles.axes1,'Butterfly');
rotate3d on
case 4 % User selected Stradle
handles.sh1=surf(handles.axes1,pr,t',handles.Call+handles.Put);
title(handles.axes1,'Stradle');
view(handles.axes1,[-37.5 -30]);
axis([min(pr) max(pr) min(t) max(t)]);
xlabel(handles.axes1,'Underlying Price');
ylabel(handles.axes1,'time');
rotate3d on
end
function [Call,Put]=butterfly(handles)
[handles.Call,handles.Put] = pricing(handles);
a=handles.price;
handles.price=a*0.98;
[Call1,Put1]=pricing(handles);
handles.price=a*1.02;
[Call2,Put2]=pricing(handles);
Call=Call1-2*handles.Call+Call2;
Put=Put1-2*handles.Put+Put2;
handles.price=a;