Exemple #1
0
    def run(self):
        prices = Globals.get_instance().getprices()
        mapping = Globals.get_instance().getstockidnamemapping()
        #construct e/q, adding for stocks
        valids = []
        for s in self._stocks:
            fin = Financial(s)
            if not fin.valid():
                continue
            e = fin.pershareearning()
            valids.append(
                (s, mapping.getname(s), prices.price(s), e, fin.addings()))

        print "valids count: ", len(valids)
        ax = []
        ay = []
        ay2 = []

        for v in valids:
            adding = v[4]["history"]
            ax.append(adding)
            ay.append(v[3] / v[2])
            eq = (((self._p + 1) / (adding + 1))**self._n) * self._p
            ay2.append(eq)
            q = v[2] / eq
            print v[1], v[3], v[2], ">", q, " [", adding, (
                q - v[2]) / v[2], eq, "]"

        print ax
        print ay

        plt.scatter(ax, ay, color='blue')
        plt.scatter(ax, ay2, color='red')
        plt.show()
        pass
Exemple #2
0
    def __init__(self, sid, af):
        self._sid = sid
        self._name = Globals.get_instance().getstockidnamemapping().getname(sid)
        if self._name == "--":
            af.indicatefail("Incorrect stock id")

        types = Globals.get_instance().gettypes()
        industry = types.industry(sid)
        self._industry = industry
        self._af = af
Exemple #3
0
 def run(self):
     imap = Globals.get_instance().getstockidnamemapping().getmap()
     os.chdir("./output")
     for k in imap.keys():
         ret = self.download(k)
         if ret != 0:
             break
     os.chdir("../")
     pass
Exemple #4
0
 def stat_init(self):
     iss = Globals.get_instance().getinputstocks()
     self._all = {}
     self._stat = {}
     self._total = len(iss.allstocks())
     for s in iss.allstocks():
         af = self.AF(s)
         stock = Stock(s, af)
         self._all[s] = stock
Exemple #5
0
    def build(self, idx):
        gbls = Globals.get_instance()
        name = gbls.getstockidnamemapping().getname(idx)
        if name == "--":
            print "Unknown stock id, please specific a correct one"
            return
        #check if is it available
        tps = gbls.gettypes()
        stocks = tps.typeproperty("available")["stocks"]
        if idx in stocks:
            s = name + "(" + idx + ")" + "is exist, would you like update it? (N/Y) Default N:"
            var = raw_input(s)
            if var != 'y' and var != "Y":
                #create note it is not exist
                pinyin = gbls.getinputstocks().getpinyin(idx)
                note = Config.STOCKS_PATH + "/" + pinyin + "-" + idx + "/note.xml"
                self.createnote(note)
                return

        #build directory string
        ins = gbls.getinputstocks()
        try:
            pinyin = ins.getpinyin(idx)
        except:
            while True:
                pinyin = raw_input("Please input pinyin of %s:" % name)
                if len(pinyin) < 3:
                    print "please input a correct pinyin, at least 3 letters"
                else:
                    break

        sdir = Config.STOCKS_PATH + "/" + pinyin + "-" + idx
        command = 'mkdir -p ' + sdir
        call_params = shlex.split(command)
        subprocess.call(call_params)
        # print the finance url and copy it to system paste board
        url = "http://stockpage.10jqka.com.cn/" + idx + "/finance/#finance"
        print url
        pyperclip.copy(url)
        # vim run
        command = 'vim ' + sdir + "/finance"
        call_params = shlex.split(command)
        subprocess.call(call_params)

        # if note.xml is not exist, just create it
        note = sdir + "/note.xml"
        self.createnote(note)

        # make a simple file parsing to verify
        ff = FinancialFile(sdir + "/finance")
        ff.doparse()
        r = ff.yearreport(2017)
        print r

        pass
Exemple #6
0
    def run(self, arg):
        iss = Globals.get_instance().getinputstocks()
        self._all = iss.allstocks()
        self._total = len(self._all)

        if arg == "season3":
            self.season3_year()
            self.season3_result()
        elif arg == "average5":
            self.average5()
        pass
Exemple #7
0
    def select(self, ids):
        no = 1
        for i in ids:
            print no, i, Globals.get_instance().getstockidnamemapping(
            ).getname(i)
            no += 1

        while True:
            choice = raw_input("Please select:")
            try:
                k = int(choice)
                if k < no and k > 0:
                    return ids[k - 1]
            except:
                pass
    def run(self, typ):
        types = Globals.get_instance().gettypes()
        slist = types.liststocks(typ)
        self._slist = []
        for sid in slist:
            af = self.AF(sid)
            stock = Stock(sid, af)
            vlds = stock.ffvalid()
            if not vlds[0]:
                continue
            self._slist.append(stock)

        print "stocks: ", len(self._slist)
        self.draw()
        plt.show()
