⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treedemonew.m

📁 用matlab实现衍生证券定价,非常好用
💻 M
📖 第 1 页 / 共 2 页
字号:
            elseif isafin(Tree, 'BKFwdTree')
                CName = 'BKFwdTree';
                instnames = [];
            elseif isafin(Tree, 'BKRateTree')
                CName  = 'BKRateTree';
                instnames = [];
            else
                if(NInstTree(1) ~= NInstSet)
                    error('finderiv:treedemonew:InvalidInstSet','Number of instruments in InstSet does not correspond to the number of instruments in the Tree')
                end
            end
            if ~isempty(CName)
                msg = sprintf('%s structure passed in. Ignoring input argument ''InstSet''', CName);
                warning('finderiv:treedemonew:IgnoredInstSet', msg);
            end
        end


        %View instrument price tree
        h = figure('Name','FinDeriv Tree Demo','Numbertitle','off','Userdata',Tree,'Tag','treeviewer', 'MenuBar', 'none');
        setappdata(h,'HJMTREE',Tree)
        setappdata(h, 'TREES', Trees);
        set(h,'windowstyle','normal')

        if isafin(Tree, 'BDTFwdTree')
            AxesHandle = treeguistate(Tree.FwdTree);
        elseif isafin(Tree, 'BDTRateTree')
            AxesHandle = treeguistate(Tree.RateTree);
        elseif isafin(Tree, 'BDTPriceTree')
            AxesHandle = treeguistate(Tree.PTree);
        elseif isafin(Tree, 'BDTCFTree')
            AxesHandle = treeguistate(Tree.CFTree);
        elseif isafin(Tree, 'BDTMmktTree')
            AxesHandle = treeguistate(Tree.MMktTree);
        elseif isafin(Tree, 'BinStockTree')
            AxesHandle = treeguistate(Tree.STree);
        elseif isafin(Tree, 'BinPriceTree')
            AxesHandle = treeguistate(Tree.PTree);
        elseif isafin(Tree, 'HWFwdTree') || isafin(Tree, 'HWRateTree')
            AxesHandle = trintreeguistate(Tree);
        elseif isafin(Tree, 'BKFwdTree') || isafin(Tree, 'BKRateTree')
            AxesHandle = trintreeguistate(Tree);
        elseif isafin(Tree, 'BKPriceTree') || isafin(Tree, 'HWPriceTree')
            AxesHandle = trintreeguistate(Tree);
        else
            AxesHandle = bushguistate(NChild);
        end

        %Store portfolio data in figure window for later use
        if nargin >= 3
            uicontrol('Visible','off','Tag','portfolio','Userdata',Port);
        end

        %start x-axis labels at zero
        xlab = get(gca,'Xtick')-1;

        %reposition axis
        p = get(AxesHandle,'Position');
        set(AxesHandle,'Position',[p(1)/8 p(2) p(3)/2+p(1)/2 p(4)],'Tag','Chooser',...
            'Xticklabel',xlab,'Color',[1 1 1])

        %Set highlightmode to path to root
        setappdata(AxesHandle,'HighlightMode','path')
        
        % Build tree menu
        
        
        hInputMenu = uimenu('label', 'Inputs', 'Visible', 'off');
        uimenu('parent', hInputMenu, 'label', 'Portfolio...', 'callback', {@portMenu_callback, Port});
        uimenu('parent', hInputMenu, 'label', 'Interest Rates...', 'callback', {@rateMenu_callback, RS});
        hMainTreeMenu = uimenu('label', 'Price Trees');
        for iMenus=1:size(Trees,1)
            uimenu('parent', hMainTreeMenu, 'label', Trees{iMenus,1}, ...
                'callback', {@treeMenu_callback, iMenus});
        end

        %Build uicontrols

        %Get figure position and set spacing parameters
        p = get(gcf,'Position');
        rgt = p(3);
        top = p(4);
        dfp = get(0,'DefaultFigurePosition');
        mfp = [560 420];    %Reference width and height
        bspc = mean([5/mfp(2)*dfp(4) 5/mfp(1)*dfp(3)]);
        bhgt = 20/mfp(2) * dfp(4);
        bwid = 85/mfp(1) * dfp(3);
        fwid1 = rgt-2*bspc;
        fhgt1 = 7*bspc+6*bhgt;
        fhgt2 = top-fhgt1-4*bspc;

        %Close Button
        uicontrol('String','Close','Callback','close','Position',[rgt-(bspc+bwid) 2*bspc bwid bhgt]);
        uicontrol('String','Help','Callback','derivtool(''help'',''treeviewer'')','Position',[rgt-(2*bspc+2*bwid) 2*bspc bwid bhgt]);

        %Tree Visualization frame
        uicontrol('Style','frame','Position',[rgt/2 top-5*bhgt rgt/2-bspc 2*bspc+4*bhgt]);
        uicontrol('Style','text','String','Tree Visualization',...
            'Position',[rgt/2+bspc top-(bspc+bhgt) bwid bhgt]);
        uicontrol('Style','text','String','Visualization',...
            'Position',[rgt-(bspc+1.25*bwid) top-(bspc+1.75*bhgt) bwid bhgt]);
        uicontrol('Style','radiobutton','String','Table','Tag','treeradio',...
            'Callback','treeviewercallbacks(''radiobutton'')','Value',1,...
            'Position',[rgt-(bspc+1.25*bwid) top-(bspc+2.5*bhgt) bwid bhgt]);
        uicontrol('Style','radiobutton','String','Diagram','Tag','treeradio',...
            'Callback','treeviewercallbacks(''radiobutton'')',...
            'Position',[rgt-(bspc+1.25*bwid) top-(bspc+3.5*bhgt) bwid bhgt]);
        uicontrol('Style','radiobutton','String','Plot','Tag','treeradio',...
            'Callback','treeviewercallbacks(''radiobutton'')',...
            'Position',[rgt-(bspc+1.25*bwid) top-(bspc+4.5*bhgt) bwid bhgt]);
        uicontrol('Style','text','String','Selection',...
            'Position',[rgt-(bspc+3*bwid) top-(bspc+1.75*bhgt) bwid bhgt]);
        uicontrol('Style','radiobutton','String','Path','Tag','pathradio',...
            'Callback','treeviewercallbacks(''radiobutton'')','Value',1,'Userdata','path',...
            'Position',[rgt-(bspc+3*bwid) top-(bspc+2.5*bhgt) bwid bhgt]);
        uicontrol('Style','radiobutton','String','Node and Children','Tag','pathradio',...
            'Callback','treeviewercallbacks(''radiobutton'')','Userdata','node',...
            'Position',[rgt-(bspc+3*bwid) top-(bspc+3.5*bhgt) bwid+5*bspc bhgt]);

        %Selected instrument uicontrols, only if from View Tree in main window
        if ~isempty(instnames)
            vflag = 1;
            uicontrol('Style','text','String','Instrument:',...
                'Position',[rgt-(bspc+3*bwid) top-(3*bspc+6*bhgt) bwid bhgt]);
            uicontrol('Style','popupmenu','String',instnames,'Tag','treeinstruments',...
                'Callback','treeviewercallbacks(''treeinstrument'')',...
                'Value',instval,'Position',[rgt-(bspc+2*bwid) top-(2*bspc+6*bhgt) 1.5*bwid bhgt]);
        else
            vflag = 0;   %Do not display instrument uicontrols
        end

        %Data/plot frame
        bgf = axes('Units','pixels','Position',[rgt/2 5*bspc+bhgt rgt/2-bspc 12*bhgt-bspc],...
            'Box','on','Xtick',[],'Ytick',[],...
            'Color',get(0,'Defaultuicontrolbackgroundcolor'));
        set(bgf,'Units','normal')

        %Data uicontrols
        if vflag    %Instrument tree viewing
            uicontrol('Style','text','String','Time','Userdata','pathtoroot',...
                'Position',[rgt-(2*bspc+3*bwid) top-(6*bspc+7*bhgt) bwid bhgt]);
        else     %Rates  tree viewing
            uicontrol('Style','text','String','Start Time','Userdata','pathtoroot',...
                'Position',[rgt-(2*bspc+3*bwid) top-(6*bspc+7*bhgt) bwid bhgt]);
            uicontrol('Style','text','String','End Time','Userdata','pathtoroot',...
                'Position',[rgt-(2*bspc+2.25*bwid) top-(6*bspc+7*bhgt) bwid bhgt]);
        end
        uicontrol('Style','text','String','Path 1','Userdata','pathtoroot',...
            'Foregroundcolor',ColorOne,...
            'Position',[rgt-(2*bspc+1.5*bwid) top-(6*bspc+7*bhgt) bwid bhgt]);
        uicontrol('Style','text','String','Path 2','Userdata','pathtoroot',...
            'Foregroundcolor',ColorTwo,...
            'Position',[rgt-(2*bspc+.8*bwid) top-(6*bspc+7*bhgt) bwid bhgt]);
        uicontrol('Style','listbox','Tag','treedata','Userdata','pathtoroot',...
            'Fontname',fnt,...
            'Position',[rgt/2+bspc 6*bspc+bhgt rgt/2-3*bspc 10*bhgt+bspc]);

        %Plot axis
        pta = axes('Units','pixels','Box','on','Xtick',[],'Ytick',[],'Tag','treeplot',...
            'Userdata','nodeandchildren','Visible','off','Color',[1 1 1],...
            'Position',[rgt/2+bspc 6*bspc+bhgt rgt/2-3*bspc bspc+11*bhgt]);
        set(pta,'Units','normal')

        %Define callbacks for tree elements
        trobj = findobj(gcf,'Tag','StateMark');
        set(trobj,'Buttondownfcn','treeviewercallbacks(''treeaction'')')

        %Set colors for paths, (taken from bushguistate)
        ColorOrder = get(gca,'ColorOrder');
        ColorOrder(3:4,:) = [ColorOne;ColorTwo];
        ColorOrder(5:end,:) = [];
        ColorState = ColorOrder(1,:); % Color of state markers
        ColorLine = ColorOrder(2,:);  % Color of unselected lines connecting states
        ColorSelectOrder = ColorOrder(3:end,:); % Colors available for selection
        ColorSelectInd = 1; % Location of next color in ColorSelectOrder

        ChooserH = findobj(gcf,'Tag','Chooser');
        setappdata(ChooserH, 'ColorState', ColorState);
        setappdata(ChooserH, 'ColorLine',  ColorLine);
        setappdata(ChooserH, 'ColorSelectOrder', ColorSelectOrder);
        setappdata(ChooserH, 'ColorSelectInd',   ColorSelectInd);

        setappdata(ChooserH,'CurrentPathNumber',0)

        %CLEANUPDIALOG Visual enhancement of dialog.

        %Set colors and alignment
        e = findobj(gcf,'Style','edit');
        l = findobj(gcf,'Style','listbox');
        p = findobj(gcf,'Style','popupmenu');
        set([e;l;p],'Backgroundcolor','white','Horizontalalignment','left')
        dbc = get(0,'Defaultuicontrolbackgroundcolor');
        set(gcf,'Color',dbc)

        %Make text boxes proper width
        textuis = findobj(gcf,'Style','text');
        notextui = findobj(gcf,'Tag','tabtext');  %Do not alter tab cover (which is a blank text ui)
        if ~isempty(notextui);
            j = find(notextui == textuis);
            textuis(j) = [];
        end
        for i = 1:length(textuis)
            pos = get(textuis(i),'Position');
            ext = get(textuis(i),'Extent');
            set(textuis(i),'Position',[pos(1) pos(2) ext(3) pos(4)])
        end
        set(textuis,'Backgroundcolor',dbc)
        set(findobj(gcf,'Value',-33),'Backgroundcolor',[1 1 1])

        %Normalize units
        set(findobj(gcf,'Type','uicontrol'),'Units','normal')
        set(findobj(gcf,'Type','axes'),'Units','normal')
        
    otherwise
        error('finderiv:treedemonew:InvalidCommand', 'Invalid Command passed to treedemonew');
