Beispiel #1
0
    def selected(self):
        Globals.get_instance().setOption(Config.OPTION_SELECTED)
        items = Globals.get_instance().selectedItems()
        if items == None:
            print "No selected file is set"
            return

        liststocks = {}
        for idx in items:
            stockdir = Globals.get_instance().stockpath(idx)
            if stockdir == None:
                liststocks[idx] = None
                continue
            psr = Parser(stockdir)
            liststocks[idx] = psr.getSummer()

        print Parser.getTitle()
        for summer in liststocks:
            if liststocks[summer] == None:
                print "%9s,%8s" % (Globals.get_instance().sin.getname(
                    int(summer)), summer)
                continue
            s = liststocks[summer]
            print Parser.summerFormat() % Parser.formatdata(s)
        pass
Beispiel #2
0
    def input(self):
        try:
            opts, args = getopt.getopt(sys.argv[1:], "hsv:S:pguta", [])
        except:
            self.usage()
            sys.exit(2)

        for o, a in opts:
            if o == "-p":
                Globals.get_instance().setOption(Config.OPTION_SELECTED)

        for o, a in opts:
            if o == "-h":
                self._core.holded()
            elif o == "-s":
                self._core.selected()
            elif o == "-v":
                self._core.verbose(a)
            elif o == "-S":
                try:
                    os.unlink(Config.SELECTED_PATH)
                except:
                    pass
                copyfile(a, Config.SELECTED_PATH)
            elif o == "-u":
                self._core.updateprice()
            elif o == "-t":
                self._core.test()
            elif o == "-g":
                self._core.growinglist()
            elif o == "-a":
                self._core.adjust(args)

            break
        pass
Beispiel #3
0
    def run3(self):

        myurl = 'http://hq.sinajs.cn/list='

        plist = {}
        for f in listdir(Config.STOCKS_PATH):
            fin = Config.STOCKS_PATH + "/" + f + "/finance"
            if not os.path.exists(fin):
                continue
            items = f.split("-")
            idx = int(items[1])
            name = Globals.get_instance().sin.getname(idx)
            if idx >= 600000:
                idy = "sh" + items[1]
            else:
                idy = "sz" + items[1]

            nurl = myurl + idy

            try:
                req = urllib2.Request(url=nurl)
                res = urllib2.urlopen(req)
                res = res.read()
                vals = res.split(",")

                price = float(vals[2])
            except:
                continue

            plist[items[1]] = price
        json.dump(plist, open(Config.OUTPUT_PRICELIST, 'w'))
        pass
Beispiel #4
0
    def outputVerbose(self):
        earnings = self.getpershareearnings()
        price = Globals.get_instance().getstockprice2(self.getid())
        print ""
        print self.getname(), "(", self.getid(), ")"
        print "Price:", price
        print "每股收益: %7.3f" % earnings, "\t折算利率:%6.2f" % (
            earnings / price), "\t区间[%15, %10, %5]:", "[%6.2f %6.2f %6.2f]" % (
                self._pricesRange[0], self._pricesRange[1],
                self._pricesRange[2])
        print "净资产收益率: %6.2f" % self._asset_adding2, "\t平均净资产收益率: %6.2f" % self._average_asset_adding2
        print "稳定增长:", self._continued[
            0], "\t\t365增长加快:", self._increase_fasten[
                0], "\t报告季增长加快:", self._increase_fasten[1]

        print ""
        self.forcast(earnings, price, "报告季增长", self.adding["in report"])
        self.forcast(earnings, price, "365增长", self.adding["adjacent 365"])
        self.forcast(earnings, price, "平均净利润增长", self._continued[1])

        self.forcast(earnings, price, "报告季扣非净利润增长", self.adding["profit2"])
        self.forcast(earnings, price, "平均扣非净利润增长",
                     self.adding["average profit2"])
        self.forcast(earnings, price, "综合分析增长", self.adding["manual"])

        print self._note
Beispiel #5
0
    def doparse(self):
        if self._stockpath[-1] != "/":
            self._stockpath += "/"
        items = os.path.basename(os.path.dirname(self._stockpath)).split("-")
        self._id = int(items[1])
        self._name = Globals.get_instance().sin.getname(self._id)

        self._fh = FinancialHistory(self._stockpath + "/finance")
        self._fh.doparse()

        self._latestfd = self._fh.getlatest()

        #最新季报净利润/每股收益 = 总股数
        self._totalstocks = self._latestfd.profit / self._latestfd.per_share_earnings

        #每股收益 = 最近365天净利润 / 总股数
        self._pershareearnings = self.get365Profit(
            self._latestfd) / self._totalstocks

        #[15% ~ 10% ~ 5%]区间收益
        self._pricesRange = Common().pricesRange(self._pershareearnings)

        #parse adding ...
        #报告季增长
        self.adding["in report"] = self._latestfd.profit_adding / 100
        #最近两个365增长,即最新季度往前推一年,和更早的一年,之间净利润的增长
        prev_fd = self._fh.getreport(self._latestfd.year - 1,
                                     self._latestfd.season)  #上一年同季净利润
        prev_profit365 = self.get365Profit(prev_fd)
        profit365 = self.get365Profit(self._latestfd)
        adding = (profit365 - prev_profit365) / prev_profit365
        self.adding["adjacent 365"] = adding
        #持续增长分析
        self._continued = self.continueParsing()
        self.adding["average"] = self._continued[1]
        #增长加快评级
        self._increase_fasten = self.increaseAdding()
        #净资产收益率
        self._asset_adding2 = self._pershareearnings / self._latestfd.per_share_asset
        #净资产收益率近年平均值
        self._average_asset_adding2 = self.getAverageAssetAdding2()
        #扣非净利率增长
        self.adding["profit2"] = self._latestfd.profit2_adding / 100
        if self.adding["profit2"] < -0.9999:  #skip such stupid data
            self.adding["profit2"] = -0.9999
        #扣非净利率平均增长
        self.adding["average profit2"] = self.average_profit2_adding()

        note = Note(os.path.dirname(self._stockpath) + "/note.xml")
        try:
            note.doparse()
            self._note = note._note
            self.adding["manual"] = note._adding
            self._summary = note._summary
        except:
            self._note = None
            self.adding["manual"] = None
            self._summary = ""
