示例#1
0
     print s1, s2
 
 # create tasks for this batch
 tasks = {}
 task_id = 0
 for i in range(len(strategy_args)):
     args = strategy_args[i]
     for day in days:
         task = {'strategy_id': i, 'strategy_args': args, 
                 'day': day.timetuple()[:3], 'ticker': ticker_details, 
                 'task_id': task_id}
         tasks[task_id] = task
         task_id += 1
 
 # put the tasks in the queue
 queue.putmany(tasks.values())
 print "%s: start analyzing %s tasks" % (str(datetime.now()), len(tasks))
 
 for i in range(len(tasks)):
     result_dict = result.get()
     for task_id, report in result_dict.items():
         tsk = tasks.get(task_id)
         tsk.update({'report': report})
         print "analyzed task: %s" % task_id
     
 p1.stop(); p2.stop()
 p1.join(); p2.join()
 
 # store the pickled tasks in a file for later analysis
 fname = "../simulations/first_run_%s" % start_time.strftime("%Y%m%d%H%M%S")
 f = open(fname, 'w')
示例#2
0
 # create tasks for this batch
 for args in batch_args:
     strategy_id_task_map[strategy_id] = []
     for day in days:
         task = {'strategy_id': strategy_id, 'strategy_args': args, 
                 'day': day.timetuple()[:3], 'ticker': ticker_details, 
                 'task_id': task_id}
         tasks[task_id] = task
         strategy_id_task_map[strategy_id].append(task_id)
         batch_tasks.append(task)
         task_id += 1
     strategy_results[strategy_id] = 0
     strategy_id += 1
 
 # put the tasks in the queue
 queue.putmany(batch_tasks)
 batch_runs += 1
 print "running batch: %s" % batch_runs
 
 for i in range(len(batch_tasks)):
     result_dict = result.get()
     for task_id, report in result_dict.items():
         tsk = tasks.get(task_id)
         tsk.update({'report': report})
         strategy_id = tsk['strategy_id']
         for order_id, order in report.items():
             strategy_results[strategy_id] += order['delta']
         strategy_id_task_map[strategy_id].remove(task_id)
         if not strategy_id_task_map[strategy_id]: # no more tasks for this strategy
             print "all tasks for strategy %s evaluated" % strategy_id
             if strategy_results[strategy_id] >= criterium: