Beispiel #1
0
def plotpe(ax):
    global profit, hs300

    daterange = pd.date_range('01/01/2012', end='03/03/2017', freq='B')
    #daterange = pd.date_range('03/01/2014', end = '05/20/2014', freq='B')
    convertrange = daterange.to_pydatetime()
    sz50code, namedf, price, volume = getdata.GetPriceVolume()

    epsall = getdata.GetProfit('eps')
    peseries = Series()
    validpe = Series()

    for date in convertrange:
        if date not in price.index:
            continue
        combinepe = 0
        for code in hs300.index:
            weight = hs300['weight'][code]
            eps = epsall.ix[code]

            quarter = date.month / 4 + 1
            if date.year == 2012:
                earning = eps[20124]
            elif date.year > 2016:
                earning = eps[20163] + eps[20154] - eps[20153]
            else:
                if quarter == 1:
                    earning = eps[(date.year - 1) * 10 + 4]
                else:
                    earning = eps[date.year * 10 + quarter - 1] + eps[
                        (date.year - 1) * 10 + 4] - eps[(date.year - 1) * 10 +
                                                        quarter - 1]

            temppe = float(price[code][date]) / earning

            if not isnan(temppe):
                validpe[code] = temppe

            if isnan(temppe) and code in validpe.index:
                temppe = validpe[code]

            if (not isnan(temppe)) and temppe > 0:
                combinepe = combinepe + weight * temppe
                #print combinepe
            #if date.year == 2014 and date.month==4  and date.day == 3 and temppe < 0:
            #	print date, code, temppe, earning

        peseries[date] = combinepe
        print date, combinepe
    #normalizedpe = (peseries - peseries.min()) / (peseries.max() - peseries.min())

    ax.set_title("hs300PE")
    peseries.plot(ax=ax)
Beispiel #2
0
    volume1 = volume1.apply(lambda x: (x - np.mean(x)) /
                            (np.max(x) - np.min(x)))
    volume_ma = pd.rolling_mean(volume1, window=30)
    #price_ma = pd.rolling_mean(price1, window = 30)
    #ss = getdata.GetWindowCorr(price_ma[code1], volume_ma[code1], 90)
    #price_ma[code1].plot(color='r')
    price1.plot(label="PE")
    #volume_ma[code1].plot(color='y')
    #ss.plot(color='b')
    plt.show()


if __name__ == "__main__":
    global profit, hs300, roe, growth_mbrg, growth_nprg, growth_nav

    profit = getdata.GetProfit('net_profits')
    basic = getdata.GetBasic()['totals']
    roe = getdata.GetProfit('roe')
    growth_mbrg = getdata.GetGrowth('mbrg')
    growth_nprg = getdata.GetGrowth('nprg')

    #growth_nav = getdata.GetGrowth('nav')

    hs300 = getdata.GetHs300()
    zz500 = getdata.GetZz500()

    #retpearray = Series()
    #retpbarray = Series()
    #plotcorrelation()

    #plot use subplot
Beispiel #3
0
    ratio.plot(ax=ax)
    plt.show()


def calcdivratio(code):
    global divi, hs300, eps
    zzidx = [2012, 2013, 2014, 2015, 2016]
    codelist = [
        '600015', '601166', '000001', '600000', '600036', '600016', '601818',
        '601998'
    ]
    ret = DataFrame(index=codelist, columns=zzidx)
    #print divi.ix[code]
    #print eps.ix[code]

    for code in ret.index:
        for year in zzidx:
            ret[year][code] = divi[year][code] / eps[year * 10 + 3][code] * 10
        print hs300['name'][code].decode('UTF-8'), ret.ix[code]


if __name__ == "__main__":

    global divi, hs300, eps
    divi = getdata.GetDiv('divi')
    eps = getdata.GetProfit('eps')
    #print divi
    hs300 = getdata.GetHs300()
    #plotdivratio('601166')
    calcdivratio('601166')