Back to Community
Adding my own parameters to CustomFactor

I'd like to be able to add my own parameters to my own CustomFactor, is there a way to do that besides overloading the __init__ method? and if no, what's the signature of the __init__ method?

I'd like to do something like this:

class MyFactor(CustomFactor):

    def __init__(self, argument1, argument2, context):  
        super(CustomFactor,self).__init__(argument1, argument2)  
        self.my_reference_to_context = context

   def  compute(self, today, assets, out, values):  
        for i in range(out.shape[0]):  
            out[i] = someFunction(values[:, i], some_parameter=self.my_reference_to_context.some_constant)  

Where argument1 and argument2 are the default arguments the __init__ method expects

2 responses

Not sure if this is what you are needing, but yes, you can pass parameters to a CustomFactor (and CustomFilter) class when you instantiate it. Just name the parameters. See the example in the attached notebook. No need to overload the init method.

Hope that helps.

Loading notebook preview...

It is also possible to set the parameters as a dict with default values as shown in the attached notebook.

Loading notebook preview...