Beispiel #6
0
    def holded(self):
        Globals.get_instance().setOption(Config.OPTION_HOLDED)
        holded = Globals.get_instance().holded.holded

        liststocks = {}
        for idx in holded:
            stockdir = Globals.get_instance().stockpath(holded[idx][0])
            if stockdir == None:
                liststocks[idx] = None
                continue
            psr = Parser(stockdir)
            #            psr.outputSimple()
            liststocks[idx] = psr.getSummer()

        print Parser.getTitle()
        for summer in liststocks:
            if liststocks[summer] == None:
                print "%9s,%8s" % (Globals.get_instance().sin.getname(
                    int(summer)), summer)
                continue
            if Globals.get_instance().getstocktotal(int(summer)) < 10.0:
                continue
            s = liststocks[summer]
            print Parser.summerFormat() % Parser.formatdata(s)
        pass
Beispiel #7
0
    def getSummer(self):
        n = self.getname()
        i = self.getid()
        e = self.getpershareearnings()
        p = Globals.get_instance().getstockprice(self.getid())
        t = Globals.get_instance().getstocktotal(self.getid())
        a = self._asset_adding2

        adding = self.getadding()

        earnings2 = e * ((1 + adding)**2)
        y2 = earnings2 * 100 / 10  #对应10%收益的价格
        if y2 < 0:
            p2adding = -0.99
        else:
            p2adding = ((y2 / p)**(1.0 / 2)) - 1

        earnings5 = e * ((1 + adding)**5)
        y5 = earnings5 * 100 / 10
        if y5 < 0:
            p5adding = -0.99
        else:
            p5adding = ((y5 / p)**(1.0 / 5)) - 1

        return {
            "stockname": n,
            "id": i,
            "earning": e,
            "price": p,
            "total": t,
            "asset%": a,
            "flag": self.getFlag(),
            "adding": adding,
            "2Yprice": y2,
            "p2adding": p2adding,
            "p5adding": p5adding,
            "summary": self._summary
        }
Beispiel #8
0
    def run(self):
        self.stocklists = {}

        for f in listdir(Config.STOCKS_PATH):
            fin = Config.STOCKS_PATH + "/" + f + "/finance"
            if not os.path.exists(fin):
                continue
            items = f.split("-")
            idx = items[1]

            psr = Parser(Config.STOCKS_PATH + "/" + f)
            if psr._pershareearnings < 0.001:
                continue

            q = Globals.get_instance().getstockprice3(idx)
            eq = psr._pershareearnings / q

            stock = {}
            stock["name"] = psr._name
            stock["earnings"] = psr._pershareearnings
            stock["q"] = q
            stock["eq"] = eq

            suitcount = 0
            totaldelta = 0
            for val in psr.adding:
                if not val in Config.ADDINGS:
                    continue
                info = {}

                a = psr.adding[val]
                ref = (((1.0 + self.p) /
                        (1 + a))**self.n) * self.p  # reference eq
                delta = ((psr._pershareearnings / ref) - q) / q

                info["a"] = a
                info["ref"] = ref
                info["delta"] = delta
                stock[val] = info
                if delta > 0.001:
                    suitcount += 1
                totaldelta += delta

            stock["count"] = suitcount
            stock["avdelta"] = totaldelta / len(Config.ADDINGS)
            self.stocklists[idx] = stock

        pass
Beispiel #9
0
    def run(self):
        ax = []
        ay = []

        for f in listdir(Config.STOCKS_PATH):
            fin = Config.STOCKS_PATH + "/" + f + "/finance"
            if not os.path.exists(fin):
                continue
            items = f.split("-")

            psr = Parser(Config.STOCKS_PATH + "/" + f)

            cox = psr._pershareearnings / Globals.get_instance(
            ).getstockprice3(items[1])
            #            adding = psr._continued[1]
            #            adding = psr.adding["adjacent 365"]
            #            adding = psr.adding["profit2"]
            adding = psr.adding["average profit2"]
            #            adding = psr.adding["in report"]

            print ""
            print items[1], Globals.get_instance().getstockprice3(
                items[1]), psr._pershareearnings, adding

            if adding > 1.2:
                adding = 1.0
            if cox > 0.20:
                cox = 0.2

            if adding < 0.0000001:
                continue
            if cox < 0.00001:
                continue

            ax.append(adding)
            ay.append(cox)

        print ax
        print ay

        nx = np.array(ax)
        ny = np.array(ay)
        plt.scatter(nx, ny, color='blue')

        n = 5
        p = 0.10
        ax = []
        ay = []
        for i in range(0, 20):
            x = i / 20.0
            y = (((1.0 + p) / (1 + x))**n) * p
            if y > 0.2:
                print "out of range:", x, y
                y = 0.2
            ax.append(x)
            ay.append(y)

        nx = np.array(ax)
        ny = np.array(ay)
        plt.scatter(nx, ny, color='red')
        plt.plot(nx, ny, color='red', linewidth=4)
        #        plt.plot(nx, regr.predict(nx.reshape(-1,1)), color='red', linewidth=4)

        plt.show()
        pass