Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Go long

Say I wanted to get Price/Book value for goog and check if it greater than 2 and less than or equal to 12 then go long else go short, how do i do it ?

6 responses

You can try to get book value from yahoo: http://finance.yahoo.com/d/quotes.csv?s=GOOG&f=b4 using fetch_csv: https://www.quantopian.com/help#api-fetchcsv.
Price is provided by Quantopian with every event: https://www.quantopian.com/help#api-event-properties
Ordering is done by using order* functions: https://www.quantopian.com/help#ide-ordering

Can you please demonstrate this with a little code ?

Sure. Something like this:

def initialize(context):  
    context.stock = symbol('GOOG')  
    context.bookv = 145.685

def handle_data(context, data):  
    if 2 < data[context.stock].price/context.bookv <= 12:  
        order_target_percent(context.stock, 1)  
    else:  
        order_target_percent(context.stock, -1)  

I assigned book value to a constant as yahoo doesn't provide historical values of it.

Thanks you very much, i understand now. So context is an object that you can just attach any variable to it ? like say
context.anything = something

Yes, you can attach any variable you want on context.

Yes, the context is a storage for algo states and anything else used in the algo. However, it's handy but not mandatory to use it.

Regarding your strategy: You need to find historical data for book value somewhere. Using constant is obviously not what you'd like to use in real algo. You can try to get it from quandl. Here https://www.quandl.com/help/api-for-stock-data#Damodaran-Single-Ratios it looks like they're providing 'Book Value of Assets' and 'Book Value of Equity' data.

I hope it helps.