请选择 进入手机版 | 继续访问电脑版
楼主: tulipsliu
862 3

[学科前沿] MATLAB OOA Routine for -BaselTools [推广有奖]

可计算经济学与计量经济学实证十年爱好者

学科带头人

42%

还不是VIP/贵宾

-

威望
0
论坛币
386142 个
通用积分
414.4872
学术水平
127 点
热心指数
140 点
信用等级
103 点
经验
46944 点
帖子
1767
精华
0
在线时间
2454 小时
注册时间
2007-11-5
最后登录
2024-3-24

初级热心勋章

tulipsliu 在职认证  发表于 2021-6-8 19:14:11 |显示全部楼层 |坛友微信交流群
相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

欢迎使用Markdown编辑器

经管之家:Do the best economic and management education!
Author @ bbs.pinggu.org : Daniel Tulpen Liu !
Author @ Mathwork Cop Inc :Copyright © Tommaso Belluzzo ,_意大利_语:Italia

你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。

今天要分享的是 MATLAB 的程序;

作者是国际上特别牛的人, 程序的实现的话, 我认为没有十年的 MATLAB 使用经验的话,是做不到的。
所以呢,只有好好的学习。这个代码的分享是为了大家的学习。

2021年再次修改,因为 Markdown 格式的文件,在论坛如果开头部分不够长,那么这个程序代码部分的显示,就会出一些问题。所以增加几行废话。

作者应该是MATHWORK 官方软件工程师,不是软件工程师的,写不出如此强大的程序代码。 这个程序是面向对象编程 OOA 编写。

其中的 this 是一个对象。来自于 C++ 语言。在 C++ 语言里, this 对象是比较常见的。

  • 复杂的是,这个MATLAB 程序还调用了 JAVA 程序,可见作者的编程功底非常的霸道。
  • Enjoy

OOA 编程演示

