예제 #1
0
 def LoadPortfolios(self, portfolios):
     """"""
     self.logger.info("<{}>-Load portfolios".format(
         __name__.split('.')[-1]))
     self.trdDate = GetTrdDay.GetTradeDays()
     self.rebalanceDate = sorted(portfolios.keys())
     self.ports = portfolios
예제 #2
0
파일: IC.py 프로젝트: wusf/MyQunatLib
 def SetRebalanceDate(self, begDate, endDate, freq, day):
     """"""
     self.logger.info("<{}>-Set rebalance frequency: {}".format(
         __name__.split('.')[-1], freq))
     self.objTradeDays = GetTrdDays.TradeDays()
     self.objTradeDays.GetTradeDays()
     self.rebalaceDays = self.objTradeDays.GetRebalanceDays(
         begDate, endDate, freq, day)
예제 #3
0
 def __init__(self, logger=None):
     """Constructor"""
     if logger == None:
         self.logger = LogHandler.LogOutputHandler(
             "ComputeFactorsAndZScores")
     else:
         self.logger = logger
     self.trdDays = GetTrdDay.GetTradeDays()
예제 #4
0
 def __init__(self,logger=None):
     """Constructor"""
     #Create log file
     if logger == None:
         self.logger = LogHandler.LogOutputHandler("ComputeFactorsAndZScores")
     else:    
         self.logger = logger
         
     dbPathProcessedData = GetPath.GetLocalDatabasePath()["EquityDataRefined"]
     self.dbPathProcessedData = dbPathProcessedData
     self.totalTradeDay = GetTrdDay.GetTradeDays()   
    def __init__(self,
                 dbPathFactorValues,
                 dbPathMarketData,
                 begDate,
                 endDate,
                 logger=None):
        """Constructor"""
        if logger == None:
            self.logger = logging.logger()
        else:
            self.logger = logger

        dbPathRawData = GetPath.GetLocalDatabasePath()["RawEquity"]
        dbPathProcessedData = GetPath.GetLocalDatabasePath()["ProcEquity"]

        #价格数据录入内存数据库
        self.connDbMkt = lite.connect(":memory:")
        self.connDbMkt.text_factory = str
        cur = self.connDbMkt.cursor()
        self.logger.info(
            "<{}>-Load local database into in-memory database".format(
                __name__.split('.')[-1]))
        _dbPathMarketData = dbPathRawData + dbPathMarketData
        cur.execute("ATTACH '{}' AS MktData".format(_dbPathMarketData))
        cur.execute(
            "CREATE TABLE MktData AS SELECT StkCode,Date,LC,TC FROM MktData.AStockData WHERE Date>='{}'"
            .format(begDate))
        cur.execute("CREATE INDEX mId ON MktData (Date,StkCode)")
        self.logger.info("<{}>-Done".format(__name__.split('.')[-1]))

        #连接因子数据库
        dbFactorValue = dbPathProcessedData + dbPathFactorValues
        self.connDbFV = lite.connect(dbFactorValue)
        self.connDbFV.text_factory = str

        #获取交易日
        self._trdDays = GetTrdDay.GetTradeDays()
        self.revalueDays = []
        self.trdDays = []
        cur = self.connDbFV.cursor()
        cur.execute("SELECT DISTINCT Date FROM FactorValues ORDER BY Date ASC")
        rows = cur.fetchall()
        for row in rows:
            self.revalueDays.append(row[0])
        for d in self._trdDays:
            if d >= self.revalueDays[0] and d <= endDate and d >= begDate:
                self.trdDays.append(d)

        #Initialte CalculatePortfolioReturn
        self.objCalcPortReturn = CalcPortRet.CalculatePortfolioReturn(
            dbPathMarketData, self.connDbMkt, self.logger)
예제 #6
0
 def CalcVols(self, begDate, endDate, returnHorizon):
     """"""
     self.trdDate = GetTrdDays.GetTradeDays()
     trdDay = []
     for d in self.trdDate:
         if d >= begDate and d <= endDate:
             trdDay.append(d)
     crossSectionalVols = {}
     for _index in self.constituentIndexCode:
         _vols = []
         for day in trdDay:
             stks = self.objConstituentStocks.GetConstituentStocksAtGivenDate(
                 day, [_index])
             numOfStks = len(stks)
             histRet = []
             for stk in stks:
                 hRet = self.objGetFactorValues.GetHistoricalReturns(
                     stk, day, returnHorizon)
                 histRet.append(hRet)
             vol = numpy.nanstd(histRet)
             _vols.append(vol)
         crossSectionalVols[_index] = _vols
     df = pd.DataFrame(crossSectionalVols, index=trdDay)
     return df
예제 #7
0
 def SetRebalanceDate(self, begDate, endDate, freq, day):
     """"""
     self.objTradeDays = GetTrdDays.TradeDays()
     self.objTradeDays.GetTradeDays()
     self.rebalaceDays = self.objTradeDays.GetRebalanceDays(
         begDate, endDate, freq, day)