% ______ 3 D - Graphic :   " Histogram +  Shortfall Prob. + Ribbon "  ____
% _____________________________________________________

clear all; close all; clf;
disp(['°°°°°°°°°°°°° S T A R T °°°°°°°°°°°°°°°°°°° ' ,date, ' °°°°°°°°°°°°°°'])

P        =100 ;
mu      = 10 ;                                         
vola  = 30 ;
cut = 80;                                                            % > Portfolio Value  <= 80 Mio. 
bins  = 40;

x = 30*randn(10000,1)+110;                          % Normal-Vert. des Portfolios
alpha = 0.01 ;                                                      % @ = 1%
Phi    = normcdf(cut, (P+mu), vola)                   %  Fläche unter dem Quantil bis P = 80
t        = norminv(alpha, (P+mu), vola)   

figure(1)
set(gcf, 'color', [1.0 1.0 0.6]);
subplot(121)
     hist(x, bins) ;
     title('\bf Portfolio : Hist - Graphic', 'fontsize',14); 
     ylabel('\bf Frequency', 'Fontsize', 12);
     L = findobj(gca,'Type','patch');
     set(L,'FaceColor', [0.1 0.5 1.0],'EdgeColor','k')
     set(gca, 'fontsize', 12)
     grid on;
     pause(1)
     hold on
     h = get(gca,'Children');
     S = get(h,'XData');
     T = get(h,'YData');
     Q = find( S<=cut);
     area( S(Q), T(Q), 'FaceColor', 'r');
     
     D = text(50, 300, ['\bf Prob. = ', num2str( round(Phi*100) ), ' %'], ...
                                     'Horizontalalignment', 'right', 'Fontsize', 12)
     set(D, 'color', [0.99 0.01 0.01])
     set(gca,'FontWeight','demi','FontSize',14);
     LL = xlabel(['\bf PF.-Quantil = ', num2str(cut), ' [Mio €]']);
     set(LL, 'color','r')

% ___ Gesucht :  Verlustschwelle = X-krit bei  (1-@) = 99 % 
     m    =round( mean(x));
     med =round( median(x));


subplot(122)
      [N hX] = hist(x, bins);
      ribbon(hX , N) ;  view(89, 6)                                             %  >  important for changing Axis   !!!
      h = findobj(gca,'Type', 'surface');
      set (h,'FaceColor', [0.4 0.1 0.4] , 'EdgeColor', 'g')
      title('\bf Test - Graphic : Ribbon', 'fontsize',14);    
      ylabel('\bf XXX') ;  
      zlabel('\bf ZZZ');
      set(gca, 'Xtick', [], 'fontsize',14 )
      pause(1)
      
     TH = title({' Hist \oplus' , '\bf RIBBON \nabla'},'fontname', 'Calisto MT Fett', 'fontsize', 14);
     set(TH, 'color', 'b')
     zlabel('\bf Probability - Frequency','FontSize',12)
  %   set(gca, 'Xtick', [])
%     t = colorbar('horiz'); 
     set(gca,'FontWeight','demi','FontSize',12);
     colormap(prism)
hold on
hr = get(gca, 'Children');
X = get(hr, 'XData');
Y = get(hr, 'YData');
Z = get(hr, 'Zdata');

% ind = 30;                                         % zwischen 1 und bins wählen 
ind1 = find(Y(:,1) <=cut);              %  anstatt  cut  >> Value
ind2 = find(Y(:,1) >=cut); 

patch([X(ind1,:); X(1,:)],  [Y(ind1,:); Y(cut), Y(cut)],  [Z(ind1,:); 0,0], 'r', 'Facealpha', 0.6); 
patch([X(ind2,:); X(1,:)],  [Y(ind2,:); Y(cut), Y(cut)],  [Z(ind2,:); 0,0], 'c', 'Facealpha', 0.6);

Phi    = normcdf(cut, (P+mu), vola)                 %  Fläche unter dem Quantil bis PF.-cut = 80
hL = legend([' Prob. = ', num2str(Phi*100), '%'], 1)
