How to use the "Self" parameter
CloudQuant is ultimately based on Python, so CloudQuant scripts must follow Python's flavor of object-oriented programming. You use objects in every part of your script: the parameters to many methods like on_minute_bar are themselves objects. Because objects encapsulate data within themselves, this allows us to pass in lots of data with just a few objects. The data within a Python object is accessed like this: object_name.attribute_name, so you can, for example, access the symbol attribute of the event object by writing event.symbol. However, the scripts you write are objects too! But how do we access the data contained within them?
This is where the self parameter comes in. You will notice that the parameter lists for almost all the instance methods you implement for CloudQuant scripts like on_start and on_minute_bar have self as the first parameter. This is a requirement in Python - object instance methods must receive the self parameter before anything else. What this allows us to do is access the data contained within our own object. With other objects, like the event and account that we often see as parameters, we access their attributes by the object's name. But how do we know the name of our own object, as we do not instantiate it ourselves? The answer is that we do not, but the self parameter fills the same role. To access the data within our own object, we simply call self.attribute_name. This emphasizes the fact that our object is really no different from any other. To initialize a new attribute on our object we set it equal to a new value (self.new_attribute = some_value).