# Path: OpenTrader/doer.py
# class Doer(PLogMixin):
#     """The Doer class has one main method: bexecute
# which will execute the options and args given to it
# in the do_instance method of the Cmd2 instance.
# 
# It encapsulkates everything tthat is needed to do a
# command in the Cmd2 instance.
# """
# 
#     def __init__(self, ocmd2, sprefix):
#         self.ocmd2 = ocmd2
#         self.poutput = self.ocmd2.poutput
#         self.pfeedback = self.ocmd2.pfeedback
#         self.sprefix = sprefix
# 
#     def G(self, gVal=None):
#         if gVal is not None:
#             self.ocmd2._G = gVal
#             self._G = self.ocmd2._G
#         return self.ocmd2._G
# 
#     def vassert_args(self, lArgs, lcommands, imin=1):
#         assert len(lArgs) >= imin, \
#                "ERROR: argument required, one of: " +str(lcommands)
#         sDo = lArgs[0]
#         assert  sDo in lcommands + ['help'], \
#           "ERROR: " +sDo +" choose one of: " +str(lcommands)
# 
#     def bis_help(self, lArgs):
#         sDo = lArgs[0]
#         # e.g. make help
#         if sDo != 'help':
#             return False
#         if not hasattr(self, 'lCommands'):
#             lCommands = []
#             for sElt in dir(self):
#                 if not sElt.startswith(self.sprefix): continue
#                 sKey = sElt[len(self.sprefix)+1:]
#                 lCommands.append(sKey)
#             self.lCommands = lCommands
#         if len(lArgs) == 1:
#             self.poutput(self.dhelp[''])
#             # N.B.: subcommands by convention are documented in the module docstring
#             self.poutput("For help on subcommands type: " +self.sprefix +" help <sub> ")
#             self.poutput("For help on options type: help " +self.sprefix)
#             return True
#         # e.g. make help features
#         smeth = lArgs[1]
#         smethod = self.sprefix +'_' + smeth
#         # FixMe: make a wrapper so this isnt needed?
#         if smeth not in self.dhelp and hasattr(self, smethod):
#             omethod = getattr(self, smethod)
#             if hasattr(omethod, '__doc__'):
#                 self.dhelp[smeth] = omethod.__doc__
#         if smeth in self.dhelp:
#             self.poutput(self.dhelp[smeth])
#             self.poutput("For help on options type: help " +self.sprefix)
#             return True
#         raise NotImplementedError("Unknown help command for " +sDo +": " \
#                                       +smeth +' not in ' +repr(self.lCommands))
# 
#     def bexecute(self, loptions, dkw):
#         raise NotImplementedError(self.__class__.__name__)
# 
#     def vInfo(self, sMsg):
#         self.poutput("INFO: " +sMsg)
# 
#     def vWarn(self, sMsg):
#         self.poutput("WARN: " +sMsg)
# 
#     def vError(self, sMsg):
#         self.poutput("ERROR: " +sMsg)


import sys
import os
import traceback
                    import glob
            import yaml
            import matplotlib
            import numpy as np
        import warnings
        import matplotlib
        import matplotlib.pylab as pylab
from optparse import make_option
from pprint import pprint, pformat
    from OpenTrader.deps import tabview
from OpenTrader.OTUtils import sStripCreole, lConfigToList
from OpenTrader.doer import Doer
    from OpenTrader.Omlettes import Omlette
            from OpenTrader.PandasMt4 import oReadMt4Csv
            from OpenTrader.PandasMt4 import oReadMt4Csv, oPreprocessOhlc, vResampleFiles
            from OpenTrader.OTPpnAmgc import vGraphData
            from OpenTrader.OTBackTest import oPreprocessOhlc
            from OpenTrader.Omlettes import lKnownRecipes
        from OpenTrader.Omlettes import lKnownChefs
            from OpenTrader.OTBackTest import oPyBacktestCook
def oEnsureChef(ocmd2, oValues, sNewChef=""):
    oOm = oEnsureOmlette(ocmd2, oValues)
    if not sNewChef and hasattr(oOm, 'oChefModule') and oOm.oChefModule:
        return oOm.oChefModule
    if not sNewChef:
        # The are set earlier in the call to do_back
        sNewChef = ocmd2.sChef
    if hasattr(oOm, 'oChefModule') and oOm.oChefModule and oOm.oChefModule.sChef:
        sOldName = oOm.oChefModule.sChef
    else:
        sOldName = ""
    oChefModule = oOm.oAddChef(sNewChef)
    if sOldName and sOldName != sNewChef:
        #? do we invalidate the current servings if the chef changed?
        vClearOven(ocmd2, oValues)
    return oOm.oChefModule

def vClearOven(ocmd2, oValues):
    oOm = oEnsureOmlette(ocmd2, oValues)
    oOm.oBt = None

class DoBacktest(Doer):
    __doc__ = SDOC
    # putting this as a module variable backtest it available
    # before an instance has been instantiated.
    global LCOMMANDS

    dhelp = {'': __doc__}

    def __init__(self, ocmd2):

