For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Accessing Strategy Parameters



  • Hi,

    I would like to access the strategy parameters for a project I am working on.

    However when trying to do so, I get the following:

    ort.Test.params
    Out[25]: backtrader.metabase.AutoInfoClass_LineRoot_LineMultiple_LineSeries_LineIterator_DataAccessor_StrategyBase_Strategy_Test1
    

    So as a workaround, I put my parameters in a dictionary "parameters" and then passed these parameters as a tuple to params, see below:

       parameters = {'param1': 1}
       params = tuple(parameters.items())
    

    This seems to be working but I am curious to know if there is a better/more elegant way of doing this?

    Thanks!


  • administrators

    @laurent-michelizza said in Accessing Strategy Parameters:

     parameters = {'param1': 1}
     params = tuple(parameters.items())
    

    This seems to go in the opposite direction of accessing the params

    The params class/instance has the following methods (see metabase.py)

        def isdefault(self, pname):
    
        def notdefault(self, pname):
    
        def _get(self, name, default=None):
    
        @classmethod
        def _getkwargsdefault(cls):
    
        @classmethod
        def _getkeys(cls):
    
        @classmethod
        def _getdefaults(cls):
    
        @classmethod
        def _getitems(cls):
    
        @classmethod
        def _gettuple(cls):
    
        def _getkwargs(self, skip_=False):
    
        def _getvalues(self):
    

  • administrators

    @laurent-michelizza said in Accessing Strategy Parameters:

       parameters = {'param1': 1}
       params = tuple(parameters.items())
    

    Furthermore, you may find several samples that show that parameters can also be defined as a dictionary. There is no need for that conversion. A tuple ensures ordering (which can also be achieved with a collections.OrderedDict for example) should it it be needed.



  • That works thanks!


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.