Exemple #9
0
 def holded(self, LL):
     lhd = Globals.get_instance().getlatestholdedrecord()
     stocks = lhd.stocks()
     for ss in stocks:
         af = DratioAdding(ss)
         stock = Stock(ss, af)
         print stock.name()
         d0 = self.item(ss, LL[0])
         d1 = self.item(ss, LL[1])
         d2 = self.item(ss, LL[2])
         d3 = self.item(ss, LL[3])
         print d0
         print d1
         print d2
         print d3
     pass
Exemple #10
0
    def run(self):
        iss = Globals.get_instance().getinputstocks()
        self._all = {}
        self._total = len(iss.allstocks())

        stat = {}
        for s in iss.allstocks():
            af = self.AF(s)
            stock = Stock(s, af)
            vlds = stock.ffvalid()
            if not vlds[0]:
                try:
                    stat[vlds[1]] += 1
                except:
                    stat[vlds[1]] = 1
                continue
            self._all[s] = stock
        self.AF.stat(stat)

        L1 = []
        L2 = []
        L3 = []

        for s in self._all:
            ss = self._all[s]

            self.addin(L1, ss, "profit_adding")
            self.addin(L2, ss, "profit2_adding")
            self.addin(L3, ss, "sales_adding")

        end = len(L1) / 2
        M1 = L1[0:end]
        M2 = L2[0:end]
        M3 = L3[0:end]

        NN = []
        for v in M1:
            if (v in M2) and (v in M3):
                self.addin2(NN, v)

        for v in NN:
            print v.name(), v.addings(), v.a(), v.dratio()

        pass
Exemple #11
0
    def run(self):
        n = len(sys.argv)
        if n < 2:
            print "Please provide stocks type"
            return

        gbls = Globals.get_instance()
        tps = gbls.gettypes()

        try:
            prop = tps.typeproperty(sys.argv[1])
        except:
            print "Unknown type:", sys.argv[1]
            return

        stocks = prop["stocks"]

        for s in stocks:
            ns = NewStock()
            ns.build(s)
        pass
Exemple #12
0
    def run(self, args, opts):
        if len(args) < 1:
            print "Please specific the stock in id or pinyin"
            return

        try:
            int(args[0])
            idx = args[0]
        except:
            #it is pinyin
            ids = Globals.get_instance().getinputstocks().getids(args[0])
            if len(ids) == 1:
                idx = ids[0]
            elif len(ids) > 1:
                idx = self.select(ids)
            else:
                print "Please specific a correct stock"
                return

        stock = Stock(idx, DefaultAdding(idx))

        print stock.id()
        print stock.name()
        print stock.types()
        print "industry:", stock.industry()
        print stock.n(), stock.p()

        if not stock.ffvalid()[0]:
            print "No valid financial data"
            return

        print "addings: ", stock.addings()

        print "select adding:", stock.a()
        print "pershareearning:", stock.e()
        print "price:", stock.price()
        print "e/q:", stock.eq()
        print "q(reasonable price):", stock.q()
        print "dratio(price adding predict):", stock.dratio()
Exemple #13
0
        mylist.sort()
        return mylist

    def prices(self,
               filepath):  #return the dictionary generate from the filepath
        p = json.load(open(filepath))
        try:
            p = json.load(open(filepath))
        except:
            p = None
        return p

    def latestprices(self):  #return the dictionary of latest prices
        return self.prices(Config.PRICES_PATH + "/" + self.pathlist()[-1])

    def price(self, sid):
        return self._latestprices[sid]


if __name__ == "__main__":
    if sys.getdefaultencoding() != 'utf-8':
        reload(sys)
        sys.setdefaultencoding('utf-8')

    from moneysea.globals import Globals

    p = Prices(Globals.get_instance())
    #    p.update()
    #    print p.pathlist()
    print len(p.latestprices().keys())
Exemple #14
0
 def run(self, args, opts):
     prices = Globals.get_instance().getprices()
     prices.update()
Exemple #15
0
 def price(self):
     prices = Globals.get_instance().getprices()
     return prices.price(self._sid)
Exemple #16
0
 def types(self):
     types = Globals.get_instance().gettypes()
     return types.stocktypes(self._sid)
