Mariner Backtesting - service.enable_profiling()

service.enable_profiling()

enable_profiling() re-enables the profiling process.

Interface:
 enable_profiling()

Sample - Calling Method

 service.enable_profiling()
Parameters:
  • None
Returns:

None

Remarks:
  • Counteracts the effects of disable_profiling()
  • Used with disable_profiling() to control exactly what code is profiled.
  • The backtest must already be set to profile.
  • enable_profiling does not begin the profiling process, it only continues the process.
  • Has no effect in forward testing.
Working Example:

Use enable_profiling() and disable_profiling to ensure accurate profiling results.

from cloudquant.interfaces import Strategy


class Enable_Profiling(Strategy):
    # note that this doesn't start with "self" because it's a @staticmethod
    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return symbol == 'AAL'

    # called at the beginning of each instance
    def on_start(self, md, order, service, account):
        self.minute_bar_count = 0

    def on_minute_bar(self, event, md, order, service, account, bar):

        # disable profiling on the first call of the methods to avoid innacurate data
        if self.minute_bar_count == 0:
            service.disable_profiling()

        # test calls
        print 'service.time_to_string(event.timestamp)'
        print md.L1.last
        print md.bar.minute(-1)
        print md.bar.daily(-1)
        service.symbol_list.get_handle('448CBB9E-CFDE-4A55-BB7B-7521080E5A0B')

        # re-enable profiling
        if self.minute_bar_count == 0:
            service.enable_profiling()

        # terminate after the fifth bar
        elif self.minute_bar_count == 4:
            service.terminate()

        # increment counter
        self.minute_bar_count += 1

Profiling Results

Timer unit: 1e-06 s

Total time: 0 s
File: job/enable_profiling.py
Function: is_symbol_qualified at line 6

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
     6                                               @classmethod
     7                                               def is_symbol_qualified(cls, symbol, md, service, account):
     8                                                   return symbol == 'AAL'

Total time: 7e-06 s
File: job/enable_profiling.py
Function: on_start at line 11

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
    11                                               def on_start(self, md, order, service, account):
    12         1            7      7.0    100.0          self.minute_bar_count = 0

Total time: 0.056938 s
File: job/enable_profiling.py
Function: on_minute_bar at line 14

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
    14                                               def on_minute_bar(self, event, md, order, service, account, bar):
    15
    16                                                   # disable profiling on the first call of the methods to avoid innacurate data
    17         5           16      3.2      0.0          if self.minute_bar_count == 0:
    18                                                       service.disable_profiling()
    19
    20                                                   # test calls
    21         4           67     16.8      0.1          print 'service.time_to_string(event.timestamp)'
    22         4           89     22.2      0.2          print md.L1.last
    23         4        28230   7057.5     49.6          print md.bar.minute(-1)
    24         4        28360   7090.0     49.8          print md.bar.daily(-1)
    25         4          142     35.5      0.2          service.symbol_list.get_handle('448CBB9E-CFDE-4A55-BB7B-7521080E5A0B')
    26
    27                                                   # re-enable profiling
    28         4            6      1.5      0.0          if self.minute_bar_count == 0:
    29                                                       service.enable_profiling()
    30
    31                                                   # terminate after the fifth bar
    32         4            2      0.5      0.0          elif self.minute_bar_count == 4:
    33         1           18     18.0      0.0              service.terminate()
    34
    35                                                   # increment counter
    36         5            8      1.6      0.0          self.minute_bar_count += 1