Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Current price vs. last price

Alert: Im a beginner so bear with me.
I want to be able to manipulate the current price and the last price 1 minute beforehand. So, how do I define the current price a security is trading at and how do I define the last price a minute ago that the security was valued at? I know there is close_price, open_price, and last_sale_price, but the API does not fully explain what those mean.

I also tried using:
history(2, "1m", "price")
which returns the previous minute's close price and the current price, but is there a way I can separate the two prices and then manipulate them in my algorithm?

Thank you,
Alex

4 responses

Great start! When you use history(2, "1m", "price") it needs to be called something so you can reference it later.

price_hist = history(2, "1m", "price")  

That will put all that data into the object price_hist.
To reference the most recent data point, use
most_recent_point = price_hist[-1] #The current price, equal to data[stock].price The second most recent data point would be
last_minutes_price = price_hist[-2] #The second most recent point

Also, a great place for learning python, http://pythonprogramming.net/dashboard/

Calvin

How did you get it to work?
I only get " SyntaxError: unexpected indent" when trying to build my algorithm with " price_hist = history(2, "1d", "price") " inserted.

The unexpected indent error is because you have a "space" before price_hist variable.

 price_hist = history(2, "1d", "price")  

Indentation is extremely important while programming in python. You have to make sure not to have any spaces before a line of code unless its part of a conditional or loop block.