function varargout = VolatilityFigure(varargin)
% VOLATILITYFIGURE M-file for VolatilityFigure.fig
%      VOLATILITYFIGURE, by itself, creates a new VOLATILITYFIGURE or raises the existing
%      singleton*.
%
%      H = VOLATILITYFIGURE returns the handle to a new VOLATILITYFIGURE or the handle to
%      the existing singleton*.
%
%      VOLATILITYFIGURE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in VOLATILITYFIGURE.M with the given input arguments.
%
%      VOLATILITYFIGURE('Property','Value',...) creates a new VOLATILITYFIGURE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before VolatilityFigure_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to VolatilityFigure_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 VolatilityFigure

% Last Modified by GUIDE v2.5 11-Sep-2009 09:24:55

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @VolatilityFigure_OpeningFcn, ...
                   'gui_OutputFcn',  @VolatilityFigure_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 VolatilityFigure is made visible.
function VolatilityFigure_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 VolatilityFigure (see VARARGIN)

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

handles.baseFigure=varargin{1};
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes VolatilityFigure wait for user response (see UIRESUME)
% uiwait(handles.volatilityFigure);


%========================================================================================================================
% --- Outputs from this function are returned to the command line.
function varargout = VolatilityFigure_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 button press in volatilityFigurepushbutton1.
function volatilityFigurepushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to volatilityFigurepushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global SERIES
global SERIESINDEX
global SERIESTYPE
global SERIESSTAT

handles2=guidata(handles.baseFigure);

% Вычисляем волатильность матрицы, выделенной в ListBox
index=get(handles2.listbox1,'Value');
SRC=SERIES{index};
RES=getVolatility(SRC,str2num(get(handles.volatilityFigureedit1,'String')), ...
                      str2num(get(handles.volatilityFigureedit2,'String')));

SERIESINDEX=SERIESINDEX+1;
SERIES{SERIESINDEX}=RES;
SERIESTYPE{SERIESINDEX}=[char(SERIESTYPE{index}) ';VLT'];
SERIESSTAT{SERIESINDEX}=getStat(RES);
SERIESSTAT{SERIESINDEX}.fileName=SERIESSTAT{index}.fileName;
saveInfo(handles2,SERIESSTAT{SERIESINDEX});
CD=get(handles2.listbox1,'String');
[CDm,CDn]=size(CD);
CD(CDm+1,:)='Волатиль';
set(handles2.listbox1,'String',CD);
set(handles2.listbox1,'Value',SERIESINDEX);

if get(handles.checkbox1,'Value')==get(handles.checkbox1,'Max')
    RES2=getNormVolatility(RES);

    SERIESINDEX=SERIESINDEX+1;
    SERIES{SERIESINDEX}=RES2;
    SERIESTYPE{SERIESINDEX}=[char(SERIESTYPE{index}) 'VLTN'];
    SERIESSTAT{SERIESINDEX}=getStat(RES2);
    CD(CDm+2,:)='ВолатНор';
end

guidata(handles.baseFigure,handles2);
set(handles2.listbox1,'String',CD);

plot(RES);

%========================================================================================================================
% --- Executes during object creation, after setting all properties.
function volatilityFigureedit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to volatilityFigureedit1 (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 volatilityFigureedit1_Callback(hObject, eventdata, handles)
% hObject    handle to volatilityFigureedit1 (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 volatilityFigureedit1 as text
%        str2double(get(hObject,'String')) returns contents of volatilityFigureedit1 as a double


%========================================================================================================================
% --- Executes during object creation, after setting all properties.
function volatilityFigureedit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to volatilityFigureedit2 (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 volatilityFigureedit2_Callback(hObject, eventdata, handles)
% hObject    handle to volatilityFigureedit2 (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 volatilityFigureedit2 as text
%        str2double(get(hObject,'String')) returns contents of volatilityFigureedit2 as a double

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

% Hint: get(hObject,'Value') returns toggle state of checkbox1
