ScottfreeLLC / AlphaPy

Python AutoML for Trading Systems and Sports Betting
Apache License 2.0
1.14k stars 207 forks source link

Support Multiple Systems #36

Open sykesdev opened 4 years ago

sykesdev commented 4 years ago

This change allows the ability to add multiple systems to the market.yml

The modified yaml would look like...

system:
  closer_scaled:
    holdperiod : 0
    longentry  : hc
    longexit   :
    shortentry : lc
    shortexit  :
    scale      : True
  closer_unscaled:
    holdperiod : 0
    longentry  : hc
    longexit   :
    shortentry : lc
    shortexit  :
    scale      : False
@@ -298,26 +299,27 @@ def market_pipeline(model, market_specs):
     system_specs = market_specs['system']
     if system_specs:
         # get the system specs
-        system_name = system_specs['name']
-        longentry = system_specs['longentry']
-        shortentry = system_specs['shortentry']
-        longexit = system_specs['longexit']
-        shortexit = system_specs['shortexit']
-        holdperiod = system_specs['holdperiod']
-        scale = system_specs['scale']
-        logger.info("Running System %s", system_name)
-        logger.info("Long Entry  : %s", longentry)
-        logger.info("Short Entry : %s", shortentry)
-        logger.info("Long Exit   : %s", longexit)
-        logger.info("Short Exit  : %s", shortexit)
-        logger.info("Hold Period : %d", holdperiod)
-        logger.info("Scale       : %r", scale)
-        # create and run the system
-        system = System(system_name, longentry, shortentry,
-                        longexit, shortexit, holdperiod, scale)
-        tfs = run_system(model, system, group, intraday)
-        # generate a portfolio
-        gen_portfolio(model, system_name, group, tfs)
+        for system_name in system_specs:
+            longentry = system_specs[system_name]['longentry']
+            shortentry = system_specs[system_name]['shortentry']
+            longexit = system_specs[system_name]['longexit']
+            shortexit = system_specs[system_name]['shortexit']
+            holdperiod = system_specs[system_name]['holdperiod']
+            scale = system_specs[system_name]['scale']
+            logger.info("Running System %s", system_name)
+            logger.info("Long Entry  : %s", longentry)
+            logger.info("Short Entry : %s", shortentry)
+            logger.info("Long Exit   : %s", longexit)
+            logger.info("Short Exit  : %s", shortexit)
+            logger.info("Hold Period : %d", holdperiod)
+            logger.info("Scale       : %r", scale)
+            # create and run the system
+            system = System(system_name, longentry, shortentry,
+                            longexit, shortexit, holdperiod, scale)
+            tfs = run_system(model, system, group, intraday)
+            # generate a portfolio
+            gen_portfolio(model, system_name, group, tfs)

     # Return the completed model
     return model
mrconway commented 4 years ago

Great suggestion, thank you.