Exemple #1
0
    def addFund(self):

        secID = self.cbFund.itemData(self.cbFund.currentIndex())
        if secID in self._funds:
            return
        npNav = SinaQuote.GetHNav(secID)
        #stsdate = pd.to_datetime( self.sdate.date().toPython() )
        #etsdate =  pd.to_datetime( self.edate.date().toPython() )
        stsdate = self.sdate.text()
        etsdate = self.edate.text()
        npNav = npNav[npNav.fbrq >= stsdate]
        npNav = npNav[npNav.fbrq <= etsdate]

        npNav.adjNav = npNav.adjNav / npNav.adjNav[0] * 100

        self.ax1.plot(pd.to_datetime(npNav.fbrq),
                      npNav.adjNav,
                      label=self.cbFund.currentText())

        leg = self.ax1.legend(loc=0, fontsize=10, frameon=False)
        leg.get_frame().set_facecolor((.94, .94, .94))
        import matplotlib.dates
        import datetime
        xlim = matplotlib.dates.date2num([
            self.sdate.date().toPython(),
            self.edate.date().toPython() + datetime.timedelta(days=2)
        ])
        if np.min(npNav.adjNav) - 5.0 < self._ylim[0]:
            self._ylim[0] = np.min(npNav.adjNav) - 5.0
        if np.max(npNav.adjNav) + 5.0 > self._ylim[1]:
            self._ylim[1] = np.max(npNav.adjNav) + 5.0
        ysticks = [100]
        ys = 110
        while ys < self._ylim[1]:
            ysticks.append(ys)
            ys = ys * 1.1
        ys = 90
        while ys > self._ylim[0]:
            ysticks.append(ys)
            ys = ys * 0.9
        ysticks.sort()
        self.ax1.set_yscale(u'log')
        self.ax1.set_ylim(self._ylim[0], self._ylim[1])
        self.ax1.yaxis.set_ticks(ysticks)
        self.ax1.yaxis.set_major_formatter(mticker.FormatStrFormatter('%.1f'))
        self.ax1.yaxis.grid(True, color='0.6', linestyle='-', linewidth=0.5)
        self.ax1.set_xlim(xlim[0], xlim[1])

        #self.canvas.fig.autofmt_xdate()
        self.canvas.draw_idle()
        self._funds.append(secID)
Exemple #2
0
#coding=utf-8
# tpomcuvnmu 
# 501038 166024 501049 (即将上市交易) 封闭2年的创新型杠杆封基163417
import pandas as pd
import numpy as np
import xlwings as xw
import SinaQuote

wb = xw.Book('Funds.xlsx')
sht = wb.sheets['FundPerf']

for i in range(2,1000):    
    code=sht.range('B{0}'.format(i)).value
    print(code)
    if code != None:
        npNav = SinaQuote.GetHNav( code[2:] )
        if len(npNav) > 1:
            sht.range((i,4)).value = npNav.fbrq[-1]
            sht.range((i,5)).value = npNav.adjNav[-1] / npNav.adjNav[-2] - 1.0
        for j in range(6,20):
            bdate = sht.range((1,j)).value
            if bdate != None:
                begNav = npNav[ npNav.fbrq ==bdate ]
                if len(begNav) > 0:
                    sht.range((i,j)).value = npNav.adjNav[-1] / begNav.adjNav[0] - 1.0
                pass
            else:
                break
    else:
        break