classdef (Sealed) BaselOP < BaselInterface

    %% Properties: Instance
    properties (Access = private)
        Handles
        Initialized
        Modifiers
        Transition
        Year
    end

    %% Constructor
    methods (Access = public)
        function this = BaselOP()
            fig = findall(0,'Tag','BaselOP');
            
            if (~isempty(fig))
                if (isvalid(fig))
                    figure(fig);
                    return;
                else
                    delete(fig);
                end
            end
            
            this.Construct();
            
            this.Initialized = false;
            this.Transition = false;
            this.Year = year(now());
            
            gui = struct();
            gui.gui_Name = mfilename;
            gui.gui_Singleton = false;
            gui.gui_Callback = [];
            gui.gui_OpeningFcn = @this.Form_Load;
            gui.gui_OutputFcn = @this.Form_Output;
            gui.gui_LayoutFcn = [];
            
            gui_mainfcn(gui);
        end
    end
    
    %% Destructor
    methods (Access = private)
        function delete(this)
            if (~isempty(this.Handles))
                this.Handles.BaselOP.CloseRequestFcn = '';
                delete(this.Handles.BaselOP);
            end
            
            this.Handles = [];
            this.Initialized = [];
            this.Modifiers = [];
            this.Transition = [];
            this.Year = [];
            
            this.Destruct();
        end
    end
    
    %% Methods: Events
    methods (Access = private)
        function Form_Close(this,obj,evd) %#ok<INUSD>
            delete(this);
        end
        
        function Form_KeyModifiers(this,obj,evd) %#ok<INUSL>
            this.Modifiers = evd.Modifier;
        end
        
        function Form_Load(this,obj,evd,han,varargin) %#ok<INUSL>
            obj.CloseRequestFcn = @this.Form_Close;
            obj.WindowKeyPressFcn = @this.Form_KeyModifiers;
            obj.WindowKeyReleaseFcn = @this.Form_KeyModifiers;
            
            han.LossButtonClear.Callback = @this.LossButtonClear_Clicked;
            han.LossButton load.Callback = @this.LossButton load_Clicked;
            han.LossButtonThresholdMinus.Callback = @this.LossButtonThreshold_Clicked;
            han.LossButtonThresholdPlus.Callback = @this.LossButtonThreshold_Clicked;
            han.LossButtonYearMinus.Callback = @this.LossButtonYear_Clicked;
            han.LossButtonYearPlus.Callback = @this.LossButtonYear_Clicked;
            han.LossCheckboxTransition.Callback = @this.LossCheckboxTransition_CheckedChanged;
            han.CapitalButtonDefault.Callback = @this.CapitalButtonDefault_Clicked;
            han.CapitalButtonExport.Callback = @this.CapitalButtonExport_Clicked;
            han.CapitalCheckboxCompact.Callback = @this.CapitalCheckboxCompact_Clicked;
            han.CapitalGroupApproach.Selection changeFcn = @this.CapitalGroupApproach_Selection changed;
            
            han.TabGroup = uitabgroup('Parent',obj);
            han.TabGroup.Units = 'pixels';
            han.TabGroup.Position = [2 1 1024 768];
            han.IntroductionTab = uitab('Parent',han.TabGroup);
            han.IntroductionTab.Tag = 'IntroductionTab';
            han.IntroductionTab.Title = 'Introduction';
            han.IntroductionPanel.Parent = han.IntroductionTab;
            han.BusinessTab = uitab('Parent',han.TabGroup);
 han.BusinessTab.Tag = 'BusinessTab';
            han.BusinessTab.Title = 'Business Indicator Component';
            han.BusinessPanel.Parent = han.BusinessTab;
            han.LossTab = uitab('Parent',han.TabGroup);
            han.LossTab.Tag = 'LossTab';
            han.LossTab.Title = 'Loss Component';
            han.LossPanel.Parent = han.LossTab;
            han.CapitalTab = uitab('Parent',han.TabGroup);
            han.CapitalTab.Tag = 'CapitalTab';
            han.CapitalTab.Title = 'Capital Requirement';
            han.CapitalPanel.Parent = han.CapitalTab;
            
            guidata(obj,han);
            this.Handles = guidata(obj);
            
            uistack(han.Blank,'top');
            
            scr = groot;
            scr.Units = 'pixels';
            scr_siz = scr.ScreenSize;
            obj.Position = [((scr_siz(3) - 1024) / 2) ((scr_siz(4) - 768) / 2) 1024 768];
        end
        
        function varargout = Form_Output(this,obj,evd,han) %#ok<INUSD>
            varargout = {};
            
            import('java.awt.*');
            
            bar = waitbar(0,'Initializing...','CloseRequestFcn','','WindowStyle','modal');
            frm = fr ame.getfr ames();
            frm(end).setAlwaysOnTop(true);
            
            yea = this.Year - 10;
            
            tab_bus_data_col = this.Handles.BusinessTableData.ColumnName;
            tab_bus_data_col{2} = sprintf('Value %d',(this.Year - 3));
            tab_bus_data_col{3} = sprintf('Value %d',(this.Year - 2));
            tab_bus_data_col{4} = sprintf('Value %d',(this.Year - 1));
            
            tab_bus_data = cell(15,5);
            tab_bus_data([2:7 9:10 12:15],2:5) = {0};
            tab_bus_data(1:7,1) = {'Interest, Lease & Dividend Component' 'II' 'IE' 'IEA' 'LI' 'LE' 'DI'};
            tab_bus_data(8:10,1) = {'Financial Component' 'BB' 'TB'};
            tab_bus_data(11:15,1) = {'Services Component' 'FI' 'FE' 'OOI' 'OOE'};
            
            tab_bus_agg = cell(5,2);
            tab_bus_agg(:,1) = {'ILDC' 'FC' 'SC' 'UBI' 'BI'};
            tab_bus_agg(:,2) = {0};
            
            tab_bus_com = cell(5,3);
            tab_bus_com(:,1) = {'1' '2' '3' '4' '5'};
            tab_bus_com(:,2) = {'0 - 1bn' '1bn - 3bn' '3bn - 10bn' '10bn - 30bn' '30bn - INF'};
            tab_bus_com(:,3) = {0 '-' '-' '-' '-'};
            
            tab_capi_data_col = this.Handles.CapitalTableComparison.ColumnName;
            tab_capi_data_col{2} = sprintf('Value %d',(this.Year - 3));
            tab_capi_data_col{3} = sprintf('Value %d',(this.Year - 2));
            tab_capi_data_col{4} = sprintf('Value %d',(this.Year - 1));
            
            tab_capi_res = cell(7,2);
            tab_capi_res(:,1) = {'BIC' 'LC' 'ILM' 'K SMA' 'RWA SMA' 'K BII' 'RWA BII'};
            tab_capi_res([1 4:7],2) = {0};
            tab_capi_res([2 3],2) = {'-'};
            
            tab_capi_com = cell(8,4);
            tab_capi_com(:,1) = {'AG' 'AM' 'CB' 'CF' 'PS' 'RBA' 'RBR' 'TS'};
            tab_capi_com(:,2:4) = {0};
            
            try
                uistack(this.Handles.Blank,'bottom');
                
                this.SetupBox(this.Handles.IntroductionBox);
                
                this.Handles.BusinessTableData.ColumnName = tab_bus_data_col;
                this.SetupTable(this.Handles.BusinessTableData, ...
                    'Data',        tab_bus_data, ...
                    'DataChanged', @this.BusinessTableData_DataChanged, ...
                    'Editor',      {'EditorCurrency' 0 1e12 0}, ...
                    'Renderer',    {'RendererOpBusData'}, ...
                    'Table',       {'TableOpBusData'});
                
                this.SetupTable(this.Handles.BusinessTableResult, ...
                    'Data',        tab_bus_agg, ...
                    'Renderer',    {'RendererOpBusRslt'}, ...
                    'RowsHeight',  60);
                
                this.SetupTable(this.Handles.BusinessTableComponent, ...
                    'Data',        tab_bus_com, ...
                    'Renderer',    {'RendererOpBusComp'}, ...
                    'RowsHeight',  60);
                
                this.SetupBox(this.Handles.BusinessBox);
                
                this.Handles.LossTextboxYear.String = num2str(yea);
                this.Handles.LossTextboxYear.UserData = yea;
                
                this.SetupTable(this.Handles.LossTableDataset, ...
                    'RowHeaderWidth',    56, ...
                    'Sorting',           2, ...
                    'VerticalScrollbar', true);
                
                this.SetupTable(this.Handles.LossTableResult, ...
                    'RowsHeight',        75);
                
                this.SetupBox(this.Handles.LossBox);
                
                this.SetupTable(this.Handles.CapitalTableResult, ...
                    'Data',        tab_capi_res, ...
                    'Renderer',    {'RendererOpCapRslt'}, ...
                    'RowsHeight',  42);
                
                this.Handles.CapitalTableComparison.ColumnName = tab_capi_data_col;
                this.SetupTable(this.Handles.CapitalTableComparison, ...
                    'Data',        tab_capi_com, ...
                    'DataChanged', @this.CapitalTableComparison_DataChanged, ...
                    'Editor',      {'EditorCurrency' -1e12 1e12 0}, ...
                    'Renderer',    {'RendererOpCapCmpr'}, ...
                    'RowsHeight',  37, ...
                    'Table',       {'TableOpCapCmpr'});
                
                this.SetupBox(this.Handles.CapitalBoxExport);
                this.SetupBox(this.Handles.CapitalBoxInformation);
                
                this.Handles.CapitalButtonExport.Enable = 'on';
                
                this.Initialized = true;
            catch e
                delete(bar);
                
                err = this.FormatException('The initialization process failed.',e);
                
                dlg = errordlg(err,'Error','modal');
                uiwait(dlg);
                
                delete(this);
                
                return;
            end
            
            drawnow();
            pause(0.05);
            
            waitbar(1,bar);
            delete(bar);
        end
        
        function BusinessTableData_DataChanged(this,obj,evd)
            if (~this.Initialized)
                return;
            end
            
            col = evd.getColumn();
            row = evd.getFirstRow();
            
            if ((col < 1) || (col > 3) || (row == 0) || (row == 7) || (row == 10))
                return;
            end
            
            val_t2 = obj.getValueAt(row,1);
            val_t1 = obj.getValueAt(row,2);
            val_t0 = obj.getValueAt(row,3);
            
            obj.setValueAt(mean([val_t2 val_t1 val_t0]),row,4);
            
            this.UpdateData();
        end
        
        function CapitalButtonDefault_Clicked(this,obj,evd) %#ok<INUSD>
            obj.Enable = 'off';
            
            this.Handles.CapitalCheckboxCompact.Value = 0;
            this.Handles.CapitalCheckboxStyles.Value = 1;
            this.Handles.CapitalCheckboxLoss.Value = 0;
            this.Handles.CapitalCheckboxComparison.Value = 0;
            
            obj.Enable = 'on';
        end
        
        function CapitalButtonExport_Clicked(this,obj,evd) %#ok<INUSD>
            obj.Enable = 'off';

            rel_path = ['\Results\ResultOP-' datestr(now(),'ddmmyyyy') '.xlsx'];
            file = fullfile(pwd(),rel_path);
            
            if (exist(file,'file') == 2)
                res = questdlg(['The destination file "' file '" already exist. Do you want to overwrite it?'],'Alert','Yes','No','No');
                
                if (strcmp(res,'No'))
                    quit = false;
                    
                    while (true)
                        res = inputdlg('Please, enter a valid file name or relative path:','File',1,{rel_path});

                        if (isempty(res))
                            quit = true;
                            break;
                        end
                        
                        if (~endsWith(res,'.xlsx'))
                            continue;
                        end
                        
                        mat = regexpi(res,'^[a-z]:\\');
                        
                        if (size(mat{1},1) > 0)
                            continue;
                        end
                        
                        file = fullfile(pwd(),res);
                        
                        break;
                    end
                    
                    if (quit)
                        obj.Enable = 'on';
                        return;
                    end
                end
            end

            import('java.awt.*');
            
            bar = waitbar(0,'Expoting Data...','CloseRequestFcn','','WindowStyle','modal');
            frm = fr ame.getfr ames();
            frm(end).setAlwaysOnTop(true);
            
            err = '';
            
            try
                this.ExportData(file);
            catch e
                err = this.FormatException('The exportation process failed.',e);
            end
            
            if (~isempty(err))
                delete(bar);
                
                dlg = errordlg(err,'Error','modal');
                uiwait(dlg);
                
                obj.Enable = 'on';
                
                return;
            end
            
            waitbar(1,bar);
            delete(bar);
            
            obj.Enable = 'on';
        end
        
        function CapitalCheckboxCompact_Clicked(this,obj,evd) %#ok<INUSD>
            if (obj.Value == 0)
                jpan_cap_rslt = javaob jectEDT(findjobj(this.Handles.CapitalTableResult));
                jtab_cap_rslt = javaob jectEDT(jpan_cap_rslt.getViewport().getView());
                
                if (~ischar(jtab_cap_rslt.getValueAt(1,1)))
                    this.Handles.CapitalCheckboxLoss.Enable = 'on';
                end
            else
                this.Handles.CapitalCheckboxLoss.Value = 0;
                this.Handles.CapitalCheckboxLoss.Enable = 'off';
            end
        end
        
        function CapitalGroupApproach_Selection changed(this,obj,evd) %#ok<INUSL>
            this.UpdateComparison(evd.NewValue.String);
        end
        
        function CapitalTableComparison_DataChanged(this,obj,evd) %#ok<INUSL>
            if (~this.Initialized)
                return;
            end
            
            col = evd.getColumn();
            
            if (col < 1)
                return;
            end
            
            this.UpdateComparison();
        end
        
        function LossButtonClear_Clicked(this,obj,evd) %#ok<INUSD>
            obj.Enable = 'off';
            
            jpan_cap_rslt = javaob jectEDT(findjobj(this.Handles.CapitalTableResult));
            jtab_cap_rslt = javaob jectEDT(jpan_cap_rslt.getViewport().getView());
            jtab_cap_rslt.setValueAt('-',1,1);
            
            this.UpdateCapital();
            
            this.LossComponentEnable(true);
        end
        
  

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Routine MATLAB matla Tools atlab

"Recursive Macroeconomic Theory","Labour Economic".
tulipsliu 在职认证  发表于 2021-6-8 21:35:29 |显示全部楼层 |坛友微信交流群
TommasoBelluzzo-BaselTools-ec79d17.zip (410.98 KB)

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-29 15:31