Rounding error / no error

carcarcarcar Posts: 5

Hi I am new to coding so sorry if this is a dumb question. I am following along with the Cloudquant video on minute bars and when I tried to round the numbers like he does in the video I got an error so now I am trying to figure out how to round "bardata" I keep getting "progress failed" messages but no helpful error messages in the console.

from cloudquant.interfaces import Strategy

class CQ1444c91584764bbbb09649eb8c50c39e(Strategy):

@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
    return symbol=="FB"

def on_minute_bar(self, event, md, order, service, account, bar):
    bardata = md.bar.minute(include_extended=True)
    bardata = bardata.astype(float)
    print(service.time_to_string(event.timestamp),round(bardata.close, 2),round(md.stat.prev_close, 2))
    pass

Comments

  • carcarcarcar Posts: 5

    And when I take out the round() entirely it works. So I want to figure out how to round it like the guy does in the video on min bars from cloudquant.

  • ptunneyptunney Posts: 246

    That sounds like an old video, it would be helpful if you included a link to the video or the page with the video on it.

    In this case the bardata is a list of lists... bardata.close is a single list of close prices which can be one item long or many items long. Because you have not specified a 'start' it is defaulting to 1 to get the most recent value. But that is still a LIST.

    You cannot round a list. This is not supported in current versions of python, it is possible it was supported when the video was made.

    Instead, if it is a long list, you would need to either loop through the list rounding each item at a time or you could do it in a single line and put the values into a new list, then print that list.

    In this case you simply have to select the only value in the list, you can use [0] or [-1] for this (again because the list is only one item long it does not matter but if it was longer -1 would get the most recent value. If you do not understand this watch this video...

    from cloudquant.interfaces import Strategy
    class rounding(Strategy):
        @classmethod
        def is_symbol_qualified(cls, symbol, md, service, account):
            return symbol=="FB"
        def on_minute_bar(self, event, md, order, service, account, bar):
            bardata = md.bar.minute(include_extended=True)
            print(service.time_to_string(event.timestamp),round(bardata.close[-1],2),round(md.stat.prev_close, 2))
            #bardata = md.bar.minute(start=-5, include_extended=True)
            #close_pennies = [round(num, 2) for num in bardata.close]
            #print(service.time_to_string(event.timestamp),close_pennies,round(md.stat.prev_close, 2))
    

    If you comment out the first two lines in on_minute and uncomment the last three, you will fetch more bars and see an extra line that loops through the close prices making a new list of just close prices rounded to 2 decimal places.

    You should watch the entire introductory video series...

    You should also have a strong grasp of Python, particularly lists, if you are going to make progress developing a trading model.

Sign In or Register to comment.