Bonjour,

je travaille actuellement sur de l'allocation de portefeuilles (Finance de Marché) et j'ai brièvement codé (à la va-vite) une fonction Matlab qui me permet de définir les allocations initiales en fonction de poids initiaux, finaux et d'un pas d'incrément. Je m'explique : je possède entre 30 et 40 titres de poids initiaux définis (Titre 1 : 0% Titre 2 : 10% ... Titre 40 : 30%) ainsi que finaux (Titre 1 : 100% Titre 2 : 100% ... Titre 40 : 100%) et j'aimerai définir toutes les combinaisons possibles entre les poids selon un pas sur chaque titre...
Par exemple un portefeuille de 2 titres A et B de poids initiaux (0%, 0%) et finaux (100%, 100%) avec les pas d'incréments (20%, 40%) me donne au final les vecteurs : (0%, 100%) (100%, 0%) (20%, 80%) (60% 40%)
(sous la condition que la somme des poids est tjrs égale à 100%).

Voici donc mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
function [Allocations] = PoidsInitiaux4(AllocationInitiale, Incrementation, AllocationFinale)
 
%--------------------------------------------------------------------------
 
% Vérification du nombre d'arguments.
  if nargin ~= 3
     error 'Nombre d''arguments incorrect !' 
  end
 
% Mise en place des allocations.
  Taille = length(AllocationInitiale);
  Allocations = zeros(Taille, 65500);     
 
  Numero = 0;
 
% Cas d'étude d'un portefeuille constitué de trente et un à quarante fonds.    
  if Taille == 31
     for a = AllocationInitiale(1, 1) : Incrementation(1, 1) : (AllocationFinale(1, 1)+eps*100)  
         for b = AllocationInitiale(2, 1) : Incrementation(2, 1) : (AllocationFinale(2, 1)+eps*100) 
             for c = AllocationInitiale(3, 1) : Incrementation(3, 1) : (AllocationFinale(3, 1)+eps*100) 
                 for d = AllocationInitiale(4, 1) : Incrementation(4, 1) : (AllocationFinale(4, 1)+eps*100) 
                     for e = AllocationInitiale(5, 1) : Incrementation(5, 1) : (AllocationFinale(5, 1)+eps*100)  
                         for f = AllocationInitiale(6, 1) : Incrementation(6, 1) : (AllocationFinale(6, 1)+eps*100)  
                             for g = AllocationInitiale(7, 1) : Incrementation(7, 1) : (AllocationFinale(7, 1)+eps*100)
                                 for h = AllocationInitiale(8, 1) : Incrementation(8, 1) : (AllocationFinale(8, 1)+eps*100)
                                     for i = AllocationInitiale(9, 1) : Incrementation(9, 1) : (AllocationFinale(9, 1)+eps*100)   
                                         for j = AllocationInitiale(10, 1) : Incrementation(10, 1) : (AllocationFinale(10, 1)+eps*100)
                                             for k = AllocationInitiale(11, 1) : Incrementation(11, 1) : (AllocationFinale(11, 1)+eps*100)
                                                 for l = AllocationInitiale(12, 1) : Incrementation(12, 1) : (AllocationFinale(12, 1)+eps*100)
                                                     for m = AllocationInitiale(13, 1) : Incrementation(13, 1) : (AllocationFinale(13, 1)+eps*100)
                                                         for n = AllocationInitiale(14, 1) : Incrementation(14, 1) : (AllocationFinale(14, 1)+eps*100)
                                                             for o = AllocationInitiale(15, 1) : Incrementation(15, 1) : (AllocationFinale(15, 1)+eps*100)
                                                                 for p = AllocationInitiale(16, 1) : Incrementation(16, 1) : (AllocationFinale(16, 1)+eps*100)
                                                                     for q = AllocationInitiale(17, 1) : Incrementation(17, 1) : (AllocationFinale(17, 1)+eps*100)
                                                                         for r = AllocationInitiale(18, 1) : Incrementation(18, 1) : (AllocationFinale(18, 1)+eps*100)
                                                                             for s = AllocationInitiale(19, 1) : Incrementation(19, 1) : (AllocationFinale(19, 1)+eps*100)
                                                                                 for t = AllocationInitiale(20, 1) : Incrementation(20, 1) : (AllocationFinale(20, 1)+eps*100)
                                                                                     for u = AllocationInitiale(21, 1) : Incrementation(21, 1) : (AllocationFinale(21, 1)+eps*100)
                                                                                         for v = AllocationInitiale(22, 1) : Incrementation(22, 1) : (AllocationFinale(22, 1)+eps*100)
                                                                                             for w = AllocationInitiale(23, 1) : Incrementation(23, 1) : (AllocationFinale(23, 1)+eps*100)
                                                                                                 for x = AllocationInitiale(24, 1) : Incrementation(24, 1) : (AllocationFinale(24, 1)+eps*100)
                                                                                                     for y = AllocationInitiale(25, 1) : Incrementation(25, 1) : (AllocationFinale(25, 1)+eps*100) 
                                                                                                         for z = AllocationInitiale(26, 1) : Incrementation(26, 1) : (AllocationFinale(26, 1)+eps*100)   
                                                                                                             for aa = AllocationInitiale(27, 1) : Incrementation(27, 1) : (AllocationFinale(27, 1)+eps*100)  
                                                                                                                 for bb = AllocationInitiale(28, 1) : Incrementation(28, 1) : (AllocationFinale(28, 1)+eps*100) 
                                                                                                                     for cc = AllocationInitiale(29, 1) : Incrementation(29, 1) : (AllocationFinale(29, 1)+eps*100)
                                                                                                                         for dd = AllocationInitiale(30, 1) : Incrementation(30, 1) : (AllocationFinale(30, 1)+eps*100)
                                                                                                                             if (1-a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-aa-bb-cc-dd) > (AllocationInitiale(31, 1)-eps*100) && (1-a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-aa-bb-cc-dd) < (AllocationFinale(31, 1)+eps*100)
                                                                                                                                Numero = Numero+1;      
 
                                                                                                                                if Numero > 65500
                                                                                                                                   error 'Nombre maximal de portefeuilles atteint !';
                                                                                                                                end
 
                                                                                                                                Allocations(:, Numero) = [a ; b ; c ; d ; e ; f ; g ; h ; i ; j ; k ; l ; m ; n ; o ; p ; q ; r ; s ; t ; u ; v ; w ; x ; y ; z ; aa ; bb ; cc ; dd ; 1-(a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z+aa+bb+cc+dd)]; 
                                                                                                                             end
                                                                                                                         end
                                                                                                                     end
                                                                                                                 end
                                                                                                             end
                                                                                                         end
                                                                                                     end
                                                                                                 end
                                                                                             end
                                                                                         end
                                                                                     end
                                                                                 end
                                                                             end
                                                                         end
                                                                     end
                                                                 end
                                                             end
                                                         end
                                                     end
                                                 end
                                             end
                                         end
                                     end
                                 end
                             end
                         end
                     end
                 end
             end  
         end
     end
 
