1919from src .portfolio import (
2020 calculate_expected_returns_and_cov ,
2121 MOEADOptimizer ,
22+ MOEADDRAOptimizer ,
23+ MOEADAWAOptimizer ,
2224)
2325from src .visualization import plot_population_evolution
2426
@@ -38,14 +40,13 @@ def run_evolution_demo():
3840 seed_everything (42 )
3941
4042 # Setup folders
41- run_id = datetime .now ().strftime ("%Y%m%d_%H%M%S_moead_evolution " )
43+ run_id = datetime .now ().strftime ("%Y%m%d_%H%M%S_moead_evolution_all " )
4244 run_folder = os .path .join (OUTPUT_FOLDER , run_id )
4345 os .makedirs (run_folder , exist_ok = True )
4446
45- print (f"Starting MOEA/D Evolution Demo. Result will be saved to { run_folder } " )
47+ print (f"Starting Multi-Variant Evolution Demo. Results will be saved to { run_folder } " )
4648
4749 # 1. Load data and calculate expected returns/cov
48- # (Simplified data hash for speed in this demo)
4950 raw_data_dict = load_data (DATA_FOLDER , ASSET_NAMES , verbose = False )
5051 predictor = ExactGPPredictor (
5152 training_iterations = TRAINING_ITERATIONS ,
@@ -62,35 +63,46 @@ def run_evolution_demo():
6263
6364 data_kwargs = {"expected_returns" : expected_returns , "cov_matrix" : cov_matrix }
6465
65- # 2. Run MOEA/D with history recording
66- print ("Running MOEA/D with history recording (interval=10)..." )
67- moead = MOEADOptimizer ()
66+ # 2. Variants to test
67+ variants = {
68+ "MOEA/D" : MOEADOptimizer ,
69+ "MOEA/D-DRA" : MOEADDRAOptimizer ,
70+ "MOEA/D-AWA" : MOEADAWAOptimizer ,
71+ }
72+
6873 history_interval = 10
6974 generations = 200
7075
71- # generate_pareto_front returns: metrics, population, weight_vectors, history (if record_history=True)
72- results = moead .generate_pareto_front (
73- num_points = 100 ,
74- generations = generations ,
75- verbose = True ,
76- record_history = True ,
77- history_interval = history_interval ,
78- ** data_kwargs ,
79- )
76+ for name , OptimizerClass in variants .items ():
77+ print (f"\n Processing { name } ..." )
78+ optimizer = OptimizerClass ()
8079
81- # unpack results
82- moead_metrics , _ , _ , history = results
80+ # generate_pareto_front returns: metrics, population, weight_vectors, history (if record_history=True)
81+ results = optimizer .generate_pareto_front (
82+ num_points = 100 ,
83+ generations = generations ,
84+ verbose = True ,
85+ record_history = True ,
86+ history_interval = history_interval ,
87+ ** data_kwargs ,
88+ )
8389
84- # 3. Plot Population Evolution
85- print ("Generating Population Evolution Plot..." )
86- obj_names = ["Expected Return" , "Expected Risk" ]
87- save_path = os .path .join (run_folder , "population_evolution.png" )
90+ # unpack results
91+ _metrics , _ , _ , history = results
8892
89- plot_population_evolution (
90- history , obj_names , history_interval = history_interval , save_path = save_path
91- )
93+ # 3. Plot Population Evolution
94+ print (f"Generating Population Evolution Plot for { name } ..." )
95+ obj_names = ["Expected Return" , "Expected Risk" ]
96+ safe_name = name .replace ("/" , "" ).replace ("-" , "_" ).lower ()
97+ save_path = os .path .join (run_folder , f"evolution_{ safe_name } .png" )
98+
99+ plot_population_evolution (
100+ history , obj_names , history_interval = history_interval , save_path = save_path
101+ )
102+
103+ print (f"Done! Plot saved to { save_path } " )
92104
93- print (f"Success! Plot saved to { save_path } " )
105+ print (f"\n All experiments finished. Results in { run_folder } " )
94106
95107
96108if __name__ == "__main__" :
0 commit comments