Exemple #17
0
    def run(self, args, opts):
        types = Globals.get_instance().gettypes()

        if len(args) == 0 or args[0] == "list":
            print "%24s%16s%16s%16s%16s"%("name","typetype","np","count", "cname")
            print ""
            for typ in types.listtypes():
                prop = types.typeproperty(typ)
                try:
                    np = prop["np"]
                except:
                    np = "--"
                try:
                    count = len(prop["stocks"])
                except:
                    count = 0
                print "%24s%16s%16s%16s%16s"%(typ, prop["filetype"], np, count, prop["cname"])
        elif args[0] == "dump":
            if len(args) < 2:
                print "please specify the stock type for dumping"
                print self.description()
                return 
            try:
                prop = types.typeproperty(args[1])
            except:
                print "Unknown type:", args[1]
                return

            try:
                stocks = prop["stocks"]
            except:
                return
            mapping = Globals.get_instance().getstockidnamemapping()
            print "id, \tname, \t\tdata, holded, industry"
            for idx in stocks:
                ll = len(mapping.getname(idx))

                print idx, mapping.getname(idx),
                if ll < 12:
                    print "\t",

                tps = types.stocktypes(idx)
                if "available" in tps:
                    print "\tY",
                else:
                    print "\t-",

                if "holded" in tps:
                    print "\tH",
                else:
                    print "\t-",

                for t in tps:
                    if "available" == t:
                        continue
                    if "holded" == t:
                        continue
                    tp = types.typeproperty(t)["cname"]
                    print "\t", tp,

                print ""

        elif args[0] == "show":
            if len(args) < 2:
                print "please specify the stock id to show its types"
                print self.description()
                return
            mapping = Globals.get_instance().getstockidnamemapping()
            print mapping.getname(args[1])
            print "types:       ",
            for typ in types.stocktypes(args[1]):
                print typ + ",",
        elif args[0] == "help":
            print self.description()
        else:
            print "Unknown type command:", args[0]
Exemple #18
0
    def run(self):
        ss = self.stocks()
        lists = [{},{},{},{}]
        for idx in ss:
            af = DratioAdding(idx)
            stock = Stock(idx, af)

            bs = stock.baseline()
            r2017 = stock.ff().yearreport(2017)

            e = self.gete(stock, bs, r2017)
            if e == None:
                continue
            stock._af.sete(e)
            
            index = 0
            for a in (ss[idx], bs["profit2_adding"], bs["sales_adding"], r2017["sales_adding"]):
                stock._af.seta(a/100.0)
#                if stock.id() == "300230":
#                print stock.name(), stock.id(), stock.a(), stock.e(), stock.dratio()
                dic = lists[index]
                dic[idx] = (idx, stock.a(), stock.dratio())
                index += 1



        LL = []
        for i in range(0, 4):
            dic = lists[i]
            #sort
            ll = self.sort(dic)
            end = len(ll)*6/12
#            end = len(ll)
            LL.append(ll[0:end])

#        self.holded(LL)
#        return

        types = Globals.get_instance().gettypes()

        for tt in types.industries():
            stocks = tt["stocks"]
            tmp = tt["cname"]
            for d in LL[0]:
                d1 = self.item(d[0], LL[1])
                d2 = self.item(d[0], LL[2])
                d3 = self.item(d[0], LL[3])
                if d1 == None or d2 == None or d3 == None:
                    continue

                if not d[0] in stocks:
                    continue

                af = DratioAdding(d[0])
                stock = Stock(d[0], af)
                idt = types.industry(d[0])
                print stock.id(), "(%3.1f %12.1f), (%3.1f, %12.1f), (%3.1f, %12.1f), (%3.1f, %12.1f)"%(d[1], d[2], d1[1], d1[2], d2[1], d2[2], d3[1], d3[2]), "\t", stock.name(), "\t", tmp

        count = 0
        for d in LL[0]:
            d1 = self.item(d[0], LL[1])
            d2 = self.item(d[0], LL[2])
            d3 = self.item(d[0], LL[3])
            if d1 == None or d2 == None or d3 == None:
                continue
            count += 1

            af = DratioAdding(d[0])
            stock = Stock(d[0], af)
            idt = types.industry(d[0])
            if idt != None:
                continue
            print stock.id(), "(%3.1f %12.1f), (%3.1f, %12.1f), (%3.1f, %12.1f), (%3.1f, %12.1f)"%(d[1], d[2], d1[1], d1[2], d2[1], d2[2], d3[1], d3[2]), "\t", stock.name()

        print "total:", count
        pass