Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Cannot convert data type to float?

Hello, I am totally new to quantopian and trading.
The following code creates the error: "ValueError: could not convert string to float: Equity(27543 [EXPE])
..." within the function handle_data().

I'm not so sure how I can change the data type stored in the temp array (defined within handle_data) to float data type so that I can do arithmetic
calculations with it. Please help! Thanks

def initialize(context):  
    context.minuteCounter = 0 # keeps track of number of minutes  
    # 100 different nasdaq stocks  
    context.securities = [sid(24),    sid(114),   sid(122),   sid(630)  , sid(67),  
sid(20680), sid(328),   sid(14328), sid(368),   sid(16841),  
sid(9883),  sid(337),   sid(38650), sid(739),   sid(27533),  
sid(3806),  sid(18529), sid(1209),  sid(40207), sid(1419),  
sid(15101), sid(17632), sid(39095), sid(1637),  sid(1900),  
sid(32301), sid(18870), sid(14014), sid(25317), sid(36930),  
sid(12652), sid(26111), sid(24819), sid(24482), sid(2618),  
sid(2663),  sid(27543), sid(27543), sid(2696),  sid(42950),  
sid(20208), sid(2853),  sid(8816),  sid(5530),  sid(3212),  
sid(9736),  sid(23906), sid(26578), sid(22316), sid(13862),  
sid(3951),  sid(8655),  sid(25339), sid(4246),  sid(43405),  
sid(27357), sid(32046), sid(4485),  sid(43919), sid(4668),  
sid(8677),  sid(22802), sid(3450),  sid(5061),  sid(5121),  
sid(5149),  sid(5166),  sid(23709), sid(13905), sid(19926),  
sid(19725), sid(8857),  sid(5767),  sid(5787),  sid(19917),  
sid(6295),  sid(6413),  sid(6546),  sid(20281), sid(6683),  
sid(26169), sid(6872),  sid(11901), sid(13940), sid(7061),  
sid(15581), sid(24518), sid(7272),  sid(39840), sid(7671),  
sid(27872), sid(8017),  sid(38817), sid(8045),  sid(8132),  
sid(8158),  sid(24124), sid(8344),  sid(8352),  sid(14848)]

def handle_data(context,data):  
    context.minuteCounter += 1  
    if context.minuteCounter >= 30:  
        context.minuteCounter = 0  
        price_history = data.history(context.securities,fields="price",bar_count=250,frequency="1m")  
        data_arr = []  
        for s in context.securities:  
            data_arr.append(price_history[s]) # data_arr: 100 x 250 array  
        # below is the part with problems  
        for i in range(0,len(data_arr)):  
            temp = []  
            for j in data_arr[i]:  
                temp.append(j)  
            for j in range(0,len(temp)):  
                print float(str(temp[j]))+1  

2 responses

Oh actually I could just use the code

data_arr = price_history.as_matrix()  

and then manipulate it as an array <_<

I'm curious where you're driving with this. Fixed universe, lots of price appending - there are a lot of Quantopian helper functions so you don't have to do mechanical things like that. You may be able to write it all with a few lines of code, instead, depending on what you're trying to do.

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.