end


function treeMenu_callback(source, eventdata, menuIndex)
        Trees = getappdata(gcf, 'TREES'); 
        setappdata(gcf,'HJMTREE',Trees{menuIndex,2});
        setappdata(gcf,'PathOne', []);
        setappdata(gcf,'PathTwo', []);
        
        % reset treeradio radio buttons
        hTreeRadio = findobj(gcf, 'Tag', 'treeradio');
        set(hTreeRadio, 'value', 0);
        hTableRadio = findobj(gcf, 'Tag', 'treeradio', 'String', 'Table');
        set(hTableRadio, 'Value', 1);
        
        % reset path radio buttons
        hPathRadios = findobj(gcf, 'Tag', 'pathradio');
        set(hPathRadios, 'value', 0);
        hPathRadio = findobj(gcf, 'Tag', 'pathradio', 'String', 'Path');
        set(hPathRadio, 'Value', 1);
        
        % reset treeplot
        hPlotAxes = findobj(gcf, 'Tag','treeplot');
        delete(get(hPlotAxes, 'Children'));
        set(hPlotAxes, 'vis', 'off');
      
        hLBox = findobj(gcf,'Style','listbox');
        set(hLBox, 'string', []);
        set(hLBox, 'Vis', 'on');
               
        treedemonew('update', Trees(menuIndex,2), []);  
return

function portMenu_callback(source, eventdata, Port)
portbrowser(Port);


function rateMenu_callback(source, eventdata, RateSpec)

Rates(RateSpec);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -