Entrainement.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from datetime import datetime, timedelta
  2. import ast
  3. import os
  4. from Processing import *
  5. import importlib
  6. import sys
  7. module_name = "Global"
  8. if len(sys.argv) != 2:
  9. print("Usage: python Entrainement.py <Numerodu global>")
  10. sys.exit(1)
  11. try:
  12. parametre = int(sys.argv[1])
  13. module_name = "Global_" + str(parametre)
  14. except ValueError:
  15. print("Le paramètre doit être un entier.")
  16. sys.exit(1)
  17. try:
  18. imported_module = importlib.import_module(module_name)
  19. except ImportError:
  20. print(f"Aucun fichier {module_name}")
  21. sys.exit(1)
  22. liste_fichiers = []
  23. nbtour=0
  24. valeurs_ponderees =[]
  25. valeurs_date = []
  26. with open("dateE.txt", "r") as file: #le date.txt est modifier pour commencer 30 jours apres
  27. dates = file.readlines()
  28. for date in dates:
  29. date = date.strip()
  30. ponde,da = lirefichier(date)
  31. valeurs_ponderees.append(ponde)
  32. valeurs_date.append(da)
  33. print(len(valeurs_ponderees[0]))
  34. while(nbtour<1000):
  35. Portfeuille = imported_module.PortefeuilleInit
  36. pourc = 0
  37. Action = [0] * 40
  38. weight1 = generatePoids(imported_module.nbCouche1)
  39. weight2 = generatePoids(imported_module.nbCouche2)
  40. weight3 = generatePoids(imported_module.nbCouche3)
  41. weight4 = generatePoids(imported_module.nbCouche4)
  42. couche1 = generateCouche(imported_module.nbCouche1,imported_module.nbCouche0)
  43. couche2 = generateCouche(imported_module.nbCouche2,imported_module.nbCouche1)
  44. couche3 = generateCouche(imported_module.nbCouche3,imported_module.nbCouche2)
  45. couche4 = generateCouche(imported_module.nbCouche4,imported_module.nbCouche3)
  46. print("tour: ",nbtour)
  47. nbtour+=1
  48. for date in range(len(dates)):
  49. res = processing(valeurs_ponderees[date],weight1,weight2,weight3,weight4,couche1,couche2,couche3,couche4,imported_module.nbCouche1,imported_module.nbCouche2,imported_module.nbCouche3,imported_module.nbCouche4)
  50. for i in range(0,40):
  51. Action[i],Portfeuille=evaluation(res[i], valeurs_date[date][i], Action[i], Portfeuille,imported_module.resAchat1,imported_module.resAchat2,imported_module.resAchat3,imported_module.resVente,imported_module.Achat1,imported_module.Achat2,imported_module.Achat3,imported_module.Frais)
  52. pourc = verification(valeurs_date[date],Action,Portfeuille,imported_module.PortefeuilleInit)
  53. if pourc > 1.6:
  54. var=[]
  55. var.append(imported_module.nbCouche1)
  56. var.append(imported_module.nbCouche2)
  57. var.append(imported_module.nbCouche3)
  58. var.append(imported_module.resAchat1)
  59. var.append(imported_module.resAchat2)
  60. var.append(imported_module.resAchat3)
  61. var.append(imported_module.resVente)
  62. enregistre(nbtour,parametre,var,pourc,weight1,weight2,weight3,weight4,couche1,couche2,couche3,couche4)