Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Beginner Trouble--Can't get current price of equity in array

For some reason I am having trouble gathering and displaying the current price of each equity in my array. Any help would be greatly appreciated. Thank you

import numpy

def initialize(context):

context.limit = 10  
current_price = []  

def before_trading_start(context,data):

context.fundamentals = get_fundamentals(  
    query(  
       fundamentals.valuation_ratios.peg_ratio,  
       fundamentals.operation_ratios.roe,  
       fundamentals.operation_ratios.net_income_growth  
    )  
    .filter(fundamentals.valuation_ratios.peg_ratio < 1)  
    .filter(fundamentals.operation_ratios.roe > 0.04)  
    .filter(fundamentals.operation_ratios.net_income_growth > 0)  
    .order_by(  
       fundamentals.valuation.market_cap.desc(),  
       fundamentals.operation_ratios.roe.desc(),  
       fundamentals.operation_ratios.net_income_growth.desc(),  
    )  
    .limit(context.limit)  
)  

context.hello = context.fundamentals  
update_universe(context.hello.columns.values)  
print "___________________________________\n"  

cash =  context.portfolio.cash  
cpp = context.portfolio.positions_value  

print "Cash = %s" % cash  
print  "Position Value = %s" % cpp  

def handle_data(context, data):

for stock in range(context.limit):  
   print context.hello.columns[stock]  
   current_price[stock] = data[context.hello.columns[stock]].close_price  
   print current_price  
   order(context.hello.columns[stock], 5)  
1 response

Hi Matt,
I think your filters are removing all results, so there is nothing to get the price for.

Attached is a backtest I ran, getting the same data, but using the new pipeline API. In the code, you will notice that I have commented out the set_screen line. When I include this, there are no results. When I don't, you'll notice a dataframe context.output that is logged in before_trading_start has all the fields you are interested in (fundamentals & close price).

Hope this helps.

KR

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.