....coupe du code...
 
     if Numero == 0
        Allocations = zeros(39, 1); 
     end     
 elseif Taille == 40
     for a = AllocationInitiale(1, 1) : Incrementation(1, 1) : (AllocationFinale(1, 1)+eps*100)  
         for b = AllocationInitiale(2, 1) : Incrementation(2, 1) : (AllocationFinale(2, 1)+eps*100) 
             for c = AllocationInitiale(3, 1) : Incrementation(3, 1) : (AllocationFinale(3, 1)+eps*100) 
                 for d = AllocationInitiale(4, 1) : Incrementation(4, 1) : (AllocationFinale(4, 1)+eps*100) 
                     for e = AllocationInitiale(5, 1) : Incrementation(5, 1) : (AllocationFinale(5, 1)+eps*100)  
                         for f = AllocationInitiale(6, 1) : Incrementation(6, 1) : (AllocationFinale(6, 1)+eps*100)  
                             for g = AllocationInitiale(7, 1) : Incrementation(7, 1) : (AllocationFinale(7, 1)+eps*100)
                                 for h = AllocationInitiale(8, 1) : Incrementation(8, 1) : (AllocationFinale(8, 1)+eps*100)
                                     for i = AllocationInitiale(9, 1) : Incrementation(9, 1) : (AllocationFinale(9, 1)+eps*100)   
                                         for j = AllocationInitiale(10, 1) : Incrementation(10, 1) : (AllocationFinale(10, 1)+eps*100)
                                             for k = AllocationInitiale(11, 1) : Incrementation(11, 1) : (AllocationFinale(11, 1)+eps*100)
                                                 for l = AllocationInitiale(12, 1) : Incrementation(12, 1) : (AllocationFinale(12, 1)+eps*100)
                                                     for m = AllocationInitiale(13, 1) : Incrementation(13, 1) : (AllocationFinale(13, 1)+eps*100)
                                                         for n = AllocationInitiale(14, 1) : Incrementation(14, 1) : (AllocationFinale(14, 1)+eps*100)
                                                             for o = AllocationInitiale(15, 1) : Incrementation(15, 1) : (AllocationFinale(15, 1)+eps*100)
                                                                 for p = AllocationInitiale(16, 1) : Incrementation(16, 1) : (AllocationFinale(16, 1)+eps*100)
                                                                     for q = AllocationInitiale(17, 1) : Incrementation(17, 1) : (AllocationFinale(17, 1)+eps*100)
                                                                         for r = AllocationInitiale(18, 1) : Incrementation(18, 1) : (AllocationFinale(18, 1)+eps*100)
                                                                             for s = AllocationInitiale(19, 1) : Incrementation(19, 1) : (AllocationFinale(19, 1)+eps*100)
                                                                                 for t = AllocationInitiale(20, 1) : Incrementation(20, 1) : (AllocationFinale(20, 1)+eps*100)
                                                                                     for u = AllocationInitiale(21, 1) : Incrementation(21, 1) : (AllocationFinale(21, 1)+eps*100)
                                                                                         for v = AllocationInitiale(22, 1) : Incrementation(22, 1) : (AllocationFinale(22, 1)+eps*100)
                                                                                             for w = AllocationInitiale(23, 1) : Incrementation(23, 1) : (AllocationFinale(23, 1)+eps*100)
                                                                                                 for x = AllocationInitiale(24, 1) : Incrementation(24, 1) : (AllocationFinale(24, 1)+eps*100)
                                                                                                     for y = AllocationInitiale(25, 1) : Incrementation(25, 1) : (AllocationFinale(25, 1)+eps*100) 
                                                                                                         for z = AllocationInitiale(26, 1) : Incrementation(26, 1) : (AllocationFinale(26, 1)+eps*100)   
                                                                                                             for aa = AllocationInitiale(27, 1) : Incrementation(27, 1) : (AllocationFinale(27, 1)+eps*100)  
                                                                                                                 for bb = AllocationInitiale(28, 1) : Incrementation(28, 1) : (AllocationFinale(28, 1)+eps*100) 
                                                                                                                     for cc = AllocationInitiale(29, 1) : Incrementation(29, 1) : (AllocationFinale(29, 1)+eps*100)
                                                                                                                         for dd = AllocationInitiale(30, 1) : Incrementation(30, 1) : (AllocationFinale(30, 1)+eps*100)
                                                                                                                             for ee = AllocationInitiale(31, 1) : Incrementation(31, 1) : (AllocationFinale(31, 1)+eps*100)
                                                                                                                                 for ff = AllocationInitiale(32, 1) : Incrementation(32, 1) : (AllocationFinale(32, 1)+eps*100)
                                                                                                                                     for gg = AllocationInitiale(33, 1) : Incrementation(33, 1) : (AllocationFinale(33, 1)+eps*100)
                                                                                                                                         for hh = AllocationInitiale(34, 1) : Incrementation(34, 1) : (AllocationFinale(34, 1)+eps*100)
                                                                                                                                             for ii = AllocationInitiale(35, 1) : Incrementation(35, 1) : (AllocationFinale(35, 1)+eps*100)
                                                                                                                                                 for jj = AllocationInitiale(36, 1) : Incrementation(36, 1) : (AllocationFinale(36, 1)+eps*100)
                                                                                                                                                     for kk = AllocationInitiale(37, 1) : Incrementation(37, 1) : (AllocationFinale(37, 1)+eps*100)
                                                                                                                                                         for ll = AllocationInitiale(38, 1) : Incrementation(38, 1) : (AllocationFinale(38, 1)+eps*100)
                                                                                                                                                             for mm = AllocationInitiale(39, 1) : Incrementation(39, 1) : (AllocationFinale(39, 1)+eps*100)
                                                                                                                                                                 if (1-a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-aa-bb-cc-dd-ee-ff-gg-hh-ii-jj-kk-ll-mm) > (AllocationInitiale(40, 1)-eps*100) && (1-a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-aa-bb-cc-dd-ee-ff-gg-hh-ii-jj-kk-ll-mm) < (AllocationFinale(40, 1)+eps*100)
                                                                                                                                                                    Numero = Numero+1;      
 
                                                                                                                                                                    if Numero > 65500
                                                                                                                                                                       error 'Nombre maximal de portefeuilles atteint !';
                                                                                                                                                                    end
 
                                                                                                                                                                    Allocations(:, Numero) = [a ; b ; c ; d ; e ; f ; g ; h ; i ; j ; k ; l ; m ; n ; o ; p ; q ; r ; s ; t ; u ; v ; w ; x ; y ; z ; aa ; bb ; cc ; dd ; ee ; ff ; gg ; hh ; ii ; jj ; kk ; ll ; mm ; 1-(a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z+aa+bb+cc+dd+ee+ff+gg+hh+ii+jj+kk+ll+mm)]; 
                                                                                                                                                                 end
                                                                                                                                                             end
                                                                                                                                                         end
                                                                                                                                                     end
                                                                                                                                                 end
                                                                                                                                             end
                                                                                                                                         end
                                                                                                                                     end
                                                                                                                                 end
                                                                                                                             end
                                                                                                                         end
                                                                                                                     end
                                                                                                                 end
                                                                                                             end
                                                                                                         end
                                                                                                     end
                                                                                                 end
                                                                                             end
                                                                                         end
                                                                                     end
                                                                                 end
                                                                             end
                                                                         end
                                                                     end
                                                                 end
                                                             end
                                                         end
                                                     end
                                                 end
                                             end
                                         end
                                     end
                                 end
                             end
                         end
                     end
                 end
             end  
         end
     end
     if Numero == 0
        Allocations = zeros(40, 1); 
     end      
  end 
 
  AllocationsFin = Allocations(:, sum(Allocations, 1) ~= 0);
  Allocations = AllocationsFin;
Le soucis est que ce dernier n'est pas du tout optimisé et prend énormément de temps à s'executer...

Avez-vous quelques pistes à me donner afin d'améliorer le temps d'execution de cette fonction ?

Je vous remercie de votre attention.