SHARE
TWEET

Untitled

a guest Jun 26th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class TradingStrategyExecutor(object):
  2.   """Executes a trading strategy, its computations. Computational resources."""
  3.  
  4.   def ExecuteStrategy(self, strategy, market_data, session):
  5.     """Executes given strategy.
  6.  
  7.   Args:
  8.     strategy: TradingStrategy.
  9.     other: see TradingStrategy.Evaluate.
  10.   """
  11.  
  12.   @classmethod
  13.   def GetExecutor(cls):
  14.     """Provides a suitable strategy executor for given strategy computation.
  15.  
  16.   Chooses between in-process and Hadoop executor, depending on estimated
  17.   amount of computation and available machine resources.
  18.  
  19.   Returns:
  20.     TradingStrategyExecutor. One of predefined classes.
  21.   """
  22.  
  23.  
  24. class TradingStrategyInProcessExecutor(TradingStrategyExecutor):
  25.   """Executes trading strategy computation in-process, on local machine."""
  26.  
  27.   def ExecuteStrategy(self, strategy, market_data, session):
  28.     """See base class."""
  29.  
  30.  
  31. class TradingStrategyHadoopExecutor(TradingStrategyExecutor):
  32.   """Executes trading strategy computation in a Hadoop cluster, distributed."""
  33.  
  34.   def __init__(self, hadoop_manager):
  35.     """Constructor.
  36.  
  37.   Args:
  38.     hadoop_manager: HadoopManager. For delegating computation to Hadoop.
  39.   """
  40.  
  41.   def ExecuteStrategy(self, strategy, market_data, session):
  42.     """See base class."""
  43.  
  44.   def _CreateJobConfiguration(self, strategy, market_data, session):
  45.     """Creates a hadoop job description for given strategy execution.
  46.  
  47.   Returns:
  48.     hadoop.Configuration. Hadoop job configuration describing given strategy
  49.       execution, suitable for execution in a Hadoop cluster.
  50.   """
  51.  
  52.  
  53. class HadoopManager(object):
  54.   """Manager of Hadoop jobs. Starts / stops / monitors jobs.
  55.  
  56. Interface to a Hadoop cluster.
  57. """
  58.  
  59.   def CreateJob(self, configuration):
  60.     """Creates a new job from job configuration.
  61.  
  62.   Args:
  63.     configuration: Configuration. Job to run.
  64.   Returns:
  65.     Job.
  66.   """
  67.  
  68.   def GetActiveJobs(self):
  69.     """Returns jobs that have not completed yet.
  70.  
  71.   Returns:
  72.     list of Job.
  73.   """
  74.  
  75.   def OnJobCompletion(self, callback):
  76.     """Registers a callback to be called when a job completes (of fails).
  77.  
  78.   Args:
  79.     callback: callable(Job).
  80.   """
  81.  
  82.  
  83. class HadoopJob(object):
  84.   """An executable task (a piece of computation) running in a Hadoop cluster."""
  85.  
  86.   def Run(self, wait_for_completion=True):
  87.     """Runs the job.
  88.  
  89.   Args:
  90.     wait_for_completion: bool. Whether to block until the job completes.
  91.   """
  92.  
  93.   @property
  94.   def status(self):
  95.     """Job execution status."""
  96.  
  97.   def GetCounters(self, counters=()):
  98.     """Returns job-specific counters.
  99.  
  100.   Args:
  101.     counters: list of str. Counters to return. Defaults to all.
  102.   Returns:
  103.     dict, str -> Counter.
  104.  """
  105.  
  106.  
  107. class MarketDataSlicer(object):
  108.   """Generates slices of market data from complete market data.
  109.  
  110. The slices are typically of short and equal duration.
  111.  
  112. For distributing market data processing into independent tasks,
  113. over disjoint time slices.
  114. """
  115.  
  116.   def __init__(self, market_data):
  117.     """Constructor.
  118.  
  119.   Args:
  120.     market_data: MarketData. Complete market data to generate slices from.
  121.   """
  122.  
  123.   def IterMarketDataSlices(self, num_slices=None, slice_duration=None):
  124.     """Generates slices of market data.
  125.  
  126.   Args:
  127.     num_slices: int. Desired number of equi-duration slices.
  128.     slice_duration: datetime.timedelta. Desired duration of resulting slices.
  129.       num_slices and slice_duration are mutually exclusive.
  130.   Yields:
  131.     MarketData. Slices.
  132.   """
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top