Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Plot a function with the stock price?

When I try to plot the function with the stock price i put:

record(name_of_function, stock, price)

Then I get the error message: There are a mismatched number of names and values in the record function. I don't understand what is mismatched. I'm using the correct name assigned to the function. How do I plot the function with the stock price?

9 responses

Jeff,

Try:

record(func_value = func_value, price = price)

Grant

Hey Grant,

When I try that this is what it says:

SyntaxError: pass the non-keyword argument before the keyword argument.

Hi Jeff,

It's always helpful if you include relevant code snippets. Does your code read:

record(func_value = func_value, price = price)  

If func_value & price are floats, assigned prior to the call to record, then it should work.

Grant

How do I know whether they are floats prior to the call? The exact code I have is: record(gf = g + f, stock, data[stock].close_price)

You might try:

print g  
print f  
print data[stock].close_price

% record(gf = g + f, close_price = data[stock].close_price)

If you get floats to the log output, then uncomment 'record' and it should work. Note however, that it is only set up for a single stock. Presumably, you have the call to record in a loop and you are trying to record values for multiple stocks?

Have a look at the help page and the example code there for the record function to get a better feel for how it works. Basically, you can plot up to five values, so if gf is common to all of your stocks, you could do something like:

record(gf = g + f, close_1 = data[sid_1].close_price,close_2 = data[sid_2].close_price,close_3 = data[sid_3].close_price,close_4 = data[sid_4].close_price)  

Grant

You might try:

print g  
print f  
print data[stock].close_price

% record(gf = g + f, close_price = data[stock].close_price)

If you get floats to the log output, then uncomment 'record' and it should work. Note however, that it is only set up for a single stock. Presumably, you have the call to record in a loop and you are trying to record values for multiple stocks?

Have a look at the help page and the example code there for the record function to get a better feel for how it works. Basically, you can plot up to five values, so if gf is common to all of your stocks, you could do something like:

record(gf = g + f, close_1 = data[sid_1].close_price,close_2 = data[sid_2].close_price,close_3 = data[sid_3].close_price,close_4 = data[sid_4].close_price)  

Grant

That did the trick! Grant I appreciate it. When the "%" before record is included, it says invalid syntax, then if excluded it runs the test. Any idea why that might be? I took a look at the help page, couldn't find any examples that include the "print variable" step of the process for the record function or any mention of floats unless I missed it. Is that an implied step in programming? What are floats?

Sorry...% is the comment character in MATLAB (use # for Python). A float is a floating point number. The record function will also take integers as well, but not stuff like lists, dictionaries, arrays, etc. Just a scalar (i.e. a single number, like -1.7 or 3 or 9.8e3, etc.). --Grant

Oh okay, I have some new words learn. I am still trying to define the relationship between when or why to use floating point numbers. It's a little abstract. Thanks again for your help.