Bonjour,

J'ai posé la question dans le forum python mais apparemment c'est ici qu'il faut demander.

Voici le problème :
Soit un univers de 20 actions. Chaque action a une note ESG, ODD et Carbon qui vont de 1 à 10.
L'objectif est de retrouver un portefeuille de 3 actions qui a la meilleure moyenne des 3 notes: ((somme note ESG/3) + (somme note ODD / 3) + (Somme note Carbone / 3) / 3

Voici mon code qui fonctionne:

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
 
from itertools import combinations
import pandas as pd
 
actions = {
    "action1": {"ESG": 8, "ODD": 5, "Carbon": 6},
    "action2": {"ESG": 7, "ODD": 9, "Carbon": 3},
    "action3": {"ESG": 9, "ODD": 7, "Carbon": 4},
    "action4": {"ESG": 10, "ODD": 4, "Carbon": 8},
    "action5": {"ESG": 3, "ODD": 10, "Carbon": 1},
    "action6": {"ESG": 4, "ODD": 6, "Carbon": 7},
    "action7": {"ESG": 6, "ODD": 2, "Carbon": 10},
    "action8": {"ESG": 1, "ODD": 8, "Carbon": 5},
    "action9": {"ESG": 5, "ODD": 3, "Carbon": 9},
    "action10": {"ESG": 2, "ODD": 1, "Carbon": 2},
    "action11": {"ESG": 10, "ODD": 8, "Carbon": 5},
    "action12": {"ESG": 7, "ODD": 4, "Carbon": 3},
    "action13": {"ESG": 8, "ODD": 5, "Carbon": 6},
    "action14": {"ESG": 4, "ODD": 9, "Carbon": 2},
    "action15": {"ESG": 3, "ODD": 10, "Carbon": 1},
    "action16": {"ESG": 6, "ODD": 2, "Carbon": 10},
    "action17": {"ESG": 9, "ODD": 1, "Carbon": 8},
    "action18": {"ESG": 5, "ODD": 7, "Carbon": 4},
    "action19": {"ESG": 2, "ODD": 3, "Carbon": 7},
    "action20": {"ESG": 1, "ODD": 6, "Carbon": 9}
}
 
x = 3
df = pd.DataFrame(columns=['actions', 'ESG', 'ODD', 'Carbon', 'Moyenne'])
 
for combi in combinations(actions.keys(), x):
    ESG = 0
    ODD = 0
    Carbon = 0
    for action in combi:
        ESG += actions[action]['ESG']
        ODD += actions[action]['ODD']
        Carbon += actions[action]['Carbon']
    df = df.append({'actions': combi, 'ESG': ESG/3, 'ODD': ODD/3, 'Carbon': Carbon/3, 'Moyenne': ((ESG/3)+(ODD/3)+(Carbon/3))/3}, ignore_index=True)
 
print(df)
Mon soucis c'est que dans le cas ci-dessus un univers de 20 actions et un portefeuille de 3 actions, soit 1139 combinaisons possible.
Dans la réalité, il y a 1500 actions et le portefeuille peut en contenir jusqu'à 500. Le nombre de combinaison possible est colossal et le calcul est interminable.

Quelqu'un saurait comment rechercher le meilleur portefeuille en prenant en compte les contraintes?
Merci.