Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
defininition and uses cases for last_sale_price?

Hi,

I'm confused by the definition of last_sale_price. With the backtester, it appears to be equivalent to the close price (except for the first bar, when it is zero). Under live trading, would it be the same?

Also, what are the use cases for last_sale_price (or is it equivalent to the close price)?

Grant

last_sale_price

Float: Price at last sale of this security.

def initialize(context):  
    context.submitted = False

def handle_data(context, data):  
    print get_datetime()  
    if context.submitted == False:  
        order(sid(24), 50)  
        print 'order submitted'  
        context.submitted = True  
    print 'close price:'  
    print data[sid(24)].close_price  
    print 'last sale price:'  
    print context.portfolio.positions[sid(24)].last_sale_price  

2014-03-05PRINT2014-03-05 14:31:00+00:00
2014-03-05PRINTorder submitted
2014-03-05PRINTclose price:
2014-03-05PRINT531.9
2014-03-05PRINTlast sale price:
2014-03-05PRINT0.0
2014-03-05PRINT2014-03-05 14:32:00+00:00
2014-03-05PRINTclose price:
2014-03-05PRINT531.265
2014-03-05PRINTlast sale price:
2014-03-05PRINT531.265

6 responses

Grant,

I've been confused by this as well, but I believe they are one and the same per the API User Manual:

price is the price of this security at the end of this event. Most code within Quantopian operates on this property; it is the property used by default to describe the price of a security.

close_price is the price of the security at end of this event. identical to price.

Why the need for two definitions?

Thanks Colin,

No time for me now, but digging into zipline would probably reveal the answer (at least for backtesting).

Grant

last_sale_price and price indeed return the same value. They are identical in our system.

We don't have a good reason why there are two identical variables in the system :) But from what I gather, it was based on user preference.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks Alisa,

Why does last_sale_price return zero for the first call in the algorithm above? The log output:

2014-03-05PRINT2014-03-05 14:31:00+00:00
2014-03-05PRINTorder submitted
2014-03-05PRINTclose price:
2014-03-05PRINT531.9
2014-03-05PRINTlast sale price:
2014-03-05PRINT0.0
2014-03-05PRINT2014-03-05 14:32:00+00:00
2014-03-05PRINTclose price:
2014-03-05PRINT531.265
2014-03-05PRINTlast sale price:
2014-03-05PRINT531.265

--Grant

There is no last_sale_price because the order gets placed in the first bar and filled in the next bar. On the first bar there is no last_sale_price, but the close_price is the price of the stock at market close. After the first bar, these values are identical.

Thanks Alisa,

Rather than returning zero, shouldn't last_sale_price return None when the referenced security is not an open position?

Grant