Ejemplo n.º 1
0
    def setup(self, start, end):
        try:
            startdate = datetime.date(start[0], start[1], start[2])
        except:
            return

        tmptime = time.mktime(startdate.timetuple())
        endstr = "%04d-%02d-%02d" % (end[0], end[1], end[2])
        init = prev = self._db["%04d-%02d-%02d" % start]
        while True:
            tmptime += (3600 * 24)
            dt = datetime.date.fromtimestamp(tmptime)
            if str(dt) > endstr:
                break
            share = {}
            for idx in init:
                S = Stock(Globals.get_instance(), idx)
                ps = S.historypricesshare((dt.year, dt.month, dt.day))
                if ps == None:
                    share[idx] = (prev[idx][0], prev[idx][1])
                else:
                    if ps[1] == 1:
                        share[idx] = (prev[idx][0], ps[0])
                    elif ps[1] == 0:
                        share[idx] = (prev[idx][0], ps[0])
                    else:
                        share[idx] = (prev[idx][0] * ps[1], ps[0])
                prev = share
            self._db[str(dt)] = share
        pass
Ejemplo n.º 2
0
    def __init__(self, ss, start, end):
        share = {}
        for idx in ss:
            S = Stock(Globals.get_instance(), idx)
            ps = S.historypricesshare(start)
            #use 20000 to buy it in 100 shares
            if ps == None:
                share[idx] = (0, 0)
            else:
                share[idx] = (int(20000 / ps[0]), ps[0])
        self._db = {}
        self._db["%04d-%02d-%02d" % start] = share

        self.setup(start, end)
        pass
Ejemplo n.º 3
0
class SZStat(BaseStat):
    def __init__(self, start, end):
        BaseStat.__init__(self, start, end)

        idx = "1399001"
        self._S = Stock(Globals.get_instance(), idx)
        pass

    def price(self, date):
        return self._S.price(date)
Ejemplo n.º 4
0
    def __init__(self):
        if self.INSTANCE is not None:
            raise ValueError("An instantiation already exists!")
        self._stockidnamemapping = StockIdNameMapping()
        sim = self._stockidnamemapping.getmap()

        self._stocks = {}
        for sid in sim:
            self._stocks[sid] = Stock(self, sid)

        self._prices = Prices()
        self._ff10jqka = None
Ejemplo n.º 5
0
    def __init__(self, start, end):
        BaseStat.__init__(self, start, end)

        idx = "1399001"
        self._S = Stock(Globals.get_instance(), idx)
        pass