If you are coming from Java land, you might have a better time if you think of your algorithm as an applet. The reason that there is no 'main' function like your 'public static void main(String argv[])' is that you are not exposed to the program's entry point. Your algorithm is not a standalone entity; instead, it is being entered from a larger runtime.
In java applets you have your 'public void init()' method that is almost exactly like the Quantopian 'initialize' function. The only difference is that with applets, you are expected to store any innitial state on the applet object like, 'this.memberVar = 10' where in the Quantopian version, you are expected to store the state on 'context' like 'context.member_var = 10'.
As Alisa explained, after you have setup your state with 'initialize', 'handle_data' is called once per bar of data.
'context' is a modified dictionary object that allows you to use attribute access to index into it. For example:
context.attribute
context['attribute']
are the same and can be exchanged anywhere in the algorithm.
About the parameters issue you described, python attribute lookups happen at runtime. For this reason, you may think of everything almost like a Java interface. For example, take the function:
def describe_length(a):
length = len(a)
if not length:
return 'Empty'
if length < 5:
return 'Short'
return 'Long'
Does it really matter what type 'a' is? As long as it implements a '__len__' method., we know that we can call 'len' on it and it works. To transition from Java to Python, you need to not think about the 'type' of things so rigidly, and start thinking about the behavior of things.