# Path: OpenTrader/doer.py
# class Doer(PLogMixin):
#     """The Doer class has one main method: bexecute
# which will execute the options and args given to it
# in the do_instance method of the Cmd2 instance.
# 
# It encapsulkates everything tthat is needed to do a
# command in the Cmd2 instance.
# """
# 
#     def __init__(self, ocmd2, sprefix):
#         self.ocmd2 = ocmd2
#         self.poutput = self.ocmd2.poutput
#         self.pfeedback = self.ocmd2.pfeedback
#         self.sprefix = sprefix
# 
#     def G(self, gVal=None):
#         if gVal is not None:
#             self.ocmd2._G = gVal
#             self._G = self.ocmd2._G
#         return self.ocmd2._G
# 
#     def vassert_args(self, lArgs, lcommands, imin=1):
#         assert len(lArgs) >= imin, \
#                "ERROR: argument required, one of: " +str(lcommands)
#         sDo = lArgs[0]
#         assert  sDo in lcommands + ['help'], \
#           "ERROR: " +sDo +" choose one of: " +str(lcommands)
# 
#     def bis_help(self, lArgs):
#         sDo = lArgs[0]
#         # e.g. make help
#         if sDo != 'help':
#             return False
#         if not hasattr(self, 'lCommands'):
#             lCommands = []
#             for sElt in dir(self):
#                 if not sElt.startswith(self.sprefix): continue
#                 sKey = sElt[len(self.sprefix)+1:]
#                 lCommands.append(sKey)
#             self.lCommands = lCommands
#         if len(lArgs) == 1:
#             self.poutput(self.dhelp[''])
#             # N.B.: subcommands by convention are documented in the module docstring
#             self.poutput("For help on subcommands type: " +self.sprefix +" help <sub> ")
#             self.poutput("For help on options type: help " +self.sprefix)
#             return True
#         # e.g. make help features
#         smeth = lArgs[1]
#         smethod = self.sprefix +'_' + smeth
#         # FixMe: make a wrapper so this isnt needed?
#         if smeth not in self.dhelp and hasattr(self, smethod):
#             omethod = getattr(self, smethod)
#             if hasattr(omethod, '__doc__'):
#                 self.dhelp[smeth] = omethod.__doc__
#         if smeth in self.dhelp:
#             self.poutput(self.dhelp[smeth])
#             self.poutput("For help on options type: help " +self.sprefix)
#             return True
#         raise NotImplementedError("Unknown help command for " +sDo +": " \
#                                       +smeth +' not in ' +repr(self.lCommands))
# 
#     def bexecute(self, loptions, dkw):
#         raise NotImplementedError(self.__class__.__name__)
# 
#     def vInfo(self, sMsg):
#         self.poutput("INFO: " +sMsg)
# 
#     def vWarn(self, sMsg):
#         self.poutput("WARN: " +sMsg)
# 
#     def vError(self, sMsg):
#         self.poutput("ERROR: " +sMsg)


# Path: OpenTrader/backtester.py
import sys
import os
import traceback
                    import glob
            import yaml
            import matplotlib
            import numpy as np
        import warnings
        import matplotlib
        import matplotlib.pylab as pylab
from optparse import make_option
from pprint import pprint, pformat
    from OpenTrader.deps import tabview
from OpenTrader.OTUtils import sStripCreole, lConfigToList
from OpenTrader.doer import Doer
    from OpenTrader.Omlettes import Omlette
            from OpenTrader.PandasMt4 import oReadMt4Csv
            from OpenTrader.PandasMt4 import oReadMt4Csv, oPreprocessOhlc, vResampleFiles
            from OpenTrader.OTPpnAmgc import vGraphData
            from OpenTrader.OTBackTest import oPreprocessOhlc
            from OpenTrader.Omlettes import lKnownRecipes
        from OpenTrader.Omlettes import lKnownChefs
            from OpenTrader.OTBackTest import oPyBacktestCook

def oEnsureChef(ocmd2, oValues, sNewChef=""):
    oOm = oEnsureOmlette(ocmd2, oValues)
    if not sNewChef and hasattr(oOm, 'oChefModule') and oOm.oChefModule:
        return oOm.oChefModule
    if not sNewChef:
        # The are set earlier in the call to do_back
        sNewChef = ocmd2.sChef
    if hasattr(oOm, 'oChefModule') and oOm.oChefModule and oOm.oChefModule.sChef:
        sOldName = oOm.oChefModule.sChef
    else:
        sOldName = ""
    oChefModule = oOm.oAddChef(sNewChef)
    if sOldName and sOldName != sNewChef:
        #? do we invalidate the current servings if the chef changed?
        vClearOven(ocmd2, oValues)
    return oOm.oChefModule

def vClearOven(ocmd2, oValues):
    oOm = oEnsureOmlette(ocmd2, oValues)
    oOm.oBt = None

class DoBacktest(Doer):
    __doc__ = SDOC
    # putting this as a module variable backtest it available
    # before an instance has been instantiated.
    global LCOMMANDS

    dhelp = {'': __doc__}

    def __init__(self, ocmd2):

        Doer.__init__(self, ocmd2, 'backtest')