classdef app4btEur < matlab.apps.AppBase

% Properties that correspond to app components
properties (Access = public)
    UIFigure           matlab.ui.Figure
    Button_2           matlab.ui.control.Button
    Button             matlab.ui.control.Button
    TEditField         matlab.ui.control.NumericEditField
    TEditFieldLabel    matlab.ui.control.Label
    EditField          matlab.ui.control.NumericEditField
    EditFieldLabel     matlab.ui.control.Label
    rEditField_2       matlab.ui.control.NumericEditField
    rEditField_2Label  matlab.ui.control.Label
    KEditField_2       matlab.ui.control.NumericEditField
    KEditField_2Label  matlab.ui.control.Label
    SEditFieldLabel    matlab.ui.control.Label
    PEditField         matlab.ui.control.NumericEditField
    PEditFieldLabel    matlab.ui.control.Label
    CEditField         matlab.ui.control.NumericEditField
    CEditFieldLabel    matlab.ui.control.Label
    SEditField         matlab.ui.control.NumericEditField
    Label              matlab.ui.control.Label
    TextArea           matlab.ui.control.TextArea
end

% Callbacks that handle component events
methods (Access = private)

    % Button pushed function: Button_2
    function Button_2Pushed(app, event)
        S0 = app.SEditField.Value;
        K = app.KEditField_2.Value;
        r = app.rEditField_2.Value;
        sigma = app.EditField.Value;
        T = app.TEditField.Value;
        u=exp(sigma*sqrt(T));
        d=1/u;
        p=(exp(r*T)-d)/(u-d);
        Su=S0*u;
        Sd=S0*d;
        fuc=max(Su-K,0);
        fdc=max(Sd-K,0);
        call=exp(-r*T)*(p*fuc+(1-p)*fdc);
        if S0-K>call
            call = S0-K;
            app.CEditField.Value = call;
        end

        fup=max(K-Su,0);
        fdp=max(K-Sd,0);
        put=exp(-r*T)*(p*fup+(1-p)*fdp);
        if K-S0>put
            put =K-S0;
            app.PEditField.Value = put;
        end
    end

    % Button pushed function: Button
    function ButtonPushed(app, event)
        delete(app.UIFigure)
        run app5Eur.mlapp
    end
end

% Component initialization
methods (Access = private)

    % Create UIFigure and components
    function createComponents(app)

        % Create UIFigure and hide until all components are created
        app.UIFigure = uifigure('Visible', 'off');
        app.UIFigure.Position = [100 100 640 480];
        app.UIFigure.Name = 'MATLAB App';

        % Create TextArea
        app.TextArea = uitextarea(app.UIFigure);
        app.TextArea.HorizontalAlignment = 'center';
        app.TextArea.FontName = 'Baoli TC';
        app.TextArea.FontSize = 48;
        app.TextArea.FontWeight = 'bold';
        app.TextArea.FontColor = [0.949 0.5804 0.8157];
        app.TextArea.BackgroundColor = [0.051 0.0471 0.0471];
        app.TextArea.Position = [202 407 207 74];
        app.TextArea.Value = {'期权定价'};

        % Create Label
        app.Label = uilabel(app.UIFigure);
        app.Label.BackgroundColor = [0.9098 0.7176 0.8353];
        app.Label.HorizontalAlignment = 'center';
        app.Label.FontName = 'Baoli SC';
        app.Label.FontSize = 20;
        app.Label.FontWeight = 'bold';
        app.Label.Position = [213 365 185 43];
        app.Label.Text = '二叉树模型欧式期权';

        % Create SEditField
        app.SEditField = uieditfield(app.UIFigure, 'numeric');
        app.SEditField.HorizontalAlignment = 'center';
        app.SEditField.FontName = 'Baoli SC';
        app.SEditField.BackgroundColor = [0.9804 0.7647 0.8235];
        app.SEditField.Position = [186 321 110 22];

        % Create CEditFieldLabel
        app.CEditFieldLabel = uilabel(app.UIFigure);
        app.CEditFieldLabel.HorizontalAlignment = 'center';
        app.CEditFieldLabel.FontName = 'Baoli SC';
        app.CEditFieldLabel.FontSize = 15;
        app.CEditFieldLabel.FontWeight = 'bold';
        app.CEditFieldLabel.Position = [317 283 107 22];
        app.CEditFieldLabel.Text = '看涨期权价格C';

        % Create CEditField
        app.CEditField = uieditfield(app.UIFigure, 'numeric');
        app.CEditField.HorizontalAlignment = 'center';
        app.CEditField.FontName = 'Baoli SC';
        app.CEditField.BackgroundColor = [0.9804 0.7647 0.8235];
        app.CEditField.Position = [438 280 177 29];

        % Create PEditFieldLabel
        app.PEditFieldLabel = uilabel(app.UIFigure);
        app.PEditFieldLabel.HorizontalAlignment = 'center';
        app.PEditFieldLabel.FontName = 'Baoli SC';
        app.PEditFieldLabel.FontSize = 15;
        app.PEditFieldLabel.FontWeight = 'bold';
        app.PEditFieldLabel.Position = [317 197 106 22];
        app.PEditFieldLabel.Text = '看跌期权价格P';

        % Create PEditField
        app.PEditField = uieditfield(app.UIFigure, 'numeric');
        app.PEditField.HorizontalAlignment = 'center';
        app.PEditField.FontName = 'Baoli SC';
        app.PEditField.BackgroundColor = [0.9804 0.7647 0.8235];
        app.PEditField.Position = [438 193 177 30];

        % Create SEditFieldLabel
        app.SEditFieldLabel = uilabel(app.UIFigure);
        app.SEditFieldLabel.HorizontalAlignment = 'right';
        app.SEditFieldLabel.FontName = 'Baoli TC';
        app.SEditFieldLabel.FontSize = 15;
        app.SEditFieldLabel.FontWeight = 'bold';
        app.SEditFieldLabel.Position = [22 321 152 22];
        app.SEditFieldLabel.Text = '标的资产的价格S';

        % Create KEditField_2Label
MATLAB App: 二叉树模型欧式期权定价

原文地址: https://www.cveoy.top/t/topic/f3Qt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录