In [1]:
#!/Tsan/bin/python
# -*- coding: utf-8 -*-

In [279]:
# Libraries to use
from __future__ import division 
import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import datetime
import statsmodels
import cvxopt as cv
from cvxopt import solvers

In [2]:
# Import My own library for factor testing
from SingleFactorTest import factorFilterFunctions as ff

from BarraModel import barraRiskModel as brm
#from config import *

In [4]:
%matplotlib inline

In [5]:
# basic stocl pool
ZZ500Weight = 'LZ_GPA_INDEX_CSI500WEIGHT.csv'
HS300Weight = 'LZ_GPA_INDEX_HS300WEIGHT.csv'

In [6]:
filenamePrice ='LZ_GPA_DERI_AdjustedPriceForward_20.csv'

In [7]:
# Factors
# Value factor
filenamePE='LZ_GPA_VAL_PE.csv'  # 市盈率
filenamePB='LZ_GPA_VAL_PB.csv'  # 市净率
filenamePS = 'LZ_GPA_VAL_PS.csv' # 市销率
filenamePCF = 'LZ_GPA_VAL_PC.csv' # 市现率

# Growth factor
filenameYOYGR = 'LZ_GPA_FIN_IND_QFA_YOYGR.csv'  # 单季度.营业总收入同比增长率(%)
filenameYOYNETPROFIT = 'LZ_GPA_FIN_IND_QFA_YOYNETPROFIT.csv' # 单季度.归属母公司股东的净利润同比增长率(%)
filenameYOYOCF = 'LZ_GPA_FIN_IND_YOYOCF.csv' # 同比增长率-经营活动产生的现金流量净额(%)
filenameYOYROE = 'LZ_GPA_FIN_IND_YOYROE.csv' # 同比增长率-净资产收益率(摊薄)(%)
filenameYOYBPS = 'LZ_GPA_FIN_IND_YOYBPS.csv' # 相对年初增长率-每股净资产(%)

# Financial factor
filenameCAPITALIZEDTODA = 'LZ_GPA_FIN_IND_CAPITALIZEDTODA.csv'  # 资本支出/折旧和摊销
filenameCASHRATIO = 'LZ_GPA_FIN_IND_CASHRATIO.csv' # 保守速动比率
filenameCASHTOLIQDEBT = 'LZ_GPA_FIN_IND_CASHTOLIQDEBT.csv' # 货币资金/流动负债
filenameOCFTODEBT = 'LZ_GPA_FIN_IND_OCFTODEBT.csv' # 经营活动产生的现金流量净额/负债合计
filenamePROFITTOOP = 'LZ_GPA_FIN_IND_PROFITTOOP.csv' # 利润总额/营业收入

# Momentum factor
filenameTRUEMOM = 'LZ_GPA_USR_MOM.csv' # 真动量
filenameMOM1M = 'LZ_GPA_DERI_Momentum_1M.csv' # 一月反转
filenameMOM3M = 'LZ_GPA_TURNOVER_TurnoverAvg_3M.csv' # 三月反转
filenamePVO = 'LZ_GPA_DERI_PVO.csv' # 一年偏度
filenameRV1Y = 'LZ_GPA_DERI_RealizedVolatility_1Y.csv' # 一年收益波动
filenameABNORMALVOLUME = 'LZ_GPA_DERI_NormalizedAbormalVolume.csv' # 归一化异常交易量
filenameSKEW = 'LZ_GPA_DERI_TSKEW.csv'# 偏度

# Volatility factor


# Liquidity factor
filenameTURNOVER1M = 'LZ_GPA_TURNOVER_TurnoverAvg_1M.csv' # 一月换手率均值
filenameAMOUNTAVG1M = 'LZ_GPA_DERI_AmountAvg_1M.csv'      #  日均成交量
filenameILLIQ = 'LZ_GPA_DERI_ILLIQ.csv'                   # 非流动性因子
filenameVOLUME = 'LZ_GPA_QUOTE_TVOLUME.csv'               # 成交量

In [8]:
filenameFCAP = 'LZ_GPA_VAL_A_FCAP.csv'

filenameBENCH = 'LZ_GPA_INDXQUOTE_CLOSE.csv'

filenamePriceOrg = 'LZ_GPA_QUOTE_TCLOSE.csv'

In [10]:
# some useful parameters
startTime =  datetime.strptime('20120101', '%Y%m%d')
endTime = datetime.strptime('20161231', '%Y%m%d')
facNum = 5 # factor Num
path = ff.data_path # path
timeStampNum = 2500 # Number of time period
thresholdNum = 0.05  # thresholdNum to filter stocks by Nan's amount
HS300Index ='000300.SH' # HS300 index code
ZZ500Index = '000905.SH' #   ZZ500 index code

In [11]:
orgPrice = pd.read_csv(path+filenamePriceOrg,infer_datetime_format=True,parse_dates=[0],index_col=0)
orgPrice.shape


Out[11]:
(2989, 3294)

In [12]:
stockPool = pd.read_csv(path+ZZ500Weight,infer_datetime_format=True,parse_dates=[0],index_col=0).loc[startTime:endTime]
#stockPool = stockPool.iloc[-1].dropna(how='any').index.tolist()  # get today's ZX500 stock pool
stockPool1 = pd.read_csv(path+HS300Weight,infer_datetime_format=True,parse_dates=[0],index_col=0).loc[startTime:endTime]

In [13]:
stockPool = stockPool.dropna(how = 'all',axis =1).columns.tolist() # stock pool
stockPool1 = stockPool1.dropna(how = 'all',axis =1).columns.tolist()

In [14]:
stockPool = list((set(stockPool1)|set(stockPool)))

In [15]:
len(stockPool)


Out[15]:
1186

In [16]:
class dataCleaning():
    
    def __init__(self,data):
        self.__data = data
    #@property
    #def _constructor(self):
    #    return dataCleaning

    #@property
    #def _constructor_sliced(self):
    #   return SubclassedSeries
        
    def narrowData(self):
        return self.__data[stockPool].loc[startTime:endTime]
    
    def Normalize(self,narrowedData):
        dataWinsorized = narrowedData.copy()
        dataWinsorizedTrans = dataWinsorized.T
        MAD = 1.483*np.abs(dataWinsorizedTrans-dataWinsorizedTrans.median(skipna=True))
        return ((dataWinsorizedTrans - dataWinsorizedTrans.mean(axis=0, skipna=True))/dataWinsorizedTrans.std(axis=0, skipna=True)).T

In [17]:
PriceDF = pd.read_csv(path+filenamePrice,infer_datetime_format=True,parse_dates=[0],index_col=0)[stockPool].loc[startTime:endTime]

In [18]:
LFCAPData = np.log10(pd.read_csv(path+filenameFCAP,infer_datetime_format=True,parse_dates=[0],index_col=0))

PBData = pd.read_csv(path+filenamePB,infer_datetime_format=True,parse_dates=[0],index_col=0)

YOYBPSData = pd.read_csv(path+filenameYOYBPS,infer_datetime_format=True,parse_dates=[0],index_col=0)

AMOUNTAVG1MData = pd.read_csv(path+filenameAMOUNTAVG1M,infer_datetime_format=True,parse_dates=[0],index_col=0)

TURNOVER1MData = pd.read_csv(path+filenameTURNOVER1M,infer_datetime_format=True,parse_dates=[0],index_col=0)

PROFITOOPData = pd.read_csv(path+filenamePROFITTOOP,infer_datetime_format=True,parse_dates=[0],index_col=0)

benchmarkData = pd.read_csv(path+filenameBENCH,infer_datetime_format=True,parse_dates=[0],index_col=0)[ZZ500Index].loc[startTime:endTime]

In [19]:
#isinstance(dataCleaning(PBData).narrowData(),dataCleaning)

In [20]:
PBData = dataCleaning(PBData).Normalize(dataCleaning(PBData).narrowData())
LFCAPData  = dataCleaning(LFCAPData ).Normalize(dataCleaning(LFCAPData ).narrowData())
YOYBPSData = dataCleaning(YOYBPSData).Normalize(dataCleaning(YOYBPSData).narrowData())
AMOUNTAVG1MData = dataCleaning(AMOUNTAVG1MData).Normalize(dataCleaning(AMOUNTAVG1MData).narrowData())
TURNOVER1MData = dataCleaning(TURNOVER1MData).Normalize(dataCleaning(TURNOVER1MData).narrowData())
PROFITOOPData = dataCleaning(PROFITOOPData).Normalize(dataCleaning(PROFITOOPData).narrowData())

In [21]:
print PBData.shape[1], LFCAPData.shape[1], YOYBPSData.shape[1], AMOUNTAVG1MData.shape[1], TURNOVER1MData.shape[1], PROFITOOPData.shape[1]


1186 1186 1186 1186 1186 1186

In [22]:
#PROFITOOPData

In [23]:
# filter and fill data
def filterAndfill(data,threshold):
    df = data.loc[:,data.isnull().sum() < data.shape[1] * threshold]
    return df.fillna(method = 'ffill').fillna(method = 'bfill')

In [24]:
PBData = PBData .loc[:, PBData .isnull().sum() < (len(PBData) * thresholdNum)]
LFCAPData  = LFCAPData .loc[:, LFCAPData .isnull().sum() < (len(LFCAPData) * thresholdNum)]
YOYBPSData = YOYBPSData .loc[:, YOYBPSData .isnull().sum() < (len(YOYBPSData) * thresholdNum)]
AMOUNTAVG1MData = AMOUNTAVG1MData .loc[:, AMOUNTAVG1MData .isnull().sum() < (len(AMOUNTAVG1MData) * thresholdNum)]
TURNOVER1MData = TURNOVER1MData .loc[:, TURNOVER1MData .isnull().sum() < (len(TURNOVER1MData) * thresholdNum)]
PROFITOOPData  = PROFITOOPData  .loc[:, PROFITOOPData .isnull().sum() < (len(PROFITOOPData ) * thresholdNum)]

PriceDF = PriceDF.loc[:, (PriceDF.isnull().sum() < (len(PriceDF) * thresholdNum))]

In [25]:
TURNOVER1MData


Out[25]:
002344.SZ 000793.SZ 600059.SH 000713.SZ 600360.SH 000528.SZ 000063.SZ 601101.SH 000685.SZ 000636.SZ ... 000002.SZ 600122.SH 600469.SH 600282.SH 600739.SH 600406.SH 600866.SH 600121.SH 601908.SH 002195.SZ
LZ_GPA_TURNOVER_TurnoverAvg_1M-f
2012-01-04 -0.176351 -0.241920 0.050054 0.869193 -0.366411 -0.093829 -0.393634 0.019835 0.223272 -0.362456 ... -0.364535 -0.065026 -0.095687 -0.491847 -0.103122 -0.417364 -0.226168 -0.572395 1.834449 0.389762
2012-01-05 -0.148203 -0.249227 0.053181 0.922777 -0.369314 -0.073094 -0.399965 0.024752 0.273700 -0.367420 ... -0.363392 -0.064554 -0.104441 -0.497757 -0.094877 -0.417484 -0.227977 -0.583313 1.908621 0.397108
2012-01-06 -0.150965 -0.253463 0.056583 0.966051 -0.375157 -0.076563 -0.406325 0.021471 0.292534 -0.373791 ... -0.362520 -0.064029 -0.096429 -0.502588 -0.090162 -0.411667 -0.235200 -0.589101 1.945360 0.382742
2012-01-09 -0.147897 -0.271938 0.053587 0.999738 -0.383023 -0.083020 -0.407480 0.022990 0.325065 -0.376640 ... -0.365216 -0.071729 -0.099137 -0.512626 -0.072496 -0.411301 -0.236356 -0.601228 1.995226 0.356548
2012-01-10 -0.152183 -0.279319 0.037945 0.942761 -0.370101 -0.076421 -0.406706 0.089766 0.378797 -0.370965 ... -0.351053 -0.088790 -0.062426 -0.505284 -0.053147 -0.402723 -0.247932 -0.591522 1.897973 0.282578
2012-01-11 -0.168841 -0.322439 0.010055 1.036801 -0.383707 -0.020533 -0.428879 0.217896 0.474164 -0.387665 ... -0.358099 -0.089980 -0.025234 -0.534745 -0.022924 -0.417929 -0.241646 -0.626192 1.758969 0.237720
2012-01-12 -0.162372 -0.322084 -0.033919 0.959788 -0.360970 -0.013654 -0.410265 0.260215 0.470223 -0.370419 ... -0.349857 -0.099265 -0.037710 -0.505792 -0.028520 -0.400478 -0.223688 -0.592075 1.550123 0.312365
2012-01-13 -0.183801 -0.346556 -0.062592 0.961231 -0.368488 -0.000548 -0.428325 0.294343 0.510059 -0.369837 ... -0.366494 -0.093252 -0.034006 -0.528796 -0.036445 -0.414237 -0.225953 -0.616371 1.684493 0.424654
2012-01-16 -0.212042 -0.376568 -0.082489 0.984949 -0.380708 0.016878 -0.437954 0.333461 0.590162 -0.374992 ... -0.378573 -0.094583 -0.031932 -0.545493 -0.042599 -0.425377 -0.232737 -0.573792 1.777184 0.468624
2012-01-17 -0.219125 -0.394498 -0.088873 0.917117 -0.390129 0.038771 -0.444035 0.372458 0.623077 -0.379241 ... -0.384374 -0.104654 -0.017012 -0.558088 -0.051787 -0.410341 -0.239160 -0.503438 1.811306 0.500328
2012-01-18 -0.245147 -0.411192 -0.110104 0.871144 -0.401055 0.040412 -0.454860 0.417836 0.627728 -0.393604 ... -0.384941 -0.125616 -0.004364 -0.567185 -0.067020 -0.397362 -0.257404 -0.407806 1.813784 0.518071
2012-01-19 -0.274954 -0.430320 -0.125285 0.869315 -0.417791 0.056413 -0.466226 0.482096 0.633287 -0.397418 ... -0.403628 -0.163700 0.023308 -0.582603 -0.060625 -0.397930 -0.267881 -0.354266 1.813680 0.546191
2012-01-20 -0.287666 -0.438861 -0.137945 0.812346 -0.432491 0.078376 -0.432853 0.510944 0.615313 -0.399626 ... -0.395634 -0.170500 0.030190 -0.579570 -0.045881 -0.408720 -0.267592 -0.308893 1.656007 0.544229
2012-01-30 -0.306125 -0.457798 -0.134974 0.857664 -0.444669 0.127795 -0.387081 0.562299 0.648002 -0.409160 ... -0.403123 -0.201241 0.031396 -0.595858 -0.024422 -0.417538 -0.275965 -0.282890 1.709626 0.586615
2012-01-31 -0.299987 -0.440980 -0.137565 0.789206 -0.421361 0.128308 -0.355007 0.526171 0.583492 -0.385952 ... -0.364868 -0.200108 0.008899 -0.561914 -0.024017 -0.406620 -0.267634 -0.252964 1.554799 0.534224
2012-02-01 -0.301852 -0.468548 -0.145177 0.814509 -0.432690 0.146472 -0.353794 0.559221 0.595519 -0.391784 ... -0.370900 -0.211667 0.009198 -0.575289 -0.031840 -0.412883 -0.273020 -0.226196 1.633841 0.554533
2012-02-02 -0.326846 -0.482990 -0.152960 0.815525 -0.435350 0.136561 -0.353160 0.592577 0.587722 -0.400793 ... -0.377825 -0.217205 0.016963 -0.589346 -0.025147 -0.422286 -0.279675 -0.207650 1.669252 0.579474
2012-02-03 -0.336597 -0.485897 -0.160608 0.764376 -0.436665 0.147052 -0.352183 0.647395 0.576620 -0.409051 ... -0.383313 -0.223898 0.014160 -0.600853 -0.018022 -0.420203 -0.281479 -0.181641 1.687573 0.578504
2012-02-06 -0.350271 -0.499601 -0.173187 0.698719 -0.400753 0.147716 -0.352297 0.658856 0.543902 -0.407624 ... -0.387502 -0.220205 0.011300 -0.610527 -0.027678 -0.421104 -0.246912 -0.146946 1.670068 0.581189
2012-02-07 -0.334052 -0.514300 -0.186763 0.685674 -0.391928 0.142268 -0.345534 0.710393 0.511572 -0.412133 ... -0.397465 -0.231599 0.015186 -0.621467 -0.034022 -0.421312 -0.237994 -0.121478 1.831008 0.588126
2012-02-08 -0.336347 -0.521263 -0.198244 0.656236 -0.387846 0.138273 -0.349784 0.724136 0.484572 -0.417289 ... -0.393781 -0.229638 0.014006 -0.628526 -0.022207 -0.430481 -0.235447 -0.091689 1.872689 0.601832
2012-02-09 -0.356701 -0.528646 -0.197149 0.620384 -0.386122 0.165222 -0.357099 0.792308 0.448954 -0.427058 ... -0.393200 -0.239033 0.049933 -0.635407 -0.040774 -0.440361 -0.231101 -0.018088 1.964097 0.603965
2012-02-10 -0.377991 -0.539581 -0.196030 0.584913 -0.385109 0.148882 -0.360883 0.842562 0.410270 -0.430896 ... -0.392298 -0.241976 0.049180 -0.649815 -0.062422 -0.457095 -0.218549 0.019884 2.018375 0.614870
2012-02-13 -0.397476 -0.557135 -0.213564 0.582310 -0.392934 0.164331 -0.369005 0.876639 0.400119 -0.432317 ... -0.375599 -0.243280 0.054585 -0.653671 -0.073503 -0.480147 -0.221327 0.035366 2.008112 0.616491
2012-02-14 -0.415274 -0.568373 -0.211204 0.562843 -0.350739 0.164588 -0.381545 0.911076 0.372311 -0.414295 ... -0.382098 -0.242748 0.055005 -0.661910 -0.098881 -0.495954 -0.226104 0.044354 2.035851 0.652825
2012-02-15 -0.426435 -0.579982 -0.223918 0.570665 -0.342374 0.145326 -0.383730 0.868075 0.295250 -0.399825 ... -0.388246 -0.254687 0.031297 -0.670751 -0.139479 -0.509338 -0.231509 0.062828 2.064115 0.696201
2012-02-16 -0.425443 -0.576007 -0.236791 0.498661 -0.315325 0.099245 -0.357816 0.790114 0.242605 -0.377186 ... -0.402805 -0.253713 0.017101 -0.672348 -0.134634 -0.514295 -0.231553 0.102238 2.069179 0.724048
2012-02-17 -0.433813 -0.572508 -0.232145 0.490395 -0.300185 0.068313 -0.337932 0.740062 0.191899 -0.369159 ... -0.411948 -0.224619 0.021272 -0.683131 -0.137650 -0.521680 -0.237403 0.128969 2.208334 0.584542
2012-02-20 -0.432552 -0.567778 -0.238432 0.496084 -0.286920 0.044491 -0.333549 0.713215 0.176222 -0.377078 ... -0.416579 -0.238442 0.012377 -0.684973 -0.122271 -0.526266 -0.241663 0.144508 2.202496 0.476408
2012-02-21 -0.435873 -0.574868 -0.241613 0.477905 -0.284171 0.029205 -0.332529 0.687086 0.122953 -0.379727 ... -0.415824 -0.246459 0.008495 -0.693053 -0.123263 -0.523904 -0.254238 0.097749 2.118811 0.442097
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2016-11-21 0.339211 0.327051 -0.478526 0.216833 1.009662 0.122831 -0.258610 -1.011798 -0.480532 0.350209 ... -0.356853 -0.405601 -0.242672 -0.445705 -0.029647 -0.505557 0.021167 0.309672 -0.592936 0.870772
2016-11-22 0.348309 0.337006 -0.477614 0.228182 0.989635 0.098060 -0.245707 -1.012429 -0.494311 0.357895 ... -0.341186 -0.409292 -0.238683 -0.423313 -0.006477 -0.503478 0.007337 0.293464 -0.521057 0.929354
2016-11-23 0.348850 0.335159 -0.476456 0.229714 0.995550 0.067371 -0.285965 -1.016022 -0.426617 0.357303 ... -0.344394 -0.414025 -0.245770 -0.372995 0.104248 -0.502326 0.001805 0.247501 -0.434856 1.004881
2016-11-24 0.367093 0.337730 -0.474700 0.245077 0.992066 0.078542 -0.303518 -1.019543 -0.393657 0.312578 ... -0.348902 -0.258886 -0.257183 -0.318815 0.135082 -0.506026 -0.011809 0.170837 -0.408522 1.039779
2016-11-25 0.378846 0.332780 -0.473555 0.230566 1.020618 0.060976 -0.297504 -1.023122 -0.236251 0.312612 ... -0.357601 -0.224203 -0.257299 -0.262019 0.237898 -0.490263 -0.049177 0.165737 -0.414943 1.181434
2016-11-28 0.381775 0.296359 -0.479544 0.223207 1.046428 0.067307 -0.274996 -1.033295 -0.174653 0.303401 ... -0.361522 -0.273774 -0.267017 -0.227405 0.281875 -0.495471 -0.037072 0.131145 -0.416549 1.228019
2016-11-29 0.382884 0.303165 -0.475943 0.192036 0.966235 0.065597 -0.296858 -1.043822 -0.111336 0.283537 ... -0.352027 -0.312521 -0.286869 -0.205921 0.312418 -0.486903 -0.044388 0.117805 -0.418700 1.167163
2016-11-30 0.374142 0.230828 -0.467690 0.178063 0.939709 0.064111 -0.287178 -1.057634 -0.083427 0.245842 ... -0.360965 -0.346877 -0.273983 -0.155535 0.320914 -0.556055 -0.078779 0.098878 -0.431606 1.119928
2016-12-01 0.391853 0.188441 -0.453535 0.164641 0.923601 0.087166 -0.281280 -1.064245 -0.062633 0.236595 ... -0.372864 -0.375743 -0.283123 -0.123600 0.348119 -0.577364 -0.067803 0.092138 -0.442613 1.168412
2016-12-02 0.403345 0.141081 -0.440295 0.153185 0.905264 0.087818 -0.227830 -1.070498 -0.044099 0.216368 ... -0.376245 -0.404441 -0.296049 -0.092577 0.365942 -0.582938 -0.094018 0.079462 -0.439269 1.090950
2016-12-05 0.396403 0.007547 -0.451989 0.129430 0.902360 0.085735 -0.211575 -1.076894 -0.040607 0.212192 ... -0.377224 -0.428853 -0.272605 -0.060784 0.356046 -0.583934 -0.087519 0.065595 -0.443127 1.067728
2016-12-06 0.435023 -0.059724 -0.452034 0.112123 0.906201 0.101734 -0.183822 -1.088633 -0.007200 0.213928 ... -0.374652 -0.455101 -0.251837 -0.041369 0.428467 -0.580779 -0.094789 0.045681 -0.443831 1.076773
2016-12-07 0.440893 -0.066906 -0.447040 0.073963 0.929112 0.105765 -0.170952 -1.090142 0.015985 0.240810 ... -0.370060 -0.479381 -0.222863 -0.045225 0.456582 -0.549729 -0.113448 -0.013276 -0.439214 1.112534
2016-12-08 0.378036 -0.061253 -0.446720 0.030825 0.644921 0.106202 -0.238813 -1.091342 0.029054 0.231864 ... -0.357204 -0.502794 -0.200598 -0.015788 0.480091 -0.529847 -0.112802 -0.041478 -0.435094 1.120293
2016-12-09 0.169782 -0.043610 -0.431119 0.030145 0.465799 0.133322 -0.272516 -1.088982 0.042460 0.202115 ... -0.462313 -0.337505 -0.235240 0.009180 0.496282 -0.515746 -0.126452 -0.061747 -0.425869 1.145664
2016-12-12 0.081109 -0.033808 -0.432806 0.008084 0.294452 0.094596 -0.269675 -1.090375 0.051776 0.165231 ... -0.518058 -0.270382 -0.298083 -0.003551 0.542411 -0.495399 -0.174348 -0.136509 -0.414601 1.180259
2016-12-13 0.056150 -0.042762 -0.416011 0.008414 0.274752 0.012084 -0.273143 -1.108492 0.062561 0.160186 ... -0.526692 -0.160998 -0.293781 -0.002460 0.612004 -0.476690 -0.190242 -0.201323 -0.408319 1.245668
2016-12-14 -0.006133 -0.028240 -0.406396 0.078970 0.244948 -0.118562 -0.275224 -1.042991 0.073449 0.092316 ... -0.526085 -0.057184 -0.288198 0.000890 0.645049 -0.452468 -0.202820 -0.272731 -0.448315 1.250050
2016-12-15 -0.042187 -0.029670 -0.415814 0.128432 0.222281 -0.183330 -0.280087 -0.929227 0.085458 0.063167 ... -0.556493 -0.005828 -0.207580 -0.014168 0.663679 -0.379908 -0.189359 -0.304291 -0.457505 1.183270
2016-12-16 -0.065592 -0.045096 -0.405525 0.141736 0.237604 -0.198915 -0.271643 -0.867567 0.126693 0.053820 ... -0.567067 0.043004 -0.154633 -0.014044 0.669048 -0.328086 -0.180149 -0.312134 -0.474979 0.937109
2016-12-19 -0.083675 -0.008960 -0.384299 0.248362 0.203078 -0.235518 -0.258607 -0.810034 0.143088 -0.014755 ... -0.569690 0.076896 -0.109907 -0.028524 0.672902 -0.320174 -0.162324 -0.328041 -0.472701 0.879488
2016-12-20 -0.153944 0.035289 -0.383900 0.362226 0.161799 -0.261483 -0.253889 -0.777796 0.152505 -0.100052 ... -0.593818 0.131212 -0.038110 -0.005918 0.673076 -0.294732 -0.154440 -0.326380 -0.478959 0.797175
2016-12-21 -0.196152 0.044170 -0.387187 0.398765 0.174860 -0.292603 -0.264438 -0.740030 0.162656 -0.176455 ... -0.612233 0.227336 0.005686 -0.017992 0.638360 -0.267010 -0.128415 -0.361149 -0.564060 0.717394
2016-12-22 -0.212938 0.054204 -0.378527 0.476347 0.151573 -0.298470 -0.250567 -0.697605 0.069651 -0.214792 ... -0.596828 0.280681 0.109095 -0.069863 0.472788 -0.236246 -0.116745 -0.400989 -0.658733 0.622029
2016-12-23 -0.232255 0.091244 -0.375569 0.488009 0.150086 -0.315375 -0.243510 -0.655893 0.035301 -0.238426 ... -0.586612 0.138315 0.206033 -0.049636 0.419994 -0.161437 -0.120293 -0.430476 -0.682183 0.585456
2016-12-26 -0.234240 0.175453 -0.380516 0.503552 0.111011 -0.308345 -0.255892 -0.620602 -0.142386 -0.267007 ... -0.570472 0.117711 0.255970 -0.053093 0.212314 -0.121033 -0.111490 -0.474126 -0.693503 0.423348
2016-12-27 -0.233237 0.207867 -0.362428 0.483924 0.058840 -0.319714 -0.278398 -0.580884 -0.208771 -0.236028 ... -0.559975 0.186083 0.302554 -0.046797 0.118723 -0.070017 -0.129127 -0.470867 -0.696086 0.386464
2016-12-28 -0.225549 0.176722 -0.328304 0.492511 0.032220 -0.322516 -0.268330 -0.544023 -0.283736 -0.166854 ... -0.554182 0.249068 0.356346 -0.030349 0.041503 -0.012552 -0.106335 -0.470765 -0.691265 0.358643
2016-12-29 -0.209622 0.190835 -0.335515 0.515818 0.017362 -0.331125 -0.277758 -0.496093 -0.295346 -0.130025 ... -0.543827 0.316363 0.445902 -0.068804 0.009896 0.020193 -0.063188 -0.471845 -0.686699 0.360484
2016-12-30 -0.224775 0.206770 -0.329140 0.519387 0.031108 -0.357354 -0.273219 -0.455438 -0.315036 -0.137832 ... -0.558144 0.398626 0.510387 -0.006404 0.006963 0.033327 -0.059319 -0.469659 -0.671464 0.261797

1214 rows × 1086 columns


In [26]:
print PBData.shape[1], LFCAPData.shape[1], YOYBPSData.shape[1] ,AMOUNTAVG1MData.shape[1], TURNOVER1MData.shape[1], PROFITOOPData.shape[1]


1078 1093 1140 1086 1086 1143

In [27]:
#len(list((DFcolumns(PBData)) & (DFcolumns(YOYBPSData))))

In [28]:
# get intersection
def getInterStk(dfList):
    '''
    To get the columns intersections of several dataframe.
    output: List, the intersection of the columns of dataframes.
    input:
    dfList: List, which contains dataframe u want to get the intersection, len(dfList) should be more than 1.
    '''
    columnsList = map(lambda x: set(x.columns.tolist()), dfList)
    stkList = reduce(lambda x,y: x & y, columnsList)
    return stkList

In [29]:
SA = getInterStk([PBData,YOYBPSData,AMOUNTAVG1MData,TURNOVER1MData,PROFITOOPData,PriceDF])

In [30]:
len(SA)


Out[30]:
1071

In [31]:
def DFcolumns(df):
    return set(df.columns.tolist())

In [32]:
##
stkPool = list((DFcolumns(PBData)) & (DFcolumns(YOYBPSData)) & (DFcolumns(AMOUNTAVG1MData)) & (DFcolumns(TURNOVER1MData)) & (DFcolumns(PROFITOOPData))\
        & (DFcolumns(PriceDF)))
len(stkPool)


Out[32]:
1071

In [33]:
#
def fillData(df,stkPool):
    return df[stkPool].fillna(method='ffill').fillna(method='bfill')

In [34]:
PBData = fillData(PBData,stkPool)
LFCAPData = fillData(LFCAPData,stkPool)
YOYBPSData = fillData(YOYBPSData,stkPool)
AMOUNTAVG1MData = fillData(AMOUNTAVG1MData,stkPool)
TURNOVER1MData = fillData(TURNOVER1MData,stkPool)
PROFITOOPData = fillData(PROFITOOPData,stkPool)

PriceDF = fillData(PriceDF,stkPool)

In [35]:
# independentfactor should be a list contains of dataframe
def orthoFactor(factordf, independentfactor,WLS =False, weightdf = None):
    '''
    Muti variable regression for return.
    returndf and dataframes in factorDict should have same index and same columns
    output: Dataframe, the orthogonalized result of factordf
    input: 
    factordf: Dataframe, factor to be orthogonalized
    independentfactor: List,  the values are the factor dataframe as independence in regression(all \
    with same columns and index)
    '''
    emptydf = pd.DataFrame(index = factordf.index, columns = factordf.columns, data= None, dtype =float)
    dfNum = len(independentfactor)
    if dfNum == 0:
        print 'Input is an empty list!'
        raise ValueError
    for date in factordf.index:
        factordfSlice = factordf.loc[date]
        mapfunction = map(lambda x: x.loc[date], independentfactor)
        if dfNum > 1:
            totaldf = pd.concat(mapfunction, axis=1)         
        else:
            totaldf = independentfactor[0].loc[date]
        if WLS:
            w = weightdf.loc[date]
            result = sm.WLS(factordfSlice.T,totaldf,weights = 1/w ).fit()
        else:
            result = sm.OLS(factordfSlice.T,totaldf ).fit()
        emptydf .loc[date] = result.resid
    return emptydf

In [36]:
LFCAPData.shape


Out[36]:
(1214, 1071)

In [37]:
YOYBPSData


Out[37]:
600507.SH 002344.SZ 000793.SZ 300039.SZ 600059.SH 600501.SH 000713.SZ 002233.SZ 600360.SH 600565.SH ... 600150.SH 600469.SH 600282.SH 600739.SH 600406.SH 600687.SH 600866.SH 000860.SZ 601908.SH 002195.SZ
LZ_GPA_FIN_IND_YOYBPS-d
2012-01-04 0.240171 -0.992352 -0.041829 -0.724594 -0.052970 -0.092335 -0.141171 -0.859772 -0.085465 -0.141542 ... -0.757088 0.006821 -0.172923 0.298903 -1.132173 0.492759 0.009977 -0.040529 5.103138 -0.619124
2012-01-05 0.239668 -0.992292 -0.042203 -0.724656 -0.053339 -0.092687 -0.141500 -0.859774 -0.085819 -0.141871 ... -0.757137 0.006424 -0.173237 0.298374 -1.132050 0.492141 0.009579 -0.040904 5.100416 -0.619235
2012-01-06 0.239805 -0.993245 -0.042316 -0.725372 -0.053462 -0.092844 -0.141700 -0.860609 -0.085970 -0.142071 ... -0.757881 0.006355 -0.173465 0.298562 -1.133126 0.492501 0.009513 -0.041015 5.104851 -0.619858
2012-01-09 0.240006 -0.993583 -0.042238 -0.725593 -0.053389 -0.092788 -0.141665 -0.860889 -0.085912 -0.142037 ... -0.758116 0.006454 -0.173445 0.298789 -1.133525 0.492813 0.009613 -0.040937 5.107181 -0.620033
2012-01-10 0.240006 -0.993583 -0.042238 -0.725593 -0.053389 -0.092788 -0.141665 -0.860889 -0.085912 -0.142037 ... -0.758116 0.006454 -0.173445 0.298789 -1.133525 0.492813 0.009613 -0.040937 5.107181 -0.620033
2012-01-11 0.239869 -0.994227 -0.042491 -0.726127 -0.053647 -0.093062 -0.141960 -0.861479 -0.086183 -0.142331 ... -0.758664 0.006220 -0.173752 0.298676 -1.134227 0.492779 0.009381 -0.041190 5.109043 -0.620524
2012-01-12 0.239869 -0.994227 -0.042491 -0.726127 -0.053647 -0.093062 -0.141960 -0.861479 -0.086183 -0.142331 ... -0.758664 0.006220 -0.173752 0.298676 -1.134227 0.492779 0.009381 -0.041190 5.109043 -0.620524
2012-01-13 0.239869 -0.994227 -0.042491 -0.726127 -0.053647 -0.093062 -0.141960 -0.861479 -0.086183 -0.142331 ... -0.758664 0.006220 -0.173752 0.298676 -1.134227 0.492779 0.009381 -0.041190 5.109043 -0.620524
2012-01-16 0.239794 -0.994252 -0.042555 -0.726163 -0.053709 -0.093123 -0.142019 -0.861509 -0.086245 -0.142391 ... -0.758698 0.006155 -0.173810 0.298599 -1.134246 0.492694 0.009316 -0.041253 5.108771 -0.620563
2012-01-17 0.239569 -0.994165 -0.042708 -0.726144 -0.053860 -0.093264 -0.142148 -0.861456 -0.086387 -0.142519 ... -0.758671 0.005989 -0.173931 0.298359 -1.134123 0.492405 0.009149 -0.041407 5.107314 -0.620571
2012-01-18 0.239569 -0.994165 -0.042708 -0.726144 -0.053860 -0.093264 -0.142148 -0.861456 -0.086387 -0.142519 ... -0.758671 0.005989 -0.173931 0.298359 -1.134123 0.492405 0.009149 -0.041407 5.107314 -0.620571
2012-01-19 0.240100 -0.994156 -0.042297 -0.726021 -0.053454 -0.092874 -0.141778 -0.861390 -0.085994 -0.142150 ... -0.758562 0.006421 -0.173575 0.298914 -1.134173 0.493042 0.009582 -0.040995 5.109901 -0.620404
2012-01-20 0.238777 -0.993341 -0.043131 -0.725671 -0.054268 -0.093621 -0.142440 -0.860805 -0.086753 -0.142811 ... -0.758155 0.005503 -0.174182 0.297489 -1.133116 0.616949 0.008658 -0.041831 5.100143 -0.620236
2012-01-30 0.238896 -0.993764 -0.043135 -0.725976 -0.054278 -0.093647 -0.142488 -0.861170 -0.086776 -0.142859 ... -0.758475 0.005520 -0.174244 0.297635 -1.133601 0.617235 0.008677 -0.041835 5.102407 -0.620495
2012-01-31 0.238502 -0.994094 -0.043515 -0.726320 -0.054657 -0.094025 -0.142863 -0.861507 -0.087154 -0.143234 ... -0.758817 0.005137 -0.174617 0.297237 -1.133923 0.616820 0.008294 -0.042215 5.101755 -0.620845
2012-02-01 0.238410 -0.994348 -0.043644 -0.726539 -0.054787 -0.094160 -0.143005 -0.861743 -0.087288 -0.143376 ... -0.759040 0.005015 -0.174763 0.297153 -1.134195 0.616778 0.008172 -0.042344 5.102302 -0.621049
2012-02-02 0.238306 -0.994633 -0.043790 -0.726784 -0.054934 -0.094313 -0.143165 -0.862009 -0.087440 -0.143536 ... -0.759290 0.004876 -0.174927 0.297058 -0.976615 0.616730 0.008034 -0.042489 5.102912 -0.621280
2012-02-03 0.238288 -0.994688 -0.043816 -0.726831 -0.054961 -0.094341 -0.143194 -0.862060 -0.087468 -0.143565 ... -0.759338 0.004852 -0.174958 0.297042 -0.976670 0.616724 0.008009 -0.042516 5.103041 -0.621323
2012-02-06 0.238109 -0.994863 -0.043994 -0.727007 -0.055139 -0.094519 -0.143372 -0.862235 -0.087646 -0.143743 ... -0.759514 0.004673 -0.175135 0.296863 -0.976845 0.616544 0.007831 -0.042694 5.102849 -0.621500
2012-02-07 0.237622 -0.994911 -0.044380 -0.727150 -0.055522 -0.094887 -0.143723 -0.862330 -0.088017 -0.144094 ... -0.759646 0.004270 -0.175475 0.296355 -0.976899 0.615922 0.007426 -0.043081 5.100628 -0.621680
2012-02-08 0.237194 -0.995264 -0.044792 -0.727520 -0.055932 -0.095295 -0.144128 -0.862692 -0.088425 -0.144499 ... -0.760013 0.003855 -0.175878 0.295923 -0.977253 0.615470 0.007012 -0.043492 5.099903 -0.622056
2012-02-09 0.237133 -0.995315 -0.044850 -0.727573 -0.055991 -0.095353 -0.144186 -0.862744 -0.088484 -0.144557 ... -0.760066 0.003796 -0.175936 0.295861 -0.977304 0.615406 0.006953 -0.043550 5.099801 -0.622110
2012-02-10 0.237011 -0.995410 -0.044966 -0.727674 -0.056106 -0.095468 -0.144299 -0.862842 -0.088598 -0.144670 ... -0.760166 0.003680 -0.176049 0.295739 -0.977400 0.615277 0.006836 -0.043666 5.099577 -0.622213
2012-02-13 0.237808 -0.991026 -0.043348 -0.724069 -0.054456 -0.093703 -0.142392 -0.858843 -0.086853 -0.142762 ... -0.756467 0.005156 -0.174049 0.296365 -0.973068 0.614972 0.008303 -0.042052 5.086220 -0.618916
2012-02-14 0.236598 -1.006774 -0.047885 -0.736659 -0.059124 -0.098835 -0.148101 -0.873027 -0.091905 -0.148475 ... -0.769440 0.001193 -0.180132 0.295847 -0.988604 0.618224 0.004378 -0.046573 5.142367 -0.630261
2012-02-15 0.237170 -1.006570 -0.047396 -0.736375 -0.058639 -0.098362 -0.147642 -0.872784 -0.091430 -0.148017 ... -0.769166 0.001696 -0.179683 0.296437 -0.988395 0.618910 0.004881 -0.046085 5.144396 -0.629946
2012-02-16 0.237138 -1.006607 -0.047430 -0.736411 -0.058672 -0.098396 -0.147676 -0.872820 -0.091463 -0.148051 ... -0.769202 0.001663 -0.179717 0.296405 -0.988431 0.618879 0.004848 -0.046118 5.144381 -0.629981
2012-02-17 0.237054 -1.006724 -0.047521 -0.736521 -0.058764 -0.098489 -0.147770 -0.872934 -0.091556 -0.148145 ... -0.769312 0.001573 -0.179812 0.296323 -0.988548 0.618805 0.004758 -0.046210 5.144427 -0.630088
2012-02-20 0.497486 -1.007413 -0.048541 -0.737303 -0.059780 -0.099491 -0.148755 -0.873669 -0.092560 -0.149130 ... -0.770083 0.000536 -0.180786 0.295185 -0.989243 0.617556 0.003721 -0.047229 5.141618 -0.630907
2012-02-21 0.492604 -1.003322 -0.050167 -0.734823 -0.061339 -0.100814 -0.149784 -0.870376 -0.093924 -0.150157 ... -0.767408 -0.001383 -0.181624 0.291508 -0.985261 0.611958 0.001782 -0.048864 5.109045 -0.629061
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2016-11-21 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-11-22 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-11-23 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-11-24 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-11-25 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-11-28 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-11-29 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-11-30 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-01 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-02 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-05 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-06 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-07 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-08 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-09 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-12 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-13 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-14 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-15 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-16 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-19 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-20 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-21 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-22 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-23 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-26 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-27 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-28 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-29 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160
2016-12-30 0.340788 0.146407 0.103897 0.148159 0.038965 -0.011702 -0.082949 0.025408 0.016802 -0.004202 ... -0.041196 -0.607518 0.061022 0.070768 0.020463 0.087341 0.021476 0.351489 0.053659 -0.558160

1214 rows × 1071 columns


In [43]:
orthorizedDF = orthoFactor(YOYBPSData,[PROFITOOPData],True, weight)

In [44]:
orthorizedDF.head()


Out[44]:
600507.SH 002344.SZ 000793.SZ 300039.SZ 600059.SH 600501.SH 000713.SZ 002233.SZ 600360.SH 600565.SH ... 600150.SH 600469.SH 600282.SH 600739.SH 600406.SH 600687.SH 600866.SH 000860.SZ 601908.SH 002195.SZ
LZ_GPA_FIN_IND_YOYBPS-d
2012-01-04 0.151757 -1.078286 -0.129363 -0.811546 -0.140540 -0.181008 -0.229801 -0.947120 -0.173590 -0.230349 ... -0.845153 -0.081833 -0.261602 0.213348 -1.219860 0.404714 -0.077751 -0.128960 5.016732 -0.706591
2012-01-05 0.149857 -1.079584 -0.131120 -0.812983 -0.142293 -0.182761 -0.231530 -0.948502 -0.175337 -0.232081 ... -0.846592 -0.083630 -0.263317 0.211466 -1.221122 0.402704 -0.079536 -0.130732 5.012645 -0.708084
2012-01-06 0.149248 -1.081257 -0.131969 -0.814429 -0.143152 -0.183666 -0.232478 -0.950072 -0.176231 -0.233031 ... -0.848079 -0.084448 -0.264294 0.210939 -1.222937 0.402323 -0.080341 -0.131589 5.016355 -0.709442
2012-01-09 0.148981 -1.082048 -0.132354 -0.815109 -0.143542 -0.184080 -0.232913 -0.950813 -0.176638 -0.233468 ... -0.848780 -0.084818 -0.264743 0.210715 -1.223800 0.402169 -0.080704 -0.131979 5.018230 -0.710079
2012-01-10 0.148740 -1.082282 -0.132592 -0.815346 -0.143780 -0.184321 -0.233154 -0.951051 -0.176878 -0.233709 ... -0.849020 -0.085060 -0.264984 0.210482 -1.224038 0.401929 -0.080943 -0.132219 5.017994 -0.710317

5 rows × 1071 columns


In [45]:
correlationDF1 = ff.showCorrelation(orthorizedDF ,PROFITOOPData, orthorizedDF.index, filterdic = None).astype(float)
correlationDF1.describe()


Out[45]:
Pearson Spearman
count 1214.000000 1214.000000
mean 0.003473 0.221383
std 0.080167 0.229138
min -0.198467 -0.388118
25% -0.007971 0.178505
50% 0.005107 0.223134
75% 0.022895 0.327686
max 0.135320 0.587530

In [46]:
correlationDF = ff.showCorrelation(YOYBPSData ,PROFITOOPData, orthorizedDF.index, filterdic = None).astype(float)
correlationDF.describe()


Out[46]:
Pearson Spearman
count 1214.000000 1214.000000
mean 0.095275 0.363892
std 0.061983 0.155586
min 0.008090 0.145976
25% 0.051428 0.261719
50% 0.084243 0.284862
75% 0.128098 0.560356
max 0.284805 0.634266

In [47]:
orthoFactor(PBData,[LFCAPData,YOYBPSData]).head()


Out[47]:
600507.SH 002344.SZ 000793.SZ 300039.SZ 600059.SH 600501.SH 000713.SZ 002233.SZ 600360.SH 600565.SH ... 600150.SH 600469.SH 600282.SH 600739.SH 600406.SH 600687.SH 600866.SH 000860.SZ 601908.SH 002195.SZ
LZ_GPA_VAL_PB-d
2012-01-04 -0.071250 0.053166 -0.035383 0.000753 -0.037675 -0.052847 -0.014652 -0.054814 -0.088625 -0.075696 ... -0.076637 -0.096018 -0.103514 -0.073245 0.360620 0.075080 -0.083320 -0.066678 -0.066159 0.039261
2012-01-05 -0.377263 0.817910 -0.019514 0.336389 -0.093000 -0.182212 0.080297 -0.260826 -0.537475 -0.373930 ... -0.525790 -0.599379 -0.700208 -0.452856 3.866487 1.164736 -0.499238 -0.372012 -0.310752 0.661021
2012-01-06 -0.370344 0.807951 -0.033858 0.331630 -0.083475 -0.174873 -0.008016 -0.224641 -0.529716 -0.342368 ... -0.519258 -0.584974 -0.695577 -0.428696 3.870769 1.150617 -0.514991 -0.372073 -0.306836 0.694119
2012-01-09 -0.071479 0.059052 -0.032903 0.007236 -0.038524 -0.052797 -0.032796 -0.053024 -0.091473 -0.072893 ... -0.081841 -0.098388 -0.108975 -0.073139 0.398672 0.086776 -0.089531 -0.069367 -0.069264 0.036300
2012-01-10 -0.384463 0.819567 -0.052424 0.333428 -0.084771 -0.174435 0.052174 -0.184946 -0.544890 -0.386419 ... -0.523893 -0.608049 -0.721006 -0.443349 3.792828 1.014716 -0.510021 -0.364589 -0.295955 0.685328

5 rows × 1071 columns


In [48]:
# calc active return
returnDF = PriceDF.pct_change()[1:] 
returnOfBench = benchmarkData.pct_change()[1:]

activeReturnDF = returnDF .apply(lambda x: x - returnOfBench )
activeReturnDF.head().iloc[:,2].values


Out[48]:
array([ 0.04409056, -0.01318288, -0.01008094, -0.01510446, -0.00549635])

In [49]:
factorReturn = pd.DataFrame(index = returnDF.index, columns = ['LFCA', 'PB', 'YOYBPS', 'AMOUNTAVG1MData', 'TURNOVER1M' ,\
                                                              'PROFITOOP'],data= None ,dtype =float)
factorPvalue =  pd.DataFrame(index = returnDF.index, columns = ['LFCA', 'PB', 'YOYBPS', 'AMOUNTAVG1MData', 'TURNOVER1M' ,\
                                                              'PROFITOOP'],data= None ,dtype =float)

specificReturn = pd.DataFrame(index = returnDF.index, columns = LFCAPData.columns ,dtype =float )

In [50]:
# construct the multiple factor structural risk model
def multiFactorReg(returndf,factorDict,WLS =False, weightdf = None):
    '''
    Multi variable regression for return.
    returndf and dataframes in factorDict should have same index and same columns.
    output: 4 Dataframe, respectively idiosyncratic return for each stock, factor Return, factor P-value and
    R-Square of the linear regression model.
    input: 
    returndf: Dataframe, can either be return or acticve return.
    factorDict: Dictionary, the keys are the names of factors and the values are the corresponding factor dataframe(all\
    with same columns and index).
    WLS: True to use WLS , False to use OLS. If True, then weightdf should not be none.
    weightdf: Dataframe , which has no nan and the shape is same as dataframes in factorDict.
    '''
    specificReturn = pd.DataFrame(index = returndf.index, columns =returndf.columns , data= None, dtype =float)
    factorReturn = pd.DataFrame(index = returndf.index, columns =factorDict.keys(), data= None, dtype =float )
    factorPvalue = pd.DataFrame(index = returndf.index, columns =factorDict.keys(), data= None, dtype =float )
    RSquare = pd.DataFrame(index = returndf.index, columns =['R-Square'], data= None, dtype =float )
    dfNum = len(factorDict.keys())
    if dfNum == 0:
        print 'Input is an empty list!'
        raise ValueError
    for date in returndf.index:
        returndfSlice = returndf.loc[date]
        mapfunction = map(lambda x: x.loc[date], factorDict.values())
        if dfNum > 1:
            totaldf = pd.concat(mapfunction, axis=1)         
        else:
            totaldf = factorDict.values()[0].loc[date]
        if WLS:
            w = weightdf.loc[date]
            result = sm.WLS(returndfSlice.T,totaldf,weights = 1/w ).fit()
        else:
            result = sm.OLS(returndfSlice.T,totaldf ).fit()
        specificReturn .loc[date] = result.resid
        factorReturn .loc[date] = result.params.values
        factorPvalue . loc[date] = result.pvalues.values
        RSquare .loc[date] = result.rsquared
    return specificReturn, factorReturn, factorPvalue, RSquare

In [51]:
factordic = {'LFCA':LFCAPData, 'PB':PBData, 'YOYBPS':YOYBPSData, 'AMOUNTAVG1MData':AMOUNTAVG1MData, 'TURNOVER1M' :TURNOVER1MData,\
                                                              'PROFITOOP':PROFITOOPData}

In [ ]:


In [52]:
help(multiFactorReg)


Help on function multiFactorReg in module __main__:

multiFactorReg(returndf, factorDict, WLS=False, weightdf=None)
    Multi variable regression for return.
    returndf and dataframes in factorDict should have same index and same columns.
    output: 4 Dataframe, respectively idiosyncratic return for each stock, factor Return, factor P-value and
    R-Square of the linear regression model.
    input: 
    returndf: Dataframe, can either be return or acticve return.
    factorDict: Dictionary, the keys are the names of factors and the values are the corresponding factor dataframe(all    with same columns and index).
    WLS: True to use WLS , False to use OLS. If True, then weightdf should not be none.
    weightdf: Dataframe , which has no nan and the shape is same as dataframes in factorDict.


In [53]:
# set weight for WLS
weightdf = pd.read_csv(path+filenameFCAP,infer_datetime_format=True,parse_dates=[0],index_col=0).loc[startTime:endTime]
weightdf = fillData(weightdf,stkPool)
# the square root is the weight
weight = np.sqrt(weightdf)

In [54]:
weightdf[stkPool].isnull().sum().sum()


Out[54]:
0

In [55]:
weightdf


Out[55]:
600507.SH 002344.SZ 000793.SZ 300039.SZ 600059.SH 600501.SH 000713.SZ 002233.SZ 600360.SH 600565.SH ... 600150.SH 600469.SH 600282.SH 600739.SH 600406.SH 600687.SH 600866.SH 000860.SZ 601908.SH 002195.SZ
LZ_GPA_VAL_A_FCAP-d
2012-01-04 5.059064e+05 3.296545e+05 7.585292e+05 275650.5960 608818.6904 159668.3269 403180.4931 408744.0281 265129.28 2.203200e+05 ... 2.717012e+06 281206.6110 4.582656e+05 1.662217e+06 3.366400e+06 1.795473e+05 296507.3390 5.959299e+05 1.255200e+05 1.430554e+05
2012-01-05 5.007042e+05 3.149170e+05 7.639667e+05 266325.1032 578619.3506 150797.8643 362832.5565 379710.0461 254958.08 2.203200e+05 ... 2.647046e+06 277082.2474 4.498416e+05 1.652664e+06 3.340141e+06 1.795473e+05 281395.3657 5.656730e+05 1.152600e+05 1.320444e+05
2012-01-06 5.072069e+05 3.149170e+05 7.571698e+05 266736.5220 586471.1789 152654.4727 337727.1737 396948.9729 259026.56 2.304000e+05 ... 2.676728e+06 285330.9746 4.548960e+05 1.718170e+06 3.363249e+06 1.795473e+05 275142.1353 5.674270e+05 1.170000e+05 1.352156e+05
2012-01-09 5.267148e+05 3.254660e+05 7.802791e+05 279627.6444 608818.6904 159874.6167 348486.6234 422807.3631 270553.92 2.347200e+05 ... 2.785918e+06 293579.7019 4.683744e+05 1.794593e+06 3.392659e+06 1.795473e+05 287648.5960 6.016305e+05 1.231800e+05 1.352156e+05
2012-01-10 5.449223e+05 3.369457e+05 8.006697e+05 286210.3452 631770.1886 166682.1810 383454.8352 450026.7212 282081.28 2.397600e+05 ... 2.894047e+06 307452.5614 4.885920e+05 1.828711e+06 3.465134e+06 1.795473e+05 308492.6972 6.261869e+05 1.300800e+05 1.437601e+05
2012-01-11 5.696324e+05 3.425305e+05 7.965916e+05 281136.1800 624522.3471 167301.0505 390627.8017 440499.9459 280725.12 2.368800e+05 ... 2.860124e+06 309327.2721 4.902768e+05 1.809605e+06 3.496645e+06 1.795473e+05 304844.9795 6.209248e+05 1.288800e+05 1.581185e+05
2012-01-12 5.631297e+05 3.395830e+05 7.925135e+05 276336.2940 622106.3999 168332.4996 383155.9616 443221.8817 280725.12 2.361600e+05 ... 2.862244e+06 304078.0820 4.869072e+05 1.801417e+06 3.446227e+06 1.795473e+05 303802.7744 6.165397e+05 1.321200e+05 1.552997e+05
2012-01-13 5.384196e+05 3.347739e+05 7.666854e+05 254393.9580 602174.8356 161112.3557 376879.6159 424168.3310 267841.60 2.282400e+05 ... 2.788038e+06 289830.2804 4.734288e+05 1.761840e+06 3.334889e+06 1.795473e+05 287127.4935 5.867213e+05 1.314000e+05 1.447291e+05
2012-01-16 5.332175e+05 3.164684e+05 7.503730e+05 245617.0236 578015.3638 154511.0812 371499.8910 410558.6519 261738.88 2.217600e+05 ... 2.736093e+06 283081.3217 4.683744e+05 1.755017e+06 3.004026e+06 1.795473e+05 274621.0328 5.757587e+05 1.245600e+05 1.389153e+05
2012-01-17 5.332175e+05 3.327572e+05 7.829979e+05 254393.9580 611838.6243 162143.8048 392122.1698 445036.5056 276656.64 2.325600e+05 ... 2.896167e+06 300703.6027 4.953312e+05 1.865558e+06 3.069149e+06 1.795473e+05 290775.2112 6.055771e+05 1.319400e+05 1.497502e+05
2012-01-18 5.332175e+05 3.291891e+05 7.748417e+05 231080.2260 594323.0073 164825.5726 379868.3520 448665.7533 272588.16 2.304000e+05 ... 2.866485e+06 299953.7184 4.852224e+05 1.823252e+06 2.852775e+06 1.795473e+05 282958.6732 5.915449e+05 1.267800e+05 1.436721e+05
2012-01-19 5.722334e+05 3.294994e+05 7.626073e+05 235605.8328 602778.8224 165857.0217 378672.8575 451387.6892 277334.72 2.332800e+05 ... 2.908888e+06 305952.7928 4.919616e+05 1.869652e+06 3.036587e+06 1.795473e+05 284521.9808 5.989995e+05 1.312200e+05 1.442887e+05
2012-01-20 5.696324e+05 3.316713e+05 7.734823e+05 242051.3940 620898.4263 167507.3403 394214.2850 462729.0884 281403.20 2.361600e+05 ... 3.018078e+06 308577.3878 4.970160e+05 1.907864e+06 3.089105e+06 1.795473e+05 291817.4162 6.117162e+05 1.319400e+05 1.444649e+05
2012-01-30 5.709329e+05 3.254660e+05 7.734823e+05 239720.0208 623314.3735 167094.7607 390328.9281 445943.8175 280725.12 2.332800e+05 ... 2.936451e+06 301078.5448 4.919616e+05 1.890123e+06 3.071249e+06 1.795473e+05 288690.8011 6.213633e+05 1.308000e+05 1.439363e+05
2012-01-31 5.683318e+05 3.201915e+05 7.897947e+05 232588.7616 621502.4131 169363.9488 389432.3073 445943.8175 281403.20 2.361600e+05 ... 2.991575e+06 305202.9085 4.835376e+05 1.887394e+06 3.044990e+06 1.795473e+05 286606.3910 6.275024e+05 1.251000e+05 1.436721e+05
2012-02-01 5.579276e+05 3.201915e+05 7.816385e+05 233548.7388 610026.6640 166063.3115 390030.0545 430519.5146 282759.36 2.376000e+05 ... 2.918429e+06 306327.7349 4.801680e+05 1.857370e+06 3.030285e+06 1.795473e+05 286606.3910 6.226788e+05 1.227600e+05 1.426150e+05
2012-02-02 5.644302e+05 3.243801e+05 7.952322e+05 246714.1404 615462.5451 168951.3691 394214.2850 441407.2578 288862.08 2.419200e+05 ... 2.960833e+06 311576.9250 4.869072e+05 1.881935e+06 3.050242e+06 1.795473e+05 292338.5188 6.345185e+05 1.253400e+05 1.462266e+05
2012-02-03 5.696324e+05 3.318264e+05 7.938729e+05 248908.3740 622106.3999 171220.5572 393915.4114 441407.2578 300389.44 2.433600e+05 ... 3.011717e+06 315326.3465 4.902768e+05 1.880570e+06 3.203595e+06 1.795473e+05 310056.0048 6.314489e+05 1.287600e+05 1.495740e+05
2012-02-06 5.709329e+05 3.366355e+05 7.897947e+05 258508.1460 624522.3471 171014.2674 399295.1363 451387.6892 298355.20 2.419200e+05 ... 3.000056e+06 314576.4622 4.885920e+05 1.895582e+06 3.307580e+06 1.795473e+05 309013.7997 6.336415e+05 1.341000e+05 1.500144e+05
2012-02-07 5.657308e+05 3.304302e+05 7.843573e+05 252336.8640 608214.7036 167713.6302 392421.0434 437324.3541 289540.16 2.397600e+05 ... 2.925850e+06 308202.4457 4.835376e+05 1.815064e+06 3.271868e+06 1.795473e+05 299112.8516 6.187323e+05 1.314600e+05 1.461385e+05
2012-02-08 5.735339e+05 3.355495e+05 7.938729e+05 257685.3084 626334.3075 172458.2962 397203.0210 454109.6250 299711.36 2.448000e+05 ... 2.990515e+06 320575.5365 4.936464e+05 1.877841e+06 3.356947e+06 1.795473e+05 309534.9022 6.318874e+05 1.364400e+05 1.478382e+05
2012-02-09 5.865392e+05 3.366355e+05 7.965916e+05 256313.9124 637206.0698 172045.7166 396904.1474 457285.2168 303101.76 2.484000e+05 ... 3.001116e+06 318325.8837 4.953312e+05 1.865558e+06 3.383206e+06 1.795473e+05 318914.7477 6.362725e+05 1.357800e+05 1.504394e+05
2012-02-10 5.904408e+05 3.392727e+05 7.979510e+05 253708.2600 634790.1226 173077.1657 403180.4931 460914.4645 303101.76 2.498400e+05 ... 2.991575e+06 319075.7679 5.003856e+05 1.881935e+06 3.368501e+06 1.795473e+05 316830.3376 6.503047e+05 1.375800e+05 1.503527e+05
2012-02-13 5.930419e+05 3.395830e+05 8.020291e+05 267010.8012 647473.8453 174933.7741 399295.1363 455470.5929 315307.20 2.498400e+05 ... 2.989455e+06 322075.3051 4.987008e+05 1.886029e+06 3.374803e+06 1.795473e+05 322562.4655 6.533743e+05 1.372800e+05 1.521736e+05
2012-02-14 5.904408e+05 3.420651e+05 8.020291e+05 275787.7356 645661.8849 176584.0928 396306.4002 461821.7764 311238.72 2.534400e+05 ... 3.014897e+06 327699.4374 4.936464e+05 1.872382e+06 3.348544e+06 1.795473e+05 320478.0553 6.529357e+05 1.354800e+05 1.515666e+05
2012-02-15 5.982440e+05 3.459434e+05 8.197009e+05 279627.6444 646265.8717 180503.5995 397800.7683 466811.9921 322766.08 2.548800e+05 ... 3.074262e+06 329949.0902 5.054400e+05 1.940617e+06 3.329638e+06 1.795473e+05 335068.9261 6.581978e+05 1.386600e+05 1.538211e+05
2012-02-16 6.099488e+05 3.473395e+05 8.237790e+05 279079.0860 646265.8717 179678.4402 402881.6195 462729.0884 320053.76 2.592000e+05 ... 3.038219e+06 333698.5117 5.020704e+05 1.918782e+06 3.304429e+06 1.795473e+05 331942.3110 6.498662e+05 1.422000e+05 1.533875e+05
2012-02-17 6.047467e+05 3.459434e+05 8.156228e+05 274279.2000 640226.0038 182360.2080 396007.5266 456831.5608 314629.12 2.599200e+05 ... 3.052000e+06 331823.8010 5.003856e+05 1.948806e+06 3.313882e+06 1.795473e+05 326210.1832 6.437271e+05 1.437000e+05 1.499192e+05
2012-02-20 6.047467e+05 3.428407e+05 8.101853e+05 263993.7300 645661.8849 181328.7588 395110.9058 458646.1847 312594.88 2.556000e+05 ... 3.053061e+06 328824.2638 4.987008e+05 1.921511e+06 3.419968e+06 1.795473e+05 325689.0806 6.467967e+05 1.418400e+05 1.501793e+05
2012-02-21 6.008451e+05 3.437715e+05 8.224197e+05 266873.6616 674049.2643 182153.9181 396306.4002 462275.4324 316663.36 2.599200e+05 ... 3.060481e+06 329574.1481 5.020704e+05 1.950170e+06 3.460932e+06 1.795473e+05 328815.6958 6.647754e+05 1.429200e+05 1.543413e+05
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2016-11-21 8.566561e+05 1.414394e+06 2.090657e+06 694497.9562 827120.2208 746224.5224 362826.4865 789212.0183 755793.92 1.054097e+06 ... 3.253736e+06 606281.4533 1.050329e+06 2.665278e+06 3.504942e+06 1.770962e+06 395732.9013 1.165971e+06 1.334363e+06 1.052462e+06
2016-11-22 8.712431e+05 1.418818e+06 2.081520e+06 702509.0240 828737.2691 751514.0092 367010.6469 777840.0872 752841.60 1.058514e+06 ... 3.312995e+06 612467.9988 1.104589e+06 2.824949e+06 3.485091e+06 1.770962e+06 398484.8687 1.172164e+06 1.415182e+06 1.034429e+06
2016-11-23 8.712431e+05 1.372371e+06 2.057762e+06 693881.7202 827928.7450 761686.0992 361929.8807 771016.9286 752103.52 1.048208e+06 ... 3.288189e+06 605156.6269 1.123968e+06 2.792196e+06 3.476268e+06 1.770962e+06 392430.5405 1.178920e+06 1.380791e+06 1.025412e+06
2016-11-24 8.738953e+05 1.384536e+06 2.054107e+06 687719.3604 844907.7524 761686.0992 357147.9830 771016.9286 766127.04 1.045264e+06 ... 3.228930e+06 596158.0153 1.147223e+06 2.984620e+06 3.394655e+06 1.770962e+06 384725.0320 1.190743e+06 1.339522e+06 9.827893e+05
2016-11-25 9.096998e+05 1.369054e+06 2.063245e+06 688951.8323 836822.5108 758024.1468 354159.2969 763435.6412 751365.44 1.037903e+06 ... 3.263382e+06 602906.9740 1.154974e+06 2.953232e+06 3.394655e+06 1.770962e+06 380872.2778 1.183424e+06 1.330924e+06 1.065481e+06
2016-11-28 9.030693e+05 1.348043e+06 2.092485e+06 695114.1922 838439.5591 748258.9404 355354.7713 771775.0573 738080.00 1.076180e+06 ... 3.290945e+06 600094.9079 1.162726e+06 2.940950e+06 3.436564e+06 1.770962e+06 377569.9170 1.182861e+06 1.554554e+06 1.054052e+06
2016-11-29 9.256129e+05 1.352466e+06 2.035832e+06 688951.8323 842482.1799 777961.4432 349676.2679 747514.9376 718889.92 1.061458e+06 ... 3.376388e+06 579848.0319 1.127844e+06 2.900008e+06 3.423330e+06 1.770962e+06 372616.3758 1.192432e+06 1.516686e+06 1.039987e+06
2016-11-30 9.110259e+05 1.306020e+06 2.048625e+06 710520.0919 838439.5591 772265.0728 349676.2679 734626.7491 723318.40 1.043792e+06 ... 3.285432e+06 580972.8583 1.112341e+06 2.921844e+06 3.410095e+06 1.770962e+06 371515.5889 1.167660e+06 1.486791e+06 1.069876e+06
2016-12-01 9.295912e+05 1.315973e+06 2.034005e+06 708671.3839 836822.5108 773078.8400 352067.2167 743724.2939 727008.80 1.039375e+06 ... 3.388791e+06 596720.4285 1.131720e+06 2.920479e+06 3.414507e+06 1.770962e+06 375368.3431 1.164845e+06 1.498749e+06 1.068997e+06
2016-12-02 8.858301e+05 1.289432e+06 2.035832e+06 687719.3604 814183.8342 748665.8240 345790.9760 731594.2341 710032.96 1.037903e+06 ... 3.497662e+06 602906.9740 1.108465e+06 2.924573e+06 3.440976e+06 1.770962e+06 366562.0477 1.144014e+06 1.462875e+06 1.047019e+06
2016-12-05 8.845040e+05 1.246304e+06 2.019385e+06 672929.6967 817417.9308 748258.9404 345193.2388 728561.7191 704866.40 1.034958e+06 ... 3.763639e+06 606281.4533 1.096838e+06 2.632525e+06 3.491708e+06 1.770962e+06 367112.4412 1.146829e+06 1.454903e+06 1.057569e+06
2016-12-06 8.791996e+05 1.246304e+06 2.002937e+06 670464.7528 810949.7375 734018.0144 347883.0562 740691.7790 719628.00 1.027597e+06 ... 3.703002e+06 611343.1723 1.100714e+06 2.605231e+06 3.546852e+06 1.770962e+06 372065.9823 1.146266e+06 1.458889e+06 1.070755e+06
2016-12-07 9.295912e+05 1.287220e+06 1.991972e+06 679708.2926 816609.4067 736459.3160 352366.0853 764193.7699 719628.00 1.030542e+06 ... 3.806361e+06 612467.9988 1.135595e+06 2.617513e+06 3.562292e+06 1.770962e+06 378120.3105 1.155837e+06 1.472840e+06 1.080426e+06
2016-12-08 9.309173e+05 1.276162e+06 2.043142e+06 670464.7528 818226.4550 720997.7392 350572.8737 749789.3239 718151.84 1.052625e+06 ... 3.744346e+06 622591.4368 1.120092e+06 2.591584e+06 3.502737e+06 1.770962e+06 373717.1627 1.164845e+06 1.456896e+06 1.073393e+06
2016-12-09 9.136781e+05 1.277268e+06 2.035832e+06 666767.3369 819034.9791 721811.5064 349377.3992 734626.7491 711509.12 1.054097e+06 ... 3.850461e+06 624841.0896 1.131720e+06 2.603866e+06 3.489502e+06 1.770962e+06 374267.5562 1.170475e+06 1.432980e+06 1.073393e+06
2016-12-12 8.884823e+05 1.210916e+06 1.966387e+06 626095.7618 776991.7226 696584.7232 328456.5969 686864.6384 660581.60 1.027597e+06 ... 3.726430e+06 595033.1889 1.092962e+06 2.431913e+06 3.476268e+06 1.770962e+06 355554.1784 1.141762e+06 1.363224e+06 1.000427e+06
2016-12-13 9.401999e+05 1.216445e+06 1.966387e+06 630409.4137 790736.6334 712046.3000 334732.8376 712641.0156 656153.12 1.027597e+06 ... 4.002054e+06 594470.7757 1.108465e+06 2.457842e+06 3.385832e+06 1.770962e+06 357755.7523 1.176668e+06 1.351266e+06 1.006580e+06
2016-12-14 9.150042e+05 1.206493e+06 1.948112e+06 627328.2337 787502.5367 731576.7128 325169.0422 700510.9558 653200.80 1.006987e+06 ... 3.902829e+06 630465.2219 1.085211e+06 2.422360e+06 3.608613e+06 1.770962e+06 361058.1130 1.176105e+06 1.351266e+06 9.916355e+05
2016-12-15 1.006505e+06 1.251833e+06 1.973697e+06 631025.6497 789119.5850 740528.1520 329353.2027 702027.2132 670176.64 1.057041e+06 ... 3.875267e+06 636651.7673 1.104589e+06 2.420995e+06 3.635082e+06 1.770962e+06 368763.6216 1.186802e+06 1.359238e+06 1.005701e+06
2016-12-16 1.063527e+06 1.263997e+06 2.081520e+06 637804.2455 801247.4475 749479.5912 346687.5818 711124.7581 671652.80 1.087958e+06 ... 3.696111e+06 630465.2219 1.100714e+06 2.479678e+06 3.588761e+06 1.770962e+06 374817.9497 1.181735e+06 1.375182e+06 1.031195e+06
2016-12-19 1.029048e+06 1.244092e+06 2.134517e+06 630409.4137 799630.3992 752734.6600 351170.6109 712641.0156 659843.52 1.087958e+06 ... 3.753992e+06 640026.2466 1.123968e+06 2.464666e+06 3.604201e+06 1.770962e+06 375918.7366 1.197499e+06 1.375182e+06 1.018009e+06
2016-12-20 9.799827e+05 1.254045e+06 2.130862e+06 632874.3576 791545.1575 743783.2208 342802.2899 698994.6983 674605.12 1.074708e+06 ... 3.722296e+06 623716.2632 1.120092e+06 2.445560e+06 3.509354e+06 1.770962e+06 379221.0974 1.190743e+06 1.365217e+06 1.024163e+06
2016-12-21 9.786566e+05 1.260680e+06 2.123552e+06 637188.0095 798013.3509 760058.5648 347584.1876 700510.9558 677557.44 1.074708e+06 ... 3.989650e+06 668709.3210 1.139471e+06 2.471489e+06 3.555675e+06 1.770962e+06 379771.4909 1.195247e+06 1.363224e+06 1.028558e+06
2016-12-22 9.760044e+05 1.256256e+06 2.105277e+06 634106.8296 800438.9234 745003.8716 343698.8958 739933.6502 666486.24 1.098263e+06 ... 4.087497e+06 674895.8664 1.193732e+06 2.468760e+06 3.676991e+06 1.770962e+06 379221.0974 1.181735e+06 1.361231e+06 1.008339e+06
2016-12-23 9.348956e+05 1.221975e+06 2.158275e+06 626711.9978 810141.2133 740121.2684 334433.9690 719464.1743 665010.08 1.101208e+06 ... 4.104034e+06 658585.8830 1.193732e+06 2.437372e+06 3.716695e+06 1.770962e+06 373717.1627 1.162030e+06 1.349273e+06 9.969102e+05
2016-12-26 9.163303e+05 1.238563e+06 2.143655e+06 632874.3576 822269.0758 746631.4060 338319.2609 727803.5904 664272.00 1.099735e+06 ... 4.130218e+06 661960.3623 1.166601e+06 2.440101e+06 3.690226e+06 1.770962e+06 378670.7039 1.158652e+06 1.363224e+06 1.018888e+06
2016-12-27 9.136781e+05 1.238563e+06 2.149137e+06 632874.3576 828737.2691 748665.8240 342503.4213 730836.1054 669438.56 1.129179e+06 ... 4.051666e+06 661960.3623 1.158850e+06 2.429183e+06 3.701255e+06 1.770962e+06 384174.6386 1.169349e+06 1.353259e+06 1.011855e+06
2016-12-28 9.004171e+05 1.238563e+06 2.097967e+06 627328.2337 823077.6000 752734.6600 342802.2899 720980.4317 671652.80 1.114457e+06 ... 4.044775e+06 683332.0647 1.154974e+06 2.405983e+06 3.668168e+06 1.770962e+06 390228.9667 1.176105e+06 1.355252e+06 1.008339e+06
2016-12-29 9.070476e+05 1.269527e+06 2.107105e+06 634723.0656 827120.2208 754362.1944 345193.2388 731594.2341 661319.68 1.089430e+06 ... 3.948307e+06 673208.6267 1.201483e+06 2.467395e+06 3.668168e+06 1.770962e+06 385275.4255 1.175542e+06 1.383154e+06 1.010976e+06
2016-12-30 8.977650e+05 1.251833e+06 2.063245e+06 630409.4137 827928.7450 742155.6864 348181.9248 708850.3719 653938.88 1.092374e+06 ... 3.804983e+06 669271.7342 1.201483e+06 2.451019e+06 3.668168e+06 1.770962e+06 389678.5732 1.238598e+06 1.419029e+06 9.951520e+05

1214 rows × 1071 columns


In [56]:
weight


Out[56]:
600507.SH 002344.SZ 000793.SZ 300039.SZ 600059.SH 600501.SH 000713.SZ 002233.SZ 600360.SH 600565.SH ... 600150.SH 600469.SH 600282.SH 600739.SH 600406.SH 600687.SH 600866.SH 000860.SZ 601908.SH 002195.SZ
LZ_GPA_VAL_A_FCAP-d
2012-01-04 711.270946 574.155505 870.935818 525.024377 780.268345 399.585194 634.964954 639.330922 514.907060 469.382573 ... 1648.336085 530.289177 676.953174 1289.269776 1834.775229 423.730240 544.524875 771.964985 354.288018 378.226706
2012-01-05 707.604577 561.174702 874.051878 516.066956 760.670330 388.327007 602.355839 616.206172 504.933738 469.382573 ... 1626.974455 526.386025 670.702318 1285.559640 1827.605310 423.730240 530.467120 752.112365 339.499632 363.379142
2012-01-06 712.184589 561.174702 870.155060 516.465412 765.814063 390.710216 581.142989 630.038866 508.946520 480.000000 ... 1636.071029 534.163809 674.459784 1310.789708 1833.916319 423.730240 524.539927 753.277528 342.052628 367.716712
2012-01-09 725.751229 570.496268 883.334105 528.798302 780.268345 399.843240 590.327556 650.236390 520.147979 484.479102 ... 1669.106866 541.829957 684.378842 1339.624353 1841.917238 423.730240 536.328813 775.648450 350.970084 367.716712
2012-01-10 738.188508 580.470263 894.801493 534.986304 794.839725 408.267291 619.237301 670.840310 531.113246 489.652938 ... 1701.189865 554.484050 698.993562 1352.298471 1861.487006 423.730240 555.421189 791.319699 360.666051 379.157155
2012-01-11 754.739924 585.261021 892.519802 530.222765 790.267263 409.024511 625.002241 663.701699 529.834993 486.703195 ... 1691.190132 556.171981 700.197686 1345.215676 1869.931720 423.730240 552.127684 787.987812 358.998607 397.641227
2012-01-12 750.419683 582.737473 890.232264 525.676986 788.737219 410.283438 618.995930 665.749113 529.834993 485.962962 ... 1691.816846 551.432754 697.787360 1342.168751 1856.401738 423.730240 551.183068 785.200439 363.483150 394.080853
2012-01-13 733.770823 578.596478 875.605749 504.374819 775.999250 401.388036 613.905217 651.282067 517.534153 477.744702 ... 1669.741869 538.358877 688.061625 1327.343351 1826.167948 423.730240 535.842788 765.977354 362.491379 380.432806
2012-01-16 730.217433 562.555208 866.240713 495.597643 760.273217 393.078976 609.507909 640.748509 511.604222 470.914005 ... 1654.114106 532.053871 684.378842 1324.770480 1733.212720 423.730240 524.042968 758.787620 352.930588 372.713416
2012-01-17 730.217433 576.851085 884.871676 504.374819 782.201141 402.670839 626.196590 667.110565 525.981597 482.244751 ... 1701.812897 548.364480 703.797698 1365.854428 1751.898565 423.730240 539.235766 778.188328 363.235461 386.975651
2012-01-18 730.217433 573.750075 880.250905 480.708047 770.923477 405.987158 616.334610 669.825166 522.099761 480.000000 ... 1693.069580 547.680307 696.579069 1350.278606 1689.015885 423.730240 531.938599 769.119546 356.061792 379.040974
2012-01-19 756.461112 574.020394 873.273905 485.392452 776.388319 407.255475 615.364004 671.853920 526.625787 482.990683 ... 1705.546312 553.129996 701.399743 1367.352350 1742.580689 423.730240 533.406019 773.950568 362.243012 379.853495
2012-01-20 754.739924 575.909067 879.478416 491.987189 787.971082 409.276606 627.864862 680.241934 530.474505 485.962962 ... 1737.261506 555.497424 704.993617 1381.254619 1757.585105 423.730240 540.201274 782.122856 363.235461 380.085325
2012-01-30 755.601008 570.496268 879.478416 489.612113 789.502611 408.772260 624.763098 667.790250 529.834993 482.990683 ... 1713.607474 548.706246 701.399743 1374.817477 1752.498017 423.730240 537.299545 788.266007 361.662826 379.389410
2012-01-31 753.877856 565.854680 888.703967 482.274571 788.354243 411.538514 624.045116 667.790250 530.474505 485.962962 ... 1729.617090 552.451725 695.368679 1373.824470 1744.990066 423.730240 535.356322 792.150481 353.694784 379.040974
2012-02-01 746.945499 565.854680 884.103225 483.268806 781.042037 407.508664 624.523862 656.139859 531.751220 487.442304 ... 1708.341019 553.468820 692.941556 1362.853646 1740.771468 423.730240 535.356322 789.100004 350.371232 377.644012
2012-02-02 751.285718 569.543739 891.757941 496.703272 784.514210 411.036944 627.864862 664.384872 537.458910 491.853637 ... 1720.707022 558.190760 697.787360 1371.836301 1746.494238 423.730240 540.683381 796.566685 354.033897 382.395896
2012-02-03 754.739924 576.043736 890.995429 498.907180 788.737219 413.788058 627.626809 664.384872 548.077951 493.315315 ... 1735.429917 561.539265 700.197686 1371.338808 1789.858798 423.730240 556.826728 794.637616 358.831437 386.747951
2012-02-06 755.601008 580.202950 888.703967 508.436964 790.267263 413.538713 631.898043 671.853920 546.219004 491.853637 ... 1732.066974 560.871164 698.993562 1376.801342 1818.675354 423.730240 555.890097 796.016000 366.196668 387.316949
2012-02-07 752.150757 574.830585 885.639461 502.331428 779.881211 409.528546 626.435187 661.305039 538.089361 489.652938 ... 1710.511523 555.159838 695.368679 1347.243131 1808.830518 423.730240 546.912106 786.595360 362.574130 382.280699
2012-02-08 757.320239 579.266383 890.995429 507.627135 791.412855 415.280985 630.240447 673.876565 547.459003 494.772675 ... 1729.310611 566.193904 702.599744 1370.343281 1832.197290 423.730240 556.358609 794.913484 369.377855 384.497282
2012-02-09 765.858504 580.202950 892.519802 506.274543 798.251884 414.783940 630.003292 676.228672 550.546783 498.397432 ... 1732.372966 564.203761 703.797698 1365.854428 1839.349309 423.730240 564.725374 797.666916 368.483378 387.865205
2012-02-10 768.401484 582.471201 893.281013 503.694610 796.737173 416.025439 634.964954 678.906816 550.546783 499.839974 ... 1729.617090 564.867921 707.379389 1371.836301 1835.347612 423.730240 562.876841 806.414725 370.917781 387.753412
2012-02-13 770.092138 582.737473 895.560764 516.730879 804.657595 418.250851 631.898043 674.885615 561.522217 499.839974 ... 1729.004077 567.516788 706.187511 1373.327698 1837.063693 423.730240 567.945830 808.315688 370.513158 390.094334
2012-02-14 768.401484 584.863290 895.560764 525.154963 803.530886 420.219101 629.528713 679.574703 557.887731 503.428247 ... 1736.345953 572.450380 702.599744 1368.350053 1829.902740 423.730240 566.107812 808.044396 368.076079 389.315591
2012-02-15 773.462360 588.169496 905.373354 528.798302 803.906631 424.857152 630.714490 683.236410 568.125057 504.856415 ... 1753.357446 574.411952 710.943036 1393.060429 1824.729454 423.730240 578.851385 811.293917 372.370783 392.200271
2012-02-16 780.992188 589.355190 907.622732 528.279364 803.906631 423.884937 634.729564 680.241934 565.732941 509.116882 ... 1743.048840 577.666436 708.569263 1385.201069 1817.808837 423.730240 576.144349 806.142792 377.094153 391.647175
2012-02-17 777.654599 588.169496 903.118373 523.716717 800.141240 427.036542 629.291289 675.893158 560.918105 509.823499 ... 1746.997548 576.041492 707.379389 1395.996281 1820.407151 423.730240 571.148127 802.326065 379.077828 387.193964
2012-02-20 777.654599 585.526025 900.102944 513.803202 803.530886 425.827147 628.578480 677.234217 559.101851 505.568986 ... 1747.300926 573.432005 706.187511 1386.185926 1849.315668 423.730240 570.691756 804.236693 376.616516 387.529730
2012-02-21 775.141977 586.320318 906.873559 516.598163 821.005033 426.794937 629.528713 679.908400 562.728496 509.823499 ... 1749.423093 574.085488 708.569263 1396.484990 1860.358148 423.730240 573.424534 815.337607 378.047616 392.862959
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2016-11-21 925.557166 1189.283040 1445.910513 833.365440 909.461500 863.842881 602.350800 888.376057 869.364089 1026.692281 ... 1803.811423 778.640773 1024.855559 1632.567999 1872.149159 1330.774865 629.073049 1079.801530 1155.146511 1025.895512
2016-11-22 933.404034 1191.141296 1442.747283 838.158114 910.350081 866.899077 605.814037 881.952429 867.664451 1028.840925 ... 1820.163373 782.603347 1050.994505 1680.758555 1866.839760 1330.774865 631.256579 1082.665384 1189.614168 1017.068714
2016-11-23 933.404034 1171.482605 1434.490242 832.995630 909.905899 872.746297 601.606084 878.075696 867.239021 1023.820409 ... 1813.336314 777.918136 1060.173671 1670.986620 1864.475175 1330.774865 626.442767 1085.780975 1175.070660 1012.626463
2016-11-24 934.823661 1176.663056 1433.215706 829.288466 919.188638 872.746297 597.618593 878.075696 875.286833 1022.381448 ... 1796.922239 772.112696 1071.084837 1727.605385 1842.458899 1330.774865 620.262067 1091.211853 1157.377244 991.357301
2016-11-25 953.781834 1170.065774 1436.399926 830.031224 914.780034 870.645822 595.112844 873.748042 866.813382 1018.775153 ... 1806.483455 776.470846 1074.697275 1718.497030 1842.458899 1330.774865 617.148505 1087.853078 1153.656960 1032.221270
2016-11-28 950.299596 1161.052362 1446.542329 833.735085 915.663453 865.019619 596.116408 878.507289 859.115825 1037.390996 ... 1814.096145 774.657930 1078.297611 1714.919722 1853.797214 1330.774865 614.467181 1087.594281 1246.817471 1026.670505
2016-11-29 962.087784 1162.955728 1426.825947 830.031224 917.868280 882.021226 591.334311 864.589462 847.873764 1030.270864 ... 1837.495065 761.477532 1061.999984 1702.941091 1850.224200 1330.774865 610.423112 1091.985488 1231.538254 1019.797320
2016-11-30 954.476758 1142.812290 1431.301774 842.923539 915.663453 878.786136 591.334311 857.103698 850.481276 1021.661207 ... 1812.576165 762.215756 1054.675758 1709.340141 1846.644272 1330.774865 609.520786 1080.583334 1219.340479 1034.348248
2016-12-01 964.153091 1147.158518 1426.185397 841.826220 914.780034 879.249020 593.352523 862.394512 852.648110 1019.497433 ... 1840.866962 772.476814 1063.823161 1708.940902 1847.838352 1330.774865 612.673113 1079.280012 1224.234173 1033.923202
2016-12-02 941.185483 1135.531611 1426.825947 829.288466 902.321359 865.254774 588.039944 855.332821 842.634535 1018.775153 ... 1870.203856 776.470846 1052.836741 1710.138338 1854.986690 1330.774865 605.443678 1069.586076 1209.493693 1023.239684
2016-12-05 940.480739 1116.379650 1421.050599 820.322922 904.111680 865.019619 587.531479 853.558269 839.563220 1017.329056 ... 1940.010093 778.640773 1047.300313 1622.505851 1868.611236 1330.774865 605.898045 1070.901195 1206.193567 1028.381624
2016-12-06 937.656466 1116.379650 1415.251684 818.819121 900.527477 856.748513 589.816121 860.634521 848.308906 1013.704787 ... 1924.318577 781.884373 1049.149035 1614.072811 1883.308735 1330.774865 609.972116 1070.638301 1207.844757 1034.773119
2016-12-07 964.153091 1134.557324 1411.372503 824.444233 903.664433 858.172078 593.604317 874.181772 848.308906 1015.156047 ... 1950.989699 782.603347 1065.643219 1617.873118 1887.403525 1330.774865 614.914881 1075.098766 1213.606230 1039.435237
2016-12-08 964.840544 1129.673283 1429.385278 818.819121 904.558707 849.115857 592.091947 865.903761 847.438399 1025.975067 ... 1935.031140 789.044635 1058.344207 1609.839725 1871.559970 1330.774865 611.324106 1079.280012 1207.019444 1036.046686
2016-12-09 955.865088 1130.162637 1426.825947 816.558226 905.005513 849.594907 591.081550 857.103698 843.510000 1026.692281 ... 1962.259047 790.468905 1063.823161 1613.650002 1868.020931 1330.774865 611.774106 1081.885085 1197.071312 1036.046686
2016-12-12 942.593391 1100.416295 1402.279350 791.262132 881.471340 834.616513 573.111330 828.772972 812.761712 1013.704787 ... 1930.396328 771.383944 1045.448321 1559.459167 1864.475175 1330.774865 596.283639 1068.532815 1167.571885 1000.213300
2016-12-13 969.639070 1102.925800 1402.279350 793.983258 889.233734 843.828359 578.561006 844.180677 810.032789 1013.704787 ... 2000.513310 771.019310 1052.836741 1567.750739 1840.062982 1330.774865 598.126870 1084.743439 1162.439676 1003.284811
2016-12-14 956.558498 1098.404564 1395.747972 792.040551 887.413397 855.322578 570.235953 836.965325 808.208389 1003.487199 ... 1975.557905 794.018401 1041.734461 1556.393242 1899.634937 1330.774865 600.881114 1084.483900 1162.439676 995.808993
2016-12-15 1003.247016 1118.853351 1404.883400 794.371229 888.324032 860.539454 573.893024 837.870642 818.643170 1028.125209 ... 1968.569706 797.904610 1050.994505 1555.954759 1906.589084 1330.774865 607.259106 1089.404568 1165.863659 1002.846600
2016-12-16 1031.274248 1124.276333 1442.747283 798.626474 895.124264 865.724893 588.801819 843.282134 819.544264 1043.052108 ... 1922.527346 794.018401 1049.149035 1574.699252 1894.402574 1330.774865 612.223774 1087.076502 1172.681634 1015.477956
2016-12-19 1014.420108 1115.388634 1460.998683 793.983258 894.220554 867.602824 592.596499 844.180677 812.307528 1043.052108 ... 1937.522216 800.016404 1060.173671 1569.925453 1898.473436 1330.774865 613.122122 1094.303111 1172.681634 1008.964239
2016-12-20 989.940764 1119.841301 1459.747292 795.534008 889.688236 862.428676 585.493202 836.059028 821.343485 1036.681184 ... 1929.325175 789.757091 1058.344207 1563.828632 1873.326982 1330.774865 615.809303 1091.211853 1168.425062 1012.009191
2016-12-21 989.270753 1122.799936 1457.241286 798.240571 893.315930 871.813377 589.562709 836.965325 823.138773 1036.681184 ... 1997.410936 817.746489 1067.460174 1572.097159 1885.649704 1330.774865 616.256027 1093.273663 1167.571885 1014.178559
2016-12-22 987.929368 1120.828380 1450.957336 796.308250 894.672523 863.136068 586.258387 860.193961 816.386085 1047.980495 ... 2021.755869 821.520460 1092.580321 1571.228837 1917.548240 1330.774865 615.809303 1087.076502 1166.718085 1004.160660
2016-12-23 966.899971 1105.429607 1469.106742 791.651437 900.078448 860.303010 578.302662 848.212340 815.481502 1049.384354 ... 2025.841605 811.533045 1092.580321 1561.208420 1927.873134 1330.774865 611.324106 1077.975115 1161.582104 998.453908
2016-12-26 957.251405 1112.907232 1464.122481 795.534008 906.790536 864.078356 581.652182 853.114055 815.028834 1048.682660 ... 2032.293887 813.609465 1080.093278 1562.082312 1920.996038 1330.774865 615.362254 1076.407150 1167.571885 1009.399795
2016-12-27 955.865088 1112.907232 1465.993565 795.534008 910.350081 865.254774 585.237919 854.889528 818.192251 1062.628520 ... 2012.874993 813.609465 1076.498948 1558.583803 1923.864482 1330.774865 619.818230 1081.364572 1163.296617 1005.910070
2016-12-28 948.903123 1112.907232 1448.436123 792.040551 907.236243 867.602824 585.493202 849.105666 819.544264 1055.678619 ... 2011.162636 826.639017 1074.697275 1551.123272 1915.246261 1330.774865 624.683093 1084.483900 1164.152927 1004.160660
2016-12-29 952.390467 1126.732697 1451.586955 796.695089 909.461500 868.540266 587.531479 855.332821 813.215642 1043.757588 ... 1987.034705 820.492917 1096.121919 1570.794496 1915.246261 1330.774865 620.705587 1084.224299 1176.075799 1005.473003
2016-12-30 947.504591 1118.853351 1436.399926 793.983258 909.905899 861.484583 590.069424 841.932522 808.664875 1045.167120 ... 1950.636483 818.090297 1096.121919 1565.573004 1915.246261 1330.774865 624.242399 1112.923286 1191.229870 997.573049

1214 rows × 1071 columns


In [57]:
specDF = multiFactorReg(activeReturnDF,factordic,WLS=True,weightdf = weight)[0]

specDF.index.name = 'Specifc_Return_for_ZX500'

specDF = specDF.rolling(min_periods=20,window=60,center=False).std()

specDF


Out[57]:
600507.SH 002344.SZ 000793.SZ 300039.SZ 600059.SH 600501.SH 000713.SZ 002233.SZ 600360.SH 600565.SH ... 600150.SH 600469.SH 600282.SH 600739.SH 600406.SH 600687.SH 600866.SH 000860.SZ 601908.SH 002195.SZ
Specifc_Return_for_ZX500
2012-01-05 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-06 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-09 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-10 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-11 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-12 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-13 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-16 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-17 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-18 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-19 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-20 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-30 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-01-31 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-02-01 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-02-02 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-02-03 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-02-06 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-02-07 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2012-02-08 0.024681 0.010271 0.015044 0.023673 0.008274 0.012507 0.029383 0.019861 0.008383 0.018102 ... 0.008983 0.013302 0.009655 0.013662 0.030834 0.026065 0.015539 0.011284 0.021302 0.027655
2012-02-09 0.024230 0.010023 0.014664 0.023144 0.008584 0.012537 0.028653 0.019363 0.008171 0.017659 ... 0.008757 0.013599 0.009456 0.013550 0.030172 0.025437 0.015928 0.011001 0.020986 0.027008
2012-02-10 0.023650 0.009824 0.014313 0.022690 0.008516 0.012239 0.028129 0.018897 0.008216 0.017246 ... 0.008640 0.013334 0.009286 0.013251 0.029454 0.024838 0.015789 0.011379 0.020515 0.026413
2012-02-13 0.023168 0.009683 0.013984 0.024383 0.008793 0.011970 0.027700 0.019013 0.009803 0.017082 ... 0.008473 0.013053 0.009441 0.012962 0.028794 0.024352 0.015505 0.011153 0.020833 0.025808
2012-02-14 0.022721 0.009650 0.013680 0.024985 0.008606 0.011816 0.027100 0.018812 0.010242 0.016873 ... 0.008498 0.013117 0.009481 0.012768 0.028168 0.023821 0.015239 0.010909 0.020601 0.025260
2012-02-15 0.022258 0.009464 0.013527 0.024459 0.008798 0.011596 0.026581 0.018486 0.010598 0.016733 ... 0.008444 0.013081 0.009453 0.013262 0.027693 0.023448 0.016020 0.010772 0.020275 0.024736
2012-02-16 0.022065 0.009337 0.013339 0.023965 0.008642 0.011440 0.026299 0.018168 0.010670 0.016627 ... 0.008498 0.012943 0.009351 0.013097 0.027135 0.022981 0.015831 0.010793 0.020609 0.024244
2012-02-17 0.021694 0.009159 0.013122 0.023584 0.008517 0.011743 0.025870 0.017940 0.010940 0.016329 ... 0.008439 0.012726 0.009172 0.013254 0.026660 0.022589 0.015765 0.010642 0.020299 0.024070
2012-02-20 0.021297 0.009155 0.012914 0.024164 0.008560 0.011699 0.025387 0.017606 0.010967 0.016542 ... 0.008305 0.012764 0.009030 0.013295 0.027210 0.022167 0.015489 0.010485 0.020217 0.023623
2012-02-21 0.021225 0.009057 0.012732 0.023746 0.010557 0.011576 0.024948 0.017318 0.010769 0.016269 ... 0.008319 0.012705 0.008882 0.013062 0.026728 0.021798 0.015213 0.010779 0.019924 0.023392
2012-02-22 0.021023 0.008922 0.012528 0.023351 0.010620 0.011801 0.024514 0.017036 0.010835 0.016124 ... 0.008227 0.012552 0.008882 0.012837 0.026272 0.021598 0.014948 0.010684 0.019821 0.023048
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2016-11-21 0.015091 0.017818 0.020984 0.010135 0.007493 0.009722 0.009287 0.015742 0.018431 0.013953 ... 0.012222 0.011742 0.007463 0.012499 0.016296 0.006733 0.013836 0.009382 0.011381 0.009434
2016-11-22 0.015130 0.017784 0.020957 0.010131 0.007492 0.009687 0.008445 0.015927 0.018421 0.013908 ... 0.012303 0.011742 0.009045 0.014103 0.016385 0.006764 0.013825 0.009320 0.013064 0.010094
2016-11-23 0.015126 0.018146 0.020943 0.010166 0.007295 0.009928 0.008389 0.015922 0.018467 0.013572 ... 0.012277 0.011723 0.009451 0.014159 0.016069 0.006687 0.013873 0.008772 0.013287 0.010093
2016-11-24 0.015051 0.018168 0.020818 0.009450 0.007840 0.009927 0.008416 0.015922 0.017048 0.012325 ... 0.012506 0.011744 0.009753 0.016350 0.016392 0.006684 0.014046 0.008900 0.013808 0.011086
2016-11-25 0.015560 0.018247 0.020398 0.009446 0.007796 0.009970 0.008178 0.016004 0.017166 0.012265 ... 0.012516 0.011824 0.009706 0.016488 0.016399 0.006728 0.014121 0.008956 0.013873 0.011129
2016-11-28 0.015531 0.018441 0.014274 0.009494 0.007798 0.009746 0.008180 0.016009 0.017154 0.012946 ... 0.012503 0.011764 0.009399 0.016536 0.016346 0.006683 0.014190 0.008942 0.013842 0.011266
2016-11-29 0.016011 0.018477 0.014449 0.008280 0.007778 0.011732 0.008061 0.016234 0.017177 0.012568 ... 0.012930 0.011912 0.009796 0.016629 0.016343 0.006655 0.012990 0.009155 0.013960 0.011264
2016-11-30 0.016068 0.018794 0.014604 0.009618 0.007601 0.011700 0.008096 0.016301 0.017211 0.012423 ... 0.013208 0.011885 0.009724 0.016704 0.016332 0.006678 0.012941 0.009284 0.014063 0.012237
2016-12-01 0.016150 0.018766 0.014537 0.009582 0.007546 0.011584 0.007936 0.016310 0.017210 0.012442 ... 0.013590 0.012181 0.009730 0.016745 0.016349 0.006719 0.012944 0.009253 0.014063 0.012268
2016-12-02 0.016631 0.018654 0.014630 0.009655 0.007160 0.011704 0.007922 0.016297 0.017149 0.012318 ... 0.013971 0.012603 0.009566 0.016777 0.016510 0.006879 0.012960 0.009253 0.014121 0.012170
2016-12-05 0.016543 0.018814 0.014598 0.009515 0.007005 0.011661 0.007901 0.016170 0.017000 0.012351 ... 0.017550 0.012685 0.009515 0.020645 0.016460 0.006862 0.012658 0.009111 0.013987 0.012290
2016-12-06 0.016568 0.018815 0.014473 0.009524 0.007008 0.011982 0.007910 0.016178 0.017147 0.012402 ... 0.017678 0.012696 0.009522 0.020680 0.015872 0.006835 0.012713 0.009045 0.013971 0.012337
2016-12-07 0.017179 0.018821 0.013697 0.009524 0.006993 0.012024 0.007618 0.016318 0.017216 0.012413 ... 0.017800 0.012751 0.009754 0.020693 0.015770 0.006882 0.012686 0.009049 0.013971 0.012333
2016-12-08 0.017066 0.018805 0.014050 0.009588 0.007036 0.012202 0.007611 0.016451 0.017179 0.012785 ... 0.017891 0.013017 0.009838 0.020601 0.015840 0.006647 0.012632 0.009189 0.013993 0.012338
2016-12-09 0.016510 0.018675 0.013823 0.009497 0.006818 0.012197 0.007599 0.016673 0.017191 0.012093 ... 0.018135 0.012999 0.009847 0.020532 0.015844 0.006651 0.012625 0.009221 0.014136 0.012331
2016-12-12 0.016614 0.018716 0.013432 0.008921 0.006889 0.012283 0.007651 0.016003 0.017405 0.012188 ... 0.018129 0.012987 0.009848 0.020808 0.016137 0.007737 0.012599 0.009437 0.014197 0.012516
2016-12-13 0.017696 0.018634 0.013428 0.008689 0.007127 0.012448 0.007819 0.015957 0.017450 0.012207 ... 0.019850 0.013007 0.009883 0.020810 0.016460 0.007691 0.012591 0.009957 0.014290 0.012498
2016-12-14 0.017696 0.018556 0.013354 0.008637 0.006994 0.013057 0.008567 0.016071 0.017217 0.012066 ... 0.019974 0.015269 0.010090 0.020780 0.018720 0.007119 0.012164 0.009952 0.014298 0.012590
2016-12-15 0.021338 0.018951 0.013302 0.008600 0.007013 0.013064 0.008418 0.014865 0.017366 0.013130 ... 0.020082 0.015190 0.010054 0.020743 0.018727 0.007119 0.012143 0.009940 0.014271 0.012582
2016-12-16 0.021683 0.018929 0.014713 0.008533 0.007010 0.013063 0.009930 0.014520 0.017341 0.013383 ... 0.021107 0.015427 0.010150 0.020848 0.018846 0.007114 0.012156 0.009983 0.014235 0.012789
2016-12-19 0.022125 0.019104 0.014994 0.008652 0.007008 0.012984 0.009964 0.014514 0.017478 0.013382 ... 0.021140 0.015459 0.010392 0.020874 0.018823 0.007026 0.012069 0.010079 0.014221 0.012963
2016-12-20 0.022915 0.019149 0.014934 0.008705 0.007059 0.013021 0.010380 0.014530 0.017799 0.013351 ... 0.021065 0.015691 0.010392 0.020854 0.019010 0.007040 0.010119 0.010053 0.014217 0.013023
2016-12-21 0.022921 0.019158 0.015028 0.008703 0.007057 0.013140 0.010401 0.014536 0.017801 0.013191 ... 0.022525 0.017515 0.010406 0.020824 0.018693 0.007122 0.010167 0.010062 0.014268 0.013030
2016-12-22 0.022927 0.019117 0.015066 0.008478 0.006981 0.013391 0.010491 0.016197 0.017904 0.013482 ... 0.022659 0.017531 0.011958 0.020819 0.019221 0.007086 0.010159 0.010163 0.014256 0.013249
2016-12-23 0.023276 0.019184 0.015716 0.008454 0.007677 0.013287 0.010538 0.016344 0.017898 0.013461 ... 0.022681 0.017600 0.011995 0.020739 0.019381 0.007179 0.010122 0.010105 0.014250 0.013251
2016-12-26 0.023457 0.019165 0.015226 0.008491 0.007805 0.013256 0.010283 0.016313 0.017799 0.013475 ... 0.022653 0.017598 0.012533 0.020715 0.019424 0.006771 0.009983 0.010088 0.014294 0.013398
2016-12-27 0.022837 0.019168 0.015226 0.008454 0.007852 0.013252 0.010317 0.016279 0.017753 0.013812 ... 0.022858 0.017591 0.012593 0.020341 0.019427 0.006713 0.010060 0.010125 0.014318 0.013408
2016-12-28 0.022897 0.019166 0.015460 0.008467 0.007868 0.013256 0.010302 0.016172 0.017703 0.013906 ... 0.022845 0.018035 0.012599 0.020351 0.019407 0.006727 0.010221 0.010165 0.014331 0.013358
2016-12-29 0.022880 0.019226 0.015481 0.008547 0.007908 0.013211 0.010285 0.016149 0.017719 0.014199 ... 0.023107 0.018135 0.013591 0.020601 0.019405 0.006726 0.010214 0.010192 0.014635 0.013376
2016-12-30 0.022904 0.019233 0.015446 0.008495 0.007912 0.013320 0.010356 0.016215 0.017770 0.014154 ... 0.023505 0.018137 0.013592 0.020590 0.019133 0.006735 0.010186 0.011793 0.014912 0.013397

1213 rows × 1071 columns


In [58]:
#specDF.to_csv(path+'Own_Factor_Specific_Volatility.csv',na_rep='NaN',date_format='%Y%m%d')

In [59]:
multiFactorReg(activeReturnDF,factordic)[3].describe()


Out[59]:
R-Square
count 1213.000000
mean 0.058747
std 0.055401
min 0.000807
25% 0.022558
50% 0.040173
75% 0.076018
max 0.383183

In [60]:
multiFactorReg(activeReturnDF,factordic,True,weight)[3].describe()


Out[60]:
R-Square
count 1213.000000
mean 0.052555
std 0.048237
min 0.001143
25% 0.020351
50% 0.037204
75% 0.067413
max 0.313538

In [61]:
for date in returnDF.index:
    activeReturnSlice = activeReturnDF .loc[date]
    LFCAPDataSlice = LFCAPData.loc[date]
    PBDataSlice = PBData.loc[date]
    YOYBPSDataSlice = YOYBPSData.loc[date]
    AMOUNTAVG1MDataSlice = AMOUNTAVG1MData .loc[date]
    TURNOVER1MDataSlice = TURNOVER1MData.loc[date]
    PROFITOOPDataSlice = PROFITOOPData.loc[date]
    totalDF = pd.concat([LFCAPDataSlice,PBDataSlice,YOYBPSDataSlice,AMOUNTAVG1MDataSlice,TURNOVER1MDataSlice,PROFITOOPDataSlice],axis=1)
    #print totalDF,PBDataSlice
    result = sm.OLS(activeReturnSlice.T,totalDF ).fit()
    factorReturn . loc[date] = result.params.values
    factorPvalue . loc[date] = result.pvalues.values
    specificReturn .loc[date] = result.resid
result.summary()


Out[61]:
OLS Regression Results
Dep. Variable: 2016-12-30 00:00:00 R-squared: 0.091
Model: OLS Adj. R-squared: 0.085
Method: Least Squares F-statistic: 17.68
Date: Wed, 26 Apr 2017 Prob (F-statistic): 1.33e-19
Time: 09:40:34 Log-Likelihood: 3088.4
No. Observations: 1071 AIC: -6165.
Df Residuals: 1065 BIC: -6135.
Df Model: 6
Covariance Type: nonrobust
coef std err t P>|t| [0.025 0.975]
2016-12-30 00:00:00 0.0008 0.001 1.482 0.139 -0.000 0.002
2016-12-30 00:00:00 0.0018 0.014 0.133 0.894 -0.025 0.028
2016-12-30 00:00:00 -0.0008 0.001 -0.868 0.386 -0.003 0.001
2016-12-30 00:00:00 -0.0016 0.000 -3.344 0.001 -0.003 -0.001
2016-12-30 00:00:00 -0.0038 0.001 -7.448 0.000 -0.005 -0.003
2016-12-30 00:00:00 4.907e-05 0.000 0.113 0.910 -0.001 0.001
Omnibus: 236.185 Durbin-Watson: 1.991
Prob(Omnibus): 0.000 Jarque-Bera (JB): 2483.395
Skew: 0.693 Prob(JB): 0.00
Kurtosis: 10.330 Cond. No. 39.8

In [62]:
factorReturn.head()


Out[62]:
LFCA PB YOYBPS AMOUNTAVG1MData TURNOVER1M PROFITOOP
Specifc_Return_for_ZX500
2012-01-05 0.010763 -0.001083 -0.000036 0.001894 0.001312 -0.039442
2012-01-06 0.000101 -0.000361 0.000318 0.002294 0.001647 -0.022881
2012-01-09 -0.002122 -0.032656 0.000115 0.000528 0.000192 0.050028
2012-01-10 -0.001900 -0.001688 -0.001064 0.000217 -0.001661 0.029090
2012-01-11 -0.003104 0.002084 -0.000630 0.000545 -0.000638 -0.013783

In [63]:
def calEWMcovariance(facRetdf,decay=0.94):
    '''
    To calculate EWM covariance matrix of given facRetdf
    output: Dataframe, the ewm cov-matrix of the factors
    input:
    facRetdf: Dataframe, factor return dataframe
    decay: float, decay-factors
    Decay factors were set at:
    − 0.94 (1-day) from 112 days of data;
    − 0.97 (1-month) from 227 days of data.
    '''
    m,n = facRetdf.shape
    facDF = facRetdf - facRetdf.mean()
    for i in xrange(m):
        facDF.iloc[i] = np.sqrt(decay**(m-1-i)) * facDF.iloc[i]
    ewmCovMatrix = facDF.T.dot(facDF) * (1-decay)/(1-decay**m)
    return ewmCovMatrix

In [64]:
compara = 1/0.94 - 1
ewmMatrix = factorReturn.ewm(ignore_na=True, min_periods=0, com=compara).cov(pairwise = True)[-200:].iloc[-1]

In [65]:
calEWMcovariance(factorReturn.iloc[-200:], decay=0.94)


Out[65]:
LFCA PB YOYBPS AMOUNTAVG1MData TURNOVER1M PROFITOOP
LFCA 4.650162e-06 -0.000001 2.518765e-07 -4.502851e-07 -3.139638e-06 -2.471350e-07
PB -1.216889e-06 0.001375 -6.708782e-06 -2.063559e-05 -1.669693e-05 6.297053e-06
YOYBPS 2.518765e-07 -0.000007 1.296555e-06 2.905198e-07 2.570304e-07 -1.963979e-08
AMOUNTAVG1MData -4.502851e-07 -0.000021 2.905198e-07 2.454811e-06 -2.380790e-08 -2.879563e-08
TURNOVER1M -3.139638e-06 -0.000017 2.570304e-07 -2.380790e-08 4.739274e-06 5.153030e-07
PROFITOOP -2.471350e-07 0.000006 -1.963979e-08 -2.879563e-08 5.153030e-07 5.995070e-07

In [66]:
# calculate monthly scaled variance  forecast for the market index by DEWIV
alphaS = 21*returnOfBench.ewm(ignore_na=True, min_periods=0, com=compara).cov(pairwise = True)[-200:].iloc[-1]

In [67]:
alphaS


Out[67]:
0.0002192128126956748

In [68]:
benchmarkWeight = pd.read_csv(path+ZZ500Weight,infer_datetime_format=True,parse_dates=[0],index_col=0)[stkPool].loc[startTime:endTime].fillna(0)

In [69]:
benchmarkWeight


Out[69]:
600507.SH 002344.SZ 000793.SZ 300039.SZ 600059.SH 600501.SH 000713.SZ 002233.SZ 600360.SH 600565.SH ... 600150.SH 600469.SH 600282.SH 600739.SH 600406.SH 600687.SH 600866.SH 000860.SZ 601908.SH 002195.SZ
LZ_GPA_INDEX_CSI500WEIGHT-d
2012-01-04 0.1384 0.0000 0.3659 0.0000 0.2749 0.1272 0.1678 0.2312 0.1507 0.0000 ... 0.0 0.1177 0.0000 0.0 0.0 0.0000 0.1689 0.2531 0.0000 0.0
2012-01-05 0.1424 0.0000 0.3737 0.0000 0.2701 0.1272 0.1702 0.2268 0.1492 0.0000 ... 0.0 0.1187 0.0000 0.0 0.0 0.0000 0.1763 0.2516 0.0000 0.0
2012-01-06 0.1463 0.0000 0.3908 0.0000 0.2666 0.1247 0.1590 0.2188 0.1490 0.0000 ... 0.0 0.1214 0.0000 0.0 0.0 0.0000 0.1737 0.2479 0.0000 0.0
2012-01-09 0.1476 0.0000 0.3857 0.0000 0.2690 0.1257 0.1474 0.2278 0.1507 0.0000 ... 0.0 0.1245 0.0000 0.0 0.0 0.0000 0.1691 0.2476 0.0000 0.0
2012-01-10 0.1473 0.0000 0.3820 0.0000 0.2684 0.1265 0.1461 0.2331 0.1513 0.0000 ... 0.0 0.1231 0.0000 0.0 0.0 0.0000 0.1699 0.2523 0.0000 0.0
2012-01-11 0.1463 0.0000 0.3764 0.0000 0.2675 0.1267 0.1544 0.2383 0.1515 0.0000 ... 0.0 0.1238 0.0000 0.0 0.0 0.0000 0.1750 0.2522 0.0000 0.0
2012-01-12 0.1529 0.0000 0.3744 0.0000 0.2643 0.1271 0.1573 0.2332 0.1507 0.0000 ... 0.0 0.1245 0.0000 0.0 0.0 0.0000 0.1728 0.2500 0.0000 0.0
2012-01-13 0.1512 0.0000 0.3726 0.0000 0.2633 0.1279 0.1543 0.2347 0.1507 0.0000 ... 0.0 0.1225 0.0000 0.0 0.0 0.0000 0.1723 0.2483 0.0000 0.0
2012-01-16 0.1496 0.0000 0.3729 0.0000 0.2637 0.1267 0.1570 0.2324 0.1488 0.0000 ... 0.0 0.1208 0.0000 0.0 0.0 0.0000 0.1685 0.2445 0.0000 0.0
2012-01-17 0.1530 0.0000 0.3770 0.0000 0.2615 0.1255 0.1599 0.2323 0.1502 0.0000 ... 0.0 0.1218 0.0000 0.0 0.0 0.0000 0.1665 0.2478 0.0000 0.0
2012-01-18 0.1449 0.0000 0.3726 0.0000 0.2622 0.1247 0.1599 0.2385 0.1504 0.0000 ... 0.0 0.1226 0.0000 0.0 0.0 0.0000 0.1670 0.2469 0.0000 0.0
2012-01-19 0.1479 0.0000 0.3764 0.0000 0.2600 0.1294 0.1581 0.2455 0.1512 0.0000 ... 0.0 0.1248 0.0000 0.0 0.0 0.0000 0.1658 0.2462 0.0000 0.0
2012-01-20 0.1572 0.0000 0.3667 0.0000 0.2610 0.1289 0.1560 0.2445 0.1523 0.0000 ... 0.0 0.1260 0.0000 0.0 0.0 0.0000 0.1651 0.2468 0.0000 0.0
2012-01-30 0.1543 0.0000 0.3669 0.0000 0.2652 0.1285 0.1602 0.2472 0.1525 0.0000 ... 0.0 0.1254 0.0000 0.0 0.0 0.0000 0.1670 0.2486 0.0000 0.0
2012-01-31 0.1558 0.0000 0.3695 0.0000 0.2681 0.1290 0.1597 0.2399 0.1532 0.0000 ... 0.0 0.1232 0.0000 0.0 0.0 0.0000 0.1664 0.2543 0.0000 0.0
2012-02-01 0.1550 0.0000 0.3771 0.0000 0.2672 0.1307 0.1593 0.2398 0.1535 0.0000 ... 0.0 0.1248 0.0000 0.0 0.0 0.0000 0.1651 0.2567 0.0000 0.0
2012-02-02 0.1534 0.0000 0.3764 0.0000 0.2645 0.1293 0.1609 0.2335 0.1555 0.0000 ... 0.0 0.1264 0.0000 0.0 0.0 0.0000 0.1665 0.2569 0.0000 0.0
2012-02-03 0.1521 0.0000 0.3752 0.0000 0.2615 0.1289 0.1593 0.2346 0.1557 0.0000 ... 0.0 0.1259 0.0000 0.0 0.0 0.0000 0.1664 0.2565 0.0000 0.0
2012-02-06 0.1510 0.0000 0.3685 0.0000 0.2600 0.1285 0.1566 0.2308 0.1593 0.0000 ... 0.0 0.1254 0.0000 0.0 0.0 0.0000 0.1736 0.2511 0.0000 0.0
2012-02-07 0.1501 0.0000 0.3635 0.0000 0.2588 0.1272 0.1574 0.2340 0.1568 0.0000 ... 0.0 0.1240 0.0000 0.0 0.0 0.0000 0.1716 0.2498 0.0000 0.0
2012-02-08 0.1511 0.0000 0.3669 0.0000 0.2562 0.1268 0.1573 0.2304 0.1547 0.0000 ... 0.0 0.1235 0.0000 0.0 0.0 0.0000 0.1688 0.2480 0.0000 0.0
2012-02-09 0.1493 0.0000 0.3618 0.0000 0.2570 0.1271 0.1551 0.2331 0.1560 0.0000 ... 0.0 0.1252 0.0000 0.0 0.0 0.0000 0.1702 0.2467 0.0000 0.0
2012-02-10 0.1516 0.0000 0.3605 0.0000 0.2597 0.1259 0.1539 0.2331 0.1567 0.0000 ... 0.0 0.1234 0.0000 0.0 0.0 0.0000 0.1741 0.2467 0.0000 0.0
2012-02-13 0.1518 0.0000 0.3592 0.0000 0.2573 0.1260 0.1555 0.2337 0.1559 0.0000 ... 0.0 0.1231 0.0000 0.0 0.0 0.0000 0.1721 0.2508 0.0000 0.0
2012-02-14 0.1511 0.0000 0.3578 0.0000 0.2601 0.1262 0.1526 0.2289 0.1607 0.0000 ... 0.0 0.1231 0.0000 0.0 0.0 0.0000 0.1736 0.2497 0.0000 0.0
2012-02-15 0.1502 0.0000 0.3573 0.0000 0.2590 0.1272 0.1513 0.2317 0.1584 0.0000 ... 0.0 0.1251 0.0000 0.0 0.0 0.0000 0.1723 0.2492 0.0000 0.0
2012-02-16 0.1499 0.0000 0.3597 0.0000 0.2554 0.1281 0.1496 0.2307 0.1618 0.0000 ... 0.0 0.1241 0.0000 0.0 0.0 0.0000 0.1774 0.2475 0.0000 0.0
2012-02-17 0.1529 0.0000 0.3616 0.0000 0.2555 0.1275 0.1515 0.2288 0.1605 0.0000 ... 0.0 0.1255 0.0000 0.0 0.0 0.0000 0.1758 0.2444 0.0000 0.0
2012-02-20 0.1521 0.0000 0.3592 0.0000 0.2539 0.1298 0.1494 0.2266 0.1583 0.0000 ... 0.0 0.1252 0.0000 0.0 0.0 0.0000 0.1733 0.2429 0.0000 0.0
2012-02-21 0.1518 0.0000 0.3560 0.0000 0.2555 0.1288 0.1487 0.2270 0.1569 0.0000 ... 0.0 0.1238 0.0000 0.0 0.0 0.0000 0.1727 0.2435 0.0000 0.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2016-11-21 0.0846 0.1798 0.0000 0.1389 0.1233 0.0000 0.0000 0.0934 0.0000 0.2512 ... 0.0 0.0000 0.1317 0.0 0.0 0.2434 0.0000 0.2052 0.1120 0.0
2016-11-22 0.0852 0.1780 0.0000 0.1394 0.1234 0.0000 0.0000 0.0926 0.0000 0.2505 ... 0.0 0.0000 0.1334 0.0 0.0 0.2430 0.0000 0.2056 0.1156 0.0
2016-11-23 0.0860 0.1773 0.0000 0.1400 0.1227 0.0000 0.0000 0.0906 0.0000 0.2497 ... 0.0 0.0000 0.1393 0.0 0.0 0.2412 0.0000 0.2052 0.1217 0.0
2016-11-24 0.0864 0.1722 0.0000 0.1389 0.1231 0.0000 0.0000 0.0902 0.0000 0.2484 ... 0.0 0.0000 0.1424 0.0 0.0 0.2423 0.0000 0.2073 0.1192 0.0
2016-11-25 0.0867 0.1740 0.0000 0.1378 0.1258 0.0000 0.0000 0.0903 0.0000 0.2480 ... 0.0 0.0000 0.1455 0.0 0.0 0.2426 0.0000 0.2096 0.1158 0.0
2016-11-28 0.0899 0.1713 0.0000 0.1375 0.1240 0.0000 0.0000 0.0890 0.0000 0.2451 ... 0.0 0.0000 0.1458 0.0 0.0 0.2415 0.0000 0.2074 0.1146 0.0
2016-11-29 0.0890 0.1682 0.0000 0.1383 0.1239 0.0000 0.0000 0.0897 0.0000 0.2535 ... 0.0 0.0000 0.1464 0.0 0.0 0.2409 0.0000 0.2067 0.1151 0.0
2016-11-30 0.0919 0.1700 0.0000 0.1381 0.1255 0.0000 0.0000 0.0876 0.0000 0.2519 ... 0.0 0.0000 0.1431 0.0 0.0 0.2427 0.0000 0.2100 0.1132 0.0
2016-12-01 0.0909 0.1650 0.0000 0.1432 0.1255 0.0000 0.0000 0.0865 0.0000 0.2490 ... 0.0 0.0000 0.1419 0.0 0.0 0.2440 0.0000 0.2067 0.1115 0.0
2016-12-02 0.0922 0.1653 0.0000 0.1420 0.1245 0.0000 0.0000 0.0871 0.0000 0.2465 ... 0.0 0.0000 0.1435 0.0 0.0 0.2425 0.0000 0.2050 0.1118 0.0
2016-12-05 0.0892 0.1644 0.0000 0.1399 0.1230 0.0000 0.0000 0.0870 0.0000 0.2499 ... 0.0 0.0000 0.1427 0.0 0.0 0.2462 0.0000 0.2044 0.1108 0.0
2016-12-06 0.0896 0.1598 0.0000 0.1376 0.1242 0.0000 0.0000 0.0871 0.0000 0.2505 ... 0.0 0.0000 0.1420 0.0 0.0 0.2476 0.0000 0.2060 0.1108 0.0
2016-12-07 0.0890 0.1597 0.0000 0.1370 0.1231 0.0000 0.0000 0.0885 0.0000 0.2486 ... 0.0 0.0000 0.1423 0.0 0.0 0.2474 0.0000 0.2057 0.1110 0.0
2016-12-08 0.0931 0.1632 0.0000 0.1375 0.1227 0.0000 0.0000 0.0903 0.0000 0.2467 ... 0.0 0.0000 0.1454 0.0 0.0 0.2449 0.0000 0.2053 0.1109 0.0
2016-12-09 0.0936 0.1625 0.0000 0.1362 0.1235 0.0000 0.0000 0.0890 0.0000 0.2531 ... 0.0 0.0000 0.1440 0.0 0.0 0.2459 0.0000 0.2078 0.1101 0.0
2016-12-12 0.0000 0.1578 0.0000 0.1314 0.1199 0.0000 0.0000 0.0846 0.0000 0.2535 ... 0.0 0.0000 0.1411 0.0 0.0 0.2385 0.0000 0.2026 0.1051 0.0
2016-12-13 0.0000 0.1559 0.0000 0.1286 0.1186 0.0000 0.0000 0.0824 0.0000 0.2576 ... 0.0 0.0000 0.1421 0.0 0.0 0.2486 0.0000 0.2060 0.1042 0.0
2016-12-14 0.0000 0.1559 0.0000 0.1289 0.1201 0.0000 0.0000 0.0851 0.0000 0.2564 ... 0.0 0.0000 0.1434 0.0 0.0 0.2475 0.0000 0.2113 0.1028 0.0
2016-12-15 0.0000 0.1556 0.0000 0.1290 0.1203 0.0000 0.0000 0.0842 0.0000 0.2528 ... 0.0 0.0000 0.1413 0.0 0.0 0.2490 0.0000 0.2125 0.1035 0.0
2016-12-16 0.0000 0.1604 0.0000 0.1289 0.1198 0.0000 0.0000 0.0838 0.0000 0.2637 ... 0.0 0.0000 0.1429 0.0 0.0 0.2474 0.0000 0.2130 0.1034 0.0
2016-12-19 0.0000 0.1610 0.0000 0.1295 0.1209 0.0000 0.0000 0.0844 0.0000 0.2697 ... 0.0 0.0000 0.1415 0.0 0.0 0.2459 0.0000 0.2109 0.1040 0.0
2016-12-20 0.0000 0.1584 0.0000 0.1280 0.1206 0.0000 0.0000 0.0846 0.0000 0.2696 ... 0.0 0.0000 0.1444 0.0 0.0 0.2458 0.0000 0.2136 0.1039 0.0
2016-12-21 0.0000 0.1601 0.0000 0.1289 0.1198 0.0000 0.0000 0.0832 0.0000 0.2671 ... 0.0 0.0000 0.1444 0.0 0.0 0.2465 0.0000 0.2130 0.1035 0.0
2016-12-22 0.0000 0.1598 0.0000 0.1288 0.1199 0.0000 0.0000 0.0828 0.0000 0.2653 ... 0.0 0.0000 0.1458 0.0 0.0 0.2448 0.0000 0.2123 0.1026 0.0
2016-12-23 0.0000 0.1594 0.0000 0.1283 0.1203 0.0000 0.0000 0.0875 0.0000 0.2713 ... 0.0 0.0000 0.1529 0.0 0.0 0.2450 0.0000 0.2101 0.1025 0.0
2016-12-26 0.0000 0.1434 0.0000 0.1280 0.1230 0.0000 0.0000 0.0859 0.0000 0.2746 ... 0.0 0.0000 0.1544 0.0 0.0 0.2474 0.0000 0.2086 0.1026 0.0
2016-12-27 0.0000 0.1451 0.0000 0.1291 0.1246 0.0000 0.0000 0.0868 0.0000 0.2738 ... 0.0 0.0000 0.1506 0.0 0.0 0.2470 0.0000 0.2076 0.1035 0.0
2016-12-28 0.0000 0.1453 0.0000 0.1292 0.1257 0.0000 0.0000 0.0872 0.0000 0.2814 ... 0.0 0.0000 0.1497 0.0 0.0 0.2472 0.0000 0.2097 0.1029 0.0
2016-12-29 0.0000 0.1457 0.0000 0.1285 0.1252 0.0000 0.0000 0.0863 0.0000 0.2786 ... 0.0 0.0000 0.1497 0.0 0.0 0.2479 0.0000 0.2116 0.1033 0.0
2016-12-30 0.0000 0.1479 0.0000 0.1297 0.1262 0.0000 0.0000 0.0867 0.0000 0.2731 ... 0.0 0.0000 0.1561 0.0 0.0 0.2486 0.0000 0.2133 0.1057 0.0

1214 rows × 1071 columns


In [70]:
riskExposureDF = pd.concat(map(lambda x: x.iloc[-1], factordic .values()), axis=1)

In [71]:
factordic .values()[3].iloc[-1].head()


Out[71]:
600507.SH    0.116149
002344.SZ   -0.233700
000793.SZ    0.247426
300039.SZ   -0.350758
600059.SH   -0.355085
Name: 2016-12-30 00:00:00, dtype: float64

In [72]:
# note that dictionary is not  used in the given order, so make sure keys pair the values!
factordic.keys()


Out[72]:
['YOYBPS', 'LFCA', 'PB', 'AMOUNTAVG1MData', 'PROFITOOP', 'TURNOVER1M']

In [73]:
riskExposureDF.columns= factordic.keys()

In [74]:
riskExposureDF.head()


Out[74]:
YOYBPS LFCA PB AMOUNTAVG1MData PROFITOOP TURNOVER1M
600507.SH 0.340788 -0.469033 -0.029513 0.116149 0.022185 0.396599
002344.SZ 0.146407 -0.094015 -0.033699 -0.233700 0.475590 -0.224775
000793.SZ 0.103897 0.469627 -0.032676 0.247426 0.328214 0.206770
300039.SZ 0.148159 -0.867833 -0.028938 -0.350758 0.231069 -0.123416
600059.SH 0.038965 -0.560382 -0.033503 -0.355085 0.037209 -0.329140

In [75]:
## Only conserve the diagonal element 
spEwmMatrix = calEWMcovariance(specificReturn[-200:],decay=0.94)
tempo = spEwmMatrix .copy()
digVal = np.diag(spEwmMatrix)
a = np.fill_diagonal(tempo.values ,0)
finalSpMat = spEwmMatrix -tempo

In [76]:
finalSpMat.head()


Out[76]:
600507.SH 002344.SZ 000793.SZ 300039.SZ 600059.SH 600501.SH 000713.SZ 002233.SZ 600360.SH 600565.SH ... 600150.SH 600469.SH 600282.SH 600739.SH 600406.SH 600687.SH 600866.SH 000860.SZ 601908.SH 002195.SZ
600507.SH 0.000776 0.000000 0.000000 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
002344.SZ 0.000000 0.000232 0.000000 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
000793.SZ 0.000000 0.000000 0.000292 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
300039.SZ 0.000000 0.000000 0.000000 0.000068 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
600059.SH 0.000000 0.000000 0.000000 0.000000 0.000076 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

5 rows × 1071 columns


In [77]:
# calculate monthly specific risk of the market index
alphaSP =  reduce(lambda x,y: x.dot(y),[benchmarkWeight.iloc[-1], finalSpMat, benchmarkWeight.iloc[-1].T ])

In [78]:
alphaSP


Out[78]:
0.0056262027636875909

In [79]:
# calculate adjusted factor covriance matrix
def calFinlCov(ewmMatrix, benchMarkWeight, benchMarkRet, riskExposureDF, finalSpMat, compara=1/0.94 - 1):
    '''
    To calculate final to optimize covriance, with factor covriance matrix adjusted by Barra method, 
    P32 ,chapter-2,Barra Risk Model Handbook.
    
    Output: Dataframe, namely adjusted factor covriance matrix(k*k, k is the factor amount).
    
    Inpput:
    ewmMatrix: Dataframe, the factor covriance matrix calculated directell by the outcome of multiFactorReg.
    benchMarkWeight: Dataframe or Series, benchMarkWeight of the stocks on a given date!.
    benchMarkRet: Dataframe or Series, notice the index !
    riskExposureDF: Dataframe , riskExposureDF of stocks on factors in specific date.
    finalSpMat: Dataframe, the digonal covriance matrix of specific returns.
    '''
    
    # calculate monthly scaled variance  forecast for the market index by DEWIV
    alphaS = 21*benchMarkRet.ewm(ignore_na=True, min_periods=0, com=compara).cov(pairwise = True)[-200:].iloc[-1]
    # calculate monthly specific risk of the market index
    alphaSP =  reduce(lambda x,y: x.dot(y),[benchMarkWeight, finalSpMat, benchMarkWeight.T ]) 
    # calculate total variance of the market index
    alphaM = (reduce(lambda x,y: x.dot(y),[benchMarkWeight, riskExposureDF, ewmMatrix, riskExposureDF.T, benchMarkWeight.T ])\
    +alphaSP)  
    # can not use np.dot on two series to construct a matrix 
    benchMarkWeightDF = pd.DataFrame(benchMarkWeight) 
    lastPart =  reduce(lambda x,y: x.dot(y),[ewmMatrix, riskExposureDF.T, benchMarkWeightDF, \
                                         benchMarkWeightDF.T, riskExposureDF,ewmMatrix ])
    finalCovMatrix = ewmMatrix + ((alphaS - alphaM)/(alphaS - alphaSP)) * lastPart
    return finalCovMatrix

In [80]:
calFinlCov(ewmMatrix, benchmarkWeight.iloc[-1], returnOfBench, riskExposureDF, finalSpMat, compara=1/0.94 - 1)


Out[80]:
LFCA PB YOYBPS AMOUNTAVG1MData TURNOVER1M PROFITOOP
LFCA 1.467257e-07 0.000007 -6.467844e-07 -3.561044e-07 -9.388647e-07 1.981803e-08
PB 7.089570e-06 0.000491 -4.578150e-05 -2.320465e-05 -5.793758e-05 1.374818e-06
YOYBPS -6.467844e-07 -0.000046 4.285751e-06 2.166568e-06 5.390764e-06 -1.285029e-07
AMOUNTAVG1MData -3.561044e-07 -0.000023 2.166568e-06 1.114499e-06 2.803689e-06 -6.511143e-08
TURNOVER1M -9.388647e-07 -0.000058 5.390764e-06 2.803689e-06 7.110081e-06 -1.626258e-07
PROFITOOP 1.981803e-08 0.000001 -1.285029e-07 -6.511143e-08 -1.626258e-07 3.887640e-09

In [81]:
# calculate total variance of the market index
alphaM = reduce(lambda x,y: x.dot(y),[benchmarkWeight.iloc[-1], riskExposureDF, ewmMatrix, riskExposureDF.T, benchmarkWeight.iloc[-1].T ])+alphaSP

In [82]:
alphaM


Out[82]:
0.0090002235911027344

In [83]:
ewmMatrix


Out[83]:
LFCA PB YOYBPS AMOUNTAVG1MData TURNOVER1M PROFITOOP
LFCA 1.461664e-07 0.000007 -6.431792e-07 -3.542772e-07 -9.343010e-07 1.970972e-08
PB 7.050887e-06 0.000488 -4.553217e-05 -2.307828e-05 -5.762197e-05 1.367327e-06
YOYBPS -6.431792e-07 -0.000046 4.262513e-06 2.154790e-06 5.361348e-06 -1.278048e-07
AMOUNTAVG1MData -3.542772e-07 -0.000023 2.154790e-06 1.108529e-06 2.788780e-06 -6.475759e-08
TURNOVER1M -9.343010e-07 -0.000058 5.361348e-06 2.788780e-06 7.072846e-06 -1.617420e-07
PROFITOOP 1.970972e-08 0.000001 -1.278048e-07 -6.475759e-08 -1.617420e-07 3.866666e-09

In [84]:
# can not use np.dot on two series to construct a matrix 
benchmarkWeightDF = pd.DataFrame(benchmarkWeight.iloc[-1])

In [85]:
lastPart =  reduce(lambda x,y: x.dot(y),[ewmMatrix, riskExposureDF.T, benchmarkWeightDF, \
                                         benchmarkWeightDF.T, riskExposureDF,ewmMatrix ])
lastPart


Out[85]:
LFCA PB YOYBPS AMOUNTAVG1MData TURNOVER1M PROFITOOP
LFCA 3.444220e-10 2.381932e-08 -2.219976e-09 -1.125144e-09 -2.810122e-09 6.669474e-11
PB 2.381932e-08 1.647282e-06 -1.535277e-07 -7.781202e-08 -1.943407e-07 4.612433e-09
YOYBPS -2.219976e-09 -1.535277e-07 1.430889e-08 7.252131e-09 1.811268e-08 -4.298818e-10
AMOUNTAVG1MData -1.125144e-09 -7.781202e-08 7.252131e-09 3.675576e-09 9.179995e-09 -2.178757e-10
TURNOVER1M -2.810122e-09 -1.943407e-07 1.811268e-08 9.179995e-09 2.292765e-08 -5.441591e-10
PROFITOOP 6.669474e-11 4.612433e-09 -4.298818e-10 -2.178757e-10 -5.441591e-10 1.291494e-11

In [86]:
finalCovMatrix = ewmMatrix + ((alphaS - alphaM)/(alphaS - alphaSP)) * lastPart
finalCovMatrix


Out[86]:
LFCA PB YOYBPS AMOUNTAVG1MData TURNOVER1M PROFITOOP
LFCA 1.467257e-07 0.000007 -6.467844e-07 -3.561044e-07 -9.388647e-07 1.981803e-08
PB 7.089570e-06 0.000491 -4.578150e-05 -2.320465e-05 -5.793758e-05 1.374818e-06
YOYBPS -6.467844e-07 -0.000046 4.285751e-06 2.166568e-06 5.390764e-06 -1.285029e-07
AMOUNTAVG1MData -3.561044e-07 -0.000023 2.166568e-06 1.114499e-06 2.803689e-06 -6.511143e-08
TURNOVER1M -9.388647e-07 -0.000058 5.390764e-06 2.803689e-06 7.110081e-06 -1.626258e-07
PROFITOOP 1.981803e-08 0.000001 -1.285029e-07 -6.511143e-08 -1.626258e-07 3.887640e-09

In [87]:
stocks = pd.read_csv(path+ZZ500Weight,infer_datetime_format=True,parse_dates=[0],index_col=0)[stkPool].loc[startTime:endTime].iloc[-1].dropna()

optStkPool = stocks.index.tolist()

riskExposureDFSlice = riskExposureDF.loc[optStkPool]

In [88]:
# final covriance to optimize
toOptCov = reduce(lambda x,y: x.dot(y),[riskExposureDFSlice,finalCovMatrix,riskExposureDFSlice.T])

In [89]:
toOptCov


Out[89]:
002344.SZ 300039.SZ 600059.SH 002233.SZ 600565.SH 600801.SH 000528.SZ 000723.SZ 000685.SZ 002431.SZ ... 000012.SZ 600022.SH 002437.SZ 600073.SH 600525.SH 600122.SH 600282.SH 600687.SH 000860.SZ 601908.SH
002344.SZ 6.460456e-08 1.054781e-07 -3.635383e-08 8.249420e-08 8.404245e-07 1.959745e-08 -4.338544e-08 4.078532e-07 -7.834363e-08 2.511564e-08 ... 1.104231e-06 1.501189e-07 -7.850254e-07 1.463089e-07 -3.144649e-07 4.168979e-07 3.672855e-07 -4.345615e-07 4.446826e-07 -2.259915e-07
300039.SZ 1.054781e-07 2.785994e-07 -1.238236e-07 2.176346e-07 2.276208e-06 3.622027e-08 -1.417371e-07 1.193585e-06 -2.497035e-07 2.294765e-07 ... 2.983450e-06 2.822928e-07 -2.046447e-06 3.465552e-07 -9.378182e-07 1.073706e-06 9.243146e-07 -1.277256e-06 1.123656e-06 -6.918584e-07
600059.SH -3.635383e-08 -1.238236e-07 6.868357e-08 -9.501833e-08 -1.075193e-06 -7.678861e-09 7.732528e-08 -5.667941e-07 1.283347e-07 -1.234732e-07 ... -1.411022e-06 -1.173224e-07 9.624513e-07 -1.528156e-07 4.596504e-07 -4.978370e-07 -4.260256e-07 6.213863e-07 -5.172608e-07 3.424973e-07
002233.SZ 8.249420e-08 2.176346e-07 -9.501833e-08 1.703147e-07 1.768120e-06 2.939358e-08 -1.088695e-07 9.290338e-07 -1.930939e-07 1.799086e-07 ... 2.316976e-06 2.188152e-07 -1.588236e-06 2.698256e-07 -7.277927e-07 8.342274e-07 7.180025e-07 -9.915936e-07 8.730965e-07 -5.367390e-07
600565.SH 8.404245e-07 2.276208e-06 -1.075193e-06 1.768120e-06 1.893888e-05 2.557260e-07 -1.226006e-06 9.893991e-06 -2.116198e-06 1.899380e-06 ... 2.483830e-05 2.330201e-06 -1.705131e-05 2.849441e-06 -7.848893e-06 8.912295e-06 7.671165e-06 -1.067271e-05 9.318714e-06 -5.800556e-06
600801.SH 1.959745e-08 3.622027e-08 -7.678861e-09 2.939358e-08 2.557260e-07 9.924237e-09 -9.559740e-09 1.333725e-07 -2.186195e-08 1.824583e-08 ... 3.339510e-07 4.036748e-08 -2.315458e-07 4.528100e-08 -9.578106e-08 1.259012e-07 1.097190e-07 -1.332059e-07 1.338592e-07 -6.868823e-08
000528.SZ -4.338544e-08 -1.417371e-07 7.732528e-08 -1.088695e-07 -1.226006e-06 -9.559740e-09 8.718914e-08 -6.445987e-07 1.451257e-07 -1.371807e-07 ... -1.608973e-06 -1.367917e-07 1.099062e-06 -1.757021e-07 5.217304e-07 -5.691335e-07 -4.875716e-07 7.058313e-07 -5.919477e-07 3.883078e-07
000723.SZ 4.078532e-07 1.193585e-06 -5.667941e-07 9.290338e-07 9.893991e-06 1.333725e-07 -6.445987e-07 5.225706e-06 -1.118672e-06 1.084072e-06 ... 1.296892e-05 1.151916e-06 -8.858714e-06 1.467772e-06 -4.139092e-06 4.629386e-06 3.972260e-06 -5.622268e-06 4.829475e-06 -3.065855e-06
000685.SZ -7.834363e-08 -2.497035e-07 1.283347e-07 -1.930939e-07 -2.116198e-06 -2.186195e-08 1.451257e-07 -1.118672e-06 2.463753e-07 -2.406042e-07 ... -2.775280e-06 -2.363479e-07 1.892862e-06 -3.066811e-07 8.962857e-07 -9.841202e-07 -8.428248e-07 1.214339e-06 -1.024240e-06 6.661207e-07
002431.SZ 2.511564e-08 2.294765e-07 -1.234732e-07 1.799086e-07 1.899380e-06 1.824583e-08 -1.371807e-07 1.084072e-06 -2.406042e-07 3.463685e-07 ... 2.481274e-06 1.188346e-07 -1.629369e-06 2.448234e-07 -8.605405e-07 8.450084e-07 7.059468e-07 -1.157337e-06 8.633488e-07 -6.494078e-07
002038.SZ -2.004649e-07 -6.144798e-07 3.038704e-07 -4.767860e-07 -5.149483e-06 -6.122262e-08 3.445181e-07 -2.722593e-06 5.913002e-07 -5.776255e-07 ... -6.751381e-06 -5.853919e-07 4.606840e-06 -7.543999e-07 2.168861e-06 -2.401233e-06 -2.058110e-06 2.942046e-06 -2.501709e-06 1.609424e-06
000636.SZ 1.971963e-08 5.553015e-08 -1.965997e-08 4.438953e-08 4.216838e-07 1.050615e-08 -2.273804e-08 2.295677e-07 -4.426203e-08 5.198139e-08 ... 5.507975e-07 4.770808e-08 -3.724665e-07 6.508774e-08 -1.735355e-07 1.981980e-07 1.695515e-07 -2.372037e-07 2.070660e-07 -1.278279e-07
000513.SZ 7.209053e-08 5.558119e-08 -4.281338e-09 4.336945e-08 4.180020e-07 1.852357e-08 -8.492361e-09 1.495994e-07 -1.790700e-08 -8.284577e-08 ... 5.538668e-07 1.472638e-07 -4.380783e-07 1.011932e-07 -1.068708e-07 2.394592e-07 2.235912e-07 -1.582458e-07 2.679772e-07 -6.656530e-08
300291.SZ 1.626306e-07 3.063651e-07 -1.225483e-07 2.383609e-07 2.500034e-06 4.689895e-08 -1.432625e-07 1.241302e-06 -2.511891e-07 1.321344e-07 ... 3.283888e-06 3.991943e-07 -2.309179e-06 4.132638e-07 -9.720314e-07 1.217587e-06 1.064687e-06 -1.334374e-06 1.290024e-06 -7.063443e-07
600640.SH -2.116709e-07 -6.101982e-07 2.991829e-07 -4.730031e-07 -5.119373e-06 -6.199164e-08 3.399150e-07 -2.686492e-06 5.820974e-07 -5.405778e-07 ... -6.714155e-06 -6.065736e-07 4.597495e-06 -7.584561e-07 2.140834e-06 -2.397483e-06 -2.059565e-06 2.906567e-06 -2.502093e-06 1.585873e-06
000926.SZ -6.197428e-08 -1.424042e-07 7.083164e-08 -1.092735e-07 -1.221728e-06 -1.335296e-08 8.101370e-08 -6.167003e-07 1.348830e-07 -9.123595e-08 ... -1.605686e-06 -1.707569e-07 1.118079e-06 -1.883566e-07 4.966784e-07 -5.822658e-07 -5.052135e-07 6.761553e-07 -6.119224e-07 3.654656e-07
000960.SZ 2.843055e-07 7.166499e-07 -3.295704e-07 5.568569e-07 5.942523e-06 8.556144e-08 -3.772074e-07 3.078857e-06 -6.527362e-07 5.489383e-07 ... 7.795594e-06 7.675554e-07 -5.373330e-06 9.088903e-07 -2.437244e-06 2.812810e-06 2.427716e-06 -3.319152e-06 2.947809e-06 -1.796400e-06
600522.SH -2.878594e-07 -7.390626e-07 3.463728e-07 -5.734798e-07 -6.158054e-06 -8.424162e-08 3.958110e-07 -3.192742e-06 6.815066e-07 -5.771344e-07 ... -8.079068e-06 -7.869117e-07 5.565651e-06 -9.364809e-07 2.533989e-06 -2.910099e-06 -2.510275e-06 3.448643e-06 -3.047899e-06 1.869415e-06
002019.SZ -1.134096e-07 -1.566062e-07 6.053656e-08 -1.199923e-07 -1.315988e-06 -2.421999e-08 7.236189e-08 -6.011479e-07 1.208888e-07 1.408037e-08 ... -1.735208e-06 -2.692686e-07 1.260653e-06 -2.359793e-07 4.771682e-07 -6.647543e-07 -5.921926e-07 6.606497e-07 -7.138908e-07 3.401596e-07
000572.SZ 4.271084e-07 1.137645e-06 -5.310925e-07 8.843276e-07 9.440062e-06 1.316081e-07 -6.062588e-07 4.926128e-06 -1.049298e-06 9.333661e-07 ... 1.238037e-05 1.173343e-06 -8.504673e-06 1.426599e-06 -3.902123e-06 4.448368e-06 3.830930e-06 -5.308453e-06 4.653672e-06 -2.881787e-06
600850.SH -3.856323e-07 -1.023553e-06 4.874950e-07 -7.937783e-07 -8.553029e-06 -1.121237e-07 5.560184e-07 -4.449264e-06 9.548786e-07 -8.308671e-07 ... -1.122040e-05 -1.069552e-06 7.716437e-06 -1.290225e-06 3.537085e-06 -4.030867e-06 -3.472959e-06 4.810054e-06 -4.217218e-06 2.612794e-06
600266.SH 4.804466e-08 4.808470e-08 -9.471751e-09 3.752857e-08 3.719798e-07 1.283179e-08 -1.293739e-08 1.543307e-07 -2.446408e-08 -3.555281e-08 ... 4.910626e-07 1.019527e-07 -3.708049e-07 7.855935e-08 -1.150783e-07 2.001651e-07 1.825510e-07 -1.641454e-07 2.196159e-07 -7.771837e-08
600586.SH -1.813304e-08 -6.042249e-08 3.770915e-08 -4.557323e-08 -5.502381e-07 -1.026928e-09 4.230551e-08 -2.842196e-07 6.734731e-08 -5.693212e-08 ... -7.234865e-07 -6.283355e-08 4.971065e-07 -7.730737e-08 2.357974e-07 -2.550364e-07 -2.189221e-07 3.180517e-07 -2.651445e-07 1.759200e-07
600835.SH -1.283764e-07 -4.459593e-07 2.280700e-07 -3.459190e-07 -3.753447e-06 -4.020023e-08 2.574154e-07 -2.006917e-06 4.406145e-07 -4.619723e-07 ... -4.919271e-06 -3.951464e-07 3.337730e-06 -5.371531e-07 1.602870e-06 -1.736118e-06 -1.482248e-06 2.170038e-06 -1.802892e-06 1.193477e-06
600298.SH -4.833136e-07 -1.212298e-06 5.658864e-07 -9.402856e-07 -1.010624e-05 -1.392438e-07 6.473026e-07 -5.221969e-06 1.113364e-06 -9.175745e-07 ... -1.326087e-05 -1.313130e-06 9.149438e-06 -1.544334e-06 4.145136e-06 -4.784924e-06 -4.131618e-06 5.643639e-06 -5.015205e-06 3.055526e-06
002640.SZ -2.813652e-07 -8.028408e-07 3.892662e-07 -6.229166e-07 -6.714407e-06 -8.427650e-08 4.426169e-07 -3.523493e-06 7.604024e-07 -7.057219e-07 ... -8.805408e-06 -7.995545e-07 6.030476e-06 -9.978659e-07 2.803219e-06 -3.146983e-06 -2.704025e-06 3.807216e-06 -3.285308e-06 2.075606e-06
601777.SH 6.310557e-07 1.695387e-06 -7.975495e-07 1.317171e-06 1.409520e-05 1.924050e-07 -9.098363e-07 7.358130e-06 -1.571604e-06 1.402569e-06 ... 1.848603e-05 1.743241e-06 -1.269546e-05 2.124826e-06 -5.834610e-06 6.637231e-06 5.714516e-06 -7.935252e-06 6.941656e-06 -4.310623e-06
000547.SZ -4.934297e-07 -1.393979e-06 6.723122e-07 -1.081864e-06 -1.164522e-05 -1.484552e-07 7.648685e-07 -6.106296e-06 1.315398e-06 -1.213869e-06 ... -1.527184e-05 -1.395159e-06 1.046353e-05 -1.734756e-06 4.855058e-06 -5.462135e-06 -4.694778e-06 6.595453e-06 -5.703917e-06 3.593572e-06
300113.SZ -2.721671e-07 -6.623086e-07 3.082013e-07 -5.132759e-07 -5.529165e-06 -7.639082e-08 3.529792e-07 -2.843191e-06 6.057982e-07 -4.796060e-07 ... -7.256743e-06 -7.344448e-07 5.017648e-06 -8.501180e-07 2.258214e-06 -2.624413e-06 -2.269100e-06 3.076105e-06 -2.753427e-06 1.662862e-06
600418.SH 2.882913e-07 6.826516e-07 -3.058488e-07 5.306217e-07 5.641733e-06 8.607663e-08 -3.513500e-07 2.900396e-06 -6.096014e-07 4.794407e-07 ... 7.402732e-06 7.610387e-07 -5.121775e-06 8.761199e-07 -2.291103e-06 2.685015e-06 2.323252e-06 -3.124706e-06 2.819842e-06 -1.684363e-06
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
600397.SH -1.593883e-07 -3.678970e-07 1.750890e-07 -2.837996e-07 -3.108139e-06 -3.962223e-08 2.006799e-07 -1.578814e-06 3.395465e-07 -2.419428e-07 ... -4.082438e-06 -4.306648e-07 2.836806e-06 -4.814662e-07 1.261475e-06 -1.481481e-06 -1.284444e-06 1.718874e-06 -1.556910e-06 9.275934e-07
600478.SH -5.722164e-07 -1.484602e-06 6.978722e-07 -1.152055e-06 -1.237244e-05 -1.680969e-07 7.970731e-07 -6.423295e-06 1.372311e-06 -1.174837e-06 ... -1.623120e-05 -1.569708e-06 1.117436e-05 -1.877160e-06 5.098785e-06 -5.841797e-06 -5.037194e-06 6.937801e-06 -6.116317e-06 3.762959e-06
600422.SH -3.875608e-07 -9.499363e-07 4.435595e-07 -7.361135e-07 -7.934679e-06 -1.086933e-07 5.077821e-07 -4.083544e-06 8.710791e-07 -6.947544e-07 ... -1.041364e-05 -1.048843e-06 7.197512e-06 -1.217769e-06 3.244407e-06 -3.763826e-06 -3.253337e-06 4.418702e-06 -3.947891e-06 2.389774e-06
601233.SH 3.899977e-07 9.699401e-07 -4.443699e-07 7.535917e-07 8.041526e-06 1.166957e-07 -5.089437e-07 4.158772e-06 -8.806476e-07 7.295966e-07 ... 1.054988e-05 1.048559e-06 -7.278033e-06 1.233630e-06 -3.291584e-06 3.810639e-06 3.290742e-06 -4.483840e-06 3.995296e-06 -2.424883e-06
600859.SH -5.292195e-07 -1.445724e-06 6.934977e-07 -1.121420e-06 -1.208426e-05 -1.557562e-07 7.899842e-07 -6.308817e-06 1.356973e-06 -1.213190e-06 ... -1.585068e-05 -1.481703e-06 1.088227e-05 -1.811961e-06 5.016787e-06 -5.682343e-06 -4.890413e-06 6.818751e-06 -5.939805e-06 3.709417e-06
002439.SZ -4.770728e-08 -1.771215e-07 9.336035e-08 -1.371256e-07 -1.501784e-06 -1.429546e-08 1.050992e-07 -8.055759e-07 1.787075e-07 -1.909921e-07 ... -1.968315e-06 -1.527626e-07 1.332863e-06 -2.121113e-07 6.458528e-07 -6.919123e-07 -5.898163e-07 8.733332e-07 -7.173915e-07 4.817506e-07
002353.SZ 7.442288e-07 2.011742e-06 -9.490577e-07 1.562799e-06 1.673365e-05 2.267406e-07 -1.082316e-06 8.740720e-06 -1.868723e-06 1.675329e-06 ... 2.194613e-05 2.061290e-06 -1.506713e-05 2.518940e-06 -6.932908e-06 7.875812e-06 6.779398e-06 -9.427664e-06 8.235492e-06 -5.123223e-06
300136.SZ -1.217496e-07 -2.829389e-07 1.265803e-07 -2.197938e-07 -2.341008e-06 -3.571301e-08 1.455281e-07 -1.199579e-06 2.520633e-07 -1.926390e-07 ... -3.072210e-06 -3.202867e-07 2.128633e-06 -3.649527e-07 9.480471e-07 -1.115941e-06 -9.664463e-07 1.293400e-06 -1.172718e-06 6.964964e-07
000937.SZ 4.315359e-07 1.078368e-06 -4.982076e-07 8.372310e-07 8.961765e-06 1.271336e-07 -5.702564e-07 4.633621e-06 -9.841418e-07 8.146569e-07 ... 1.175793e-05 1.165933e-06 -8.111192e-06 1.372122e-06 -3.672093e-06 4.244707e-06 3.665318e-06 -5.000954e-06 4.449586e-06 -2.706003e-06
600790.SH 1.436201e-06 3.883616e-06 -1.834378e-06 3.016575e-06 3.231637e-05 4.362884e-07 -2.091794e-06 1.687852e-05 -3.610132e-06 3.234454e-06 ... 4.238338e-05 3.980720e-06 -2.909909e-05 4.863569e-06 -1.339030e-05 1.520935e-05 1.309215e-05 -1.820816e-05 1.590371e-05 -9.895348e-06
600079.SH 1.630588e-08 -1.083973e-07 7.353535e-08 -8.429118e-08 -9.405483e-07 1.585604e-10 7.999802e-08 -5.684671e-07 1.357716e-07 -2.324648e-07 ... -1.226830e-06 -1.037129e-08 7.778978e-07 -1.002174e-07 4.617389e-07 -3.960124e-07 -3.215633e-07 6.140852e-07 -3.948837e-07 3.546558e-07
600160.SH 4.469022e-08 -2.332767e-08 3.244920e-08 -1.815149e-08 -2.324267e-07 9.245082e-09 3.334005e-08 -1.940385e-07 5.514491e-08 -1.536876e-07 ... -2.985846e-07 7.098706e-08 1.443299e-07 4.198549e-09 1.645011e-07 -6.527069e-08 -3.794298e-08 2.105871e-07 -5.008903e-08 1.342953e-07
600536.SH 1.123462e-07 3.174438e-07 -1.482774e-07 2.472470e-07 2.623205e-06 3.691943e-08 -1.689411e-07 1.381353e-06 -2.940633e-07 2.790269e-07 ... 3.438636e-06 3.122123e-07 -2.352604e-06 3.922817e-07 -1.092182e-06 1.230641e-06 1.057153e-06 -1.484674e-06 1.285173e-06 -8.080001e-07
002572.SZ 9.017617e-09 -1.559972e-07 9.984658e-08 -1.213292e-07 -1.342159e-06 -3.098871e-09 1.093093e-07 -7.926567e-07 1.861165e-07 -2.982800e-07 ... -1.752238e-06 -4.045649e-08 1.126637e-06 -1.531752e-07 6.412401e-07 -5.765020e-07 -4.733785e-07 8.557044e-07 -5.800941e-07 4.897378e-07
600088.SH -2.626710e-07 -7.070165e-07 3.407954e-07 -5.478352e-07 -5.925919e-06 -7.496682e-08 3.883023e-07 -3.084669e-06 6.648252e-07 -5.819004e-07 ... -7.774352e-06 -7.351016e-07 5.344043e-06 -8.903614e-07 2.456237e-06 -2.789527e-06 -2.402464e-06 3.338774e-06 -2.917179e-06 1.815499e-06
600497.SH 1.139441e-06 3.107444e-06 -1.478836e-06 2.412394e-06 2.590724e-05 3.423111e-07 -1.685291e-06 1.353579e-05 -2.902789e-06 2.608888e-06 ... 3.397876e-05 3.176046e-06 -2.332239e-05 3.889485e-06 -1.074946e-05 1.218442e-05 1.048595e-05 -1.461328e-05 1.273717e-05 -7.946708e-06
600967.SH 2.980151e-07 8.036037e-07 -3.761964e-07 6.247468e-07 6.668287e-06 9.242402e-08 -4.292116e-07 3.485267e-06 -7.430335e-07 6.687758e-07 ... 8.744707e-06 8.217416e-07 -6.002714e-06 1.005169e-06 -2.760953e-06 3.139239e-06 2.702164e-06 -3.755183e-06 3.282893e-06 -2.039862e-06
600195.SH -4.161919e-08 -1.446838e-07 7.893670e-08 -1.113296e-07 -1.247062e-06 -9.854560e-09 8.888009e-08 -6.605914e-07 1.485897e-07 -1.473368e-07 ... -1.635960e-06 -1.336984e-07 1.113682e-06 -1.770668e-07 5.338097e-07 -5.767294e-07 -4.930437e-07 7.217485e-07 -5.989235e-07 3.978319e-07
000998.SZ 1.198593e-06 3.032885e-06 -1.408389e-06 2.354488e-06 2.522230e-05 3.534689e-07 -1.610950e-06 1.306036e-05 -2.778783e-06 2.328316e-06 ... 3.309055e-05 3.253354e-06 -2.281134e-05 3.850337e-06 -1.035457e-05 1.193394e-05 1.029973e-05 -1.409767e-05 1.250494e-05 -7.634186e-06
002327.SZ 1.981074e-07 5.598488e-07 -2.592240e-07 4.364674e-07 4.612728e-06 6.658542e-08 -2.954664e-07 2.431834e-06 -5.159902e-07 4.934362e-07 ... 6.045867e-06 5.480461e-07 -4.134673e-06 6.904894e-07 -1.919856e-06 2.164071e-06 1.858770e-06 -2.610255e-06 2.259955e-06 -1.420118e-06
000012.SZ 1.104231e-06 2.983450e-06 -1.411022e-06 2.316976e-06 2.483830e-05 3.339510e-07 -1.608973e-06 1.296892e-05 -2.775280e-06 2.481274e-06 ... 3.257657e-05 3.062159e-06 -2.236859e-05 3.738094e-06 -1.029129e-05 1.169051e-05 1.006370e-05 -1.399389e-05 1.222449e-05 -7.605173e-06
600022.SH 1.501189e-07 2.822928e-07 -1.173224e-07 2.188152e-07 2.330201e-06 4.036748e-08 -1.367917e-07 1.151916e-06 -2.363479e-07 1.188346e-07 ... 3.062159e-06 3.734951e-07 -2.155895e-06 3.834889e-07 -9.078212e-07 1.134330e-06 9.924526e-07 -1.245212e-06 1.201600e-06 -6.601466e-07
002437.SZ -7.850254e-07 -2.046447e-06 9.624513e-07 -1.588236e-06 -1.705131e-05 -2.315458e-07 1.099062e-06 -8.858714e-06 1.892862e-06 -1.629369e-06 ... -2.236859e-05 -2.155895e-06 1.539476e-05 -2.584648e-06 7.031427e-06 -8.047973e-06 -6.938073e-06 9.566790e-06 -8.424937e-06 5.190083e-06
600073.SH 1.463089e-07 3.465552e-07 -1.528156e-07 2.698256e-07 2.849441e-06 4.528100e-08 -1.757021e-07 1.467772e-06 -3.066811e-07 2.448234e-07 ... 3.738094e-06 3.834889e-07 -2.584648e-06 4.433314e-07 -1.156293e-06 1.356295e-06 1.173290e-06 -1.577531e-06 1.424452e-06 -8.498452e-07
600525.SH -3.144649e-07 -9.378182e-07 4.596504e-07 -7.277927e-07 -7.848893e-06 -9.578106e-08 5.217304e-07 -4.139092e-06 8.962857e-07 -8.605405e-07 ... -1.029129e-05 -9.078212e-07 7.031427e-06 -1.156293e-06 3.294759e-06 -3.667014e-06 -3.145888e-06 4.471507e-06 -3.823359e-06 2.442856e-06
600122.SH 4.168979e-07 1.073706e-06 -4.978370e-07 8.342274e-07 8.912295e-06 1.259012e-07 -5.691335e-07 4.629386e-06 -9.841202e-07 8.450084e-07 ... 1.169051e-05 1.134330e-06 -8.047973e-06 1.356295e-06 -3.667014e-06 4.210968e-06 3.631410e-06 -4.991564e-06 4.409989e-06 -2.705047e-06
600282.SH 3.672855e-07 9.243146e-07 -4.260256e-07 7.180025e-07 7.671165e-06 1.097190e-07 -4.875716e-07 3.972260e-06 -8.428248e-07 7.059468e-07 ... 1.006370e-05 9.924526e-07 -6.938073e-06 1.173290e-06 -3.145888e-06 3.631410e-06 3.134658e-06 -4.284116e-06 3.805836e-06 -2.318669e-06
600687.SH -4.345615e-07 -1.277256e-06 6.213863e-07 -9.915936e-07 -1.067271e-05 -1.332059e-07 7.058313e-07 -5.622268e-06 1.214339e-06 -1.157337e-06 ... -1.399389e-05 -1.245212e-06 9.566790e-06 -1.577531e-06 4.471507e-06 -4.991564e-06 -4.284116e-06 6.070478e-06 -5.206537e-06 3.313692e-06
000860.SZ 4.446826e-07 1.123656e-06 -5.172608e-07 8.730965e-07 9.318714e-06 1.338592e-07 -5.919477e-07 4.829475e-06 -1.024240e-06 8.633488e-07 ... 1.222449e-05 1.201600e-06 -8.424937e-06 1.424452e-06 -3.823359e-06 4.409989e-06 3.805836e-06 -5.206537e-06 4.621290e-06 -2.818329e-06
601908.SH -2.259915e-07 -6.918584e-07 3.424973e-07 -5.367390e-07 -5.800556e-06 -6.868823e-08 3.883078e-07 -3.065855e-06 6.661207e-07 -6.494078e-07 ... -7.605173e-06 -6.601466e-07 5.190083e-06 -8.498452e-07 2.442856e-06 -2.705047e-06 -2.318669e-06 3.313692e-06 -2.818329e-06 1.812716e-06

455 rows × 455 columns


In [90]:
# optimize 
factorNum = riskExposureDFSlice.shape[1]
stkNum = toOptCov.shape[1]
P = cv.matrix(toOptCov.values)
q = cv.matrix(0.0, (stkNum, 1))
G = cv.matrix(np.concatenate((riskExposureDFSlice.T.values, np.diag(np.ones(stkNum)), - np.diag(np.ones(stkNum)))))
h = cv.matrix(reduce(lambda x,y : np.append(x,y),[0.01 * np.ones(factorNum),0.005 * np.ones(stkNum), np.zeros(stkNum)]))
A = cv.matrix(np.ones(stkNum)).T
b = cv.matrix(1.0).T
sol = solvers.qp(P, q, G, h, A, b)


     pcost       dcost       gap    pres   dres
 0:  2.5034e-07 -2.4052e+00  1e+03  3e+01  4e+01
 1:  9.1761e-06 -2.5895e+00  4e+01  1e+00  2e+00
 2:  4.6722e-08 -2.2694e+00  3e+00  4e-02  5e-02
 3:  7.3297e-08 -2.7486e-01  3e-01  2e-04  3e-04
 4:  7.3431e-08 -2.7620e-03  3e-03  2e-06  3e-06
 5:  7.2726e-08 -3.9199e-05  4e-05  3e-08  4e-08
 6:  4.3407e-08 -4.8314e-06  5e-06  4e-09  5e-09
 7:  9.9927e-09 -9.2092e-07  9e-07  6e-10  8e-10
 8:  3.6460e-09 -2.3577e-07  2e-07  3e-16  3e-21
 9:  3.0658e-09 -4.2605e-08  5e-08  9e-16  3e-21
Optimal solution found.

In [91]:
print sol['x']


[ 2.01e-03]
[ 2.25e-03]
[ 2.39e-03]
[ 2.30e-03]
[ 1.47e-03]
[ 2.35e-03]
[ 2.41e-03]
[ 2.29e-03]
[ 2.25e-03]
[ 3.02e-03]
[ 2.35e-03]
[ 2.42e-03]
[ 1.83e-03]
[ 1.75e-03]
[ 2.61e-03]
[ 2.61e-03]
[ 1.85e-03]
[ 2.92e-03]
[ 3.14e-03]
[ 1.81e-03]
[ 3.06e-03]
[ 2.00e-03]
[ 2.43e-03]
[ 2.21e-03]
[ 3.36e-03]
[ 2.68e-03]
[ 1.61e-03]
[ 2.89e-03]
[ 3.05e-03]
[ 1.72e-03]
[ 1.92e-03]
[ 2.40e-03]
[ 1.42e-03]
[ 2.01e-03]
[ 2.11e-03]
[ 2.72e-03]
[ 2.30e-03]
[ 2.15e-03]
[ 2.24e-03]
[ 2.47e-03]
[ 1.09e-03]
[ 1.84e-03]
[ 2.23e-03]
[ 2.90e-03]
[ 2.16e-03]
[ 1.33e-03]
[ 2.09e-03]
[ 2.52e-03]
[ 1.44e-03]
[ 2.39e-03]
[ 1.97e-03]
[ 2.15e-03]
[ 2.52e-03]
[ 2.10e-03]
[ 3.03e-03]
[ 3.00e-03]
[ 1.33e-03]
[ 2.62e-03]
[ 2.28e-03]
[ 1.28e-03]
[ 2.76e-03]
[ 2.35e-03]
[ 1.93e-03]
[ 2.38e-03]
[ 2.83e-03]
[ 2.21e-03]
[ 2.58e-03]
[ 1.94e-03]
[ 1.89e-03]
[ 1.63e-03]
[ 2.68e-03]
[ 1.44e-03]
[ 2.07e-03]
[ 2.03e-03]
[ 1.62e-03]
[ 8.58e-04]
[ 2.22e-03]
[ 2.40e-03]
[ 1.49e-03]
[ 2.17e-03]
[ 2.10e-03]
[ 8.01e-04]
[ 1.07e-03]
[ 2.47e-03]
[ 1.88e-03]
[ 2.48e-03]
[ 2.68e-03]
[ 2.06e-03]
[ 2.42e-03]
[ 2.41e-03]
[ 2.33e-03]
[ 2.81e-03]
[ 3.43e-03]
[ 1.97e-03]
[ 2.86e-03]
[ 1.63e-03]
[ 2.16e-03]
[ 2.28e-03]
[ 1.97e-03]
[ 2.52e-03]
[ 2.39e-03]
[ 3.33e-03]
[ 1.12e-03]
[ 1.05e-03]
[ 2.70e-03]
[ 2.18e-03]
[ 2.54e-03]
[ 2.18e-03]
[ 2.20e-03]
[ 1.79e-03]
[ 1.61e-03]
[ 2.65e-03]
[ 2.27e-03]
[ 2.38e-03]
[ 2.81e-03]
[ 2.27e-03]
[ 2.68e-03]
[ 1.33e-03]
[ 2.54e-03]
[ 1.82e-03]
[ 2.80e-03]
[ 2.15e-03]
[ 3.33e-03]
[ 2.53e-03]
[ 2.74e-03]
[ 2.14e-03]
[ 2.17e-03]
[ 1.57e-03]
[ 1.42e-03]
[ 2.42e-03]
[ 2.05e-03]
[ 2.40e-03]
[ 2.25e-03]
[ 2.83e-03]
[ 2.44e-03]
[ 2.03e-03]
[ 2.19e-03]
[ 2.43e-03]
[ 1.20e-03]
[ 1.78e-03]
[ 1.74e-03]
[ 2.20e-03]
[ 2.88e-03]
[ 3.18e-03]
[ 2.45e-03]
[ 1.73e-03]
[ 1.84e-03]
[ 9.27e-04]
[ 1.84e-03]
[ 3.12e-03]
[ 2.75e-03]
[ 2.09e-03]
[ 2.39e-03]
[ 1.76e-03]
[ 2.53e-03]
[ 2.79e-03]
[ 1.82e-03]
[ 2.90e-03]
[ 1.72e-03]
[ 2.19e-03]
[ 2.23e-03]
[ 2.33e-03]
[ 3.19e-03]
[ 1.94e-03]
[ 2.25e-03]
[ 2.28e-03]
[ 2.25e-03]
[ 3.12e-03]
[ 1.29e-03]
[ 3.38e-03]
[ 2.79e-03]
[ 3.30e-03]
[ 2.82e-03]
[ 1.29e-03]
[ 1.68e-03]
[ 3.42e-03]
[ 2.49e-03]
[ 1.75e-03]
[ 1.90e-03]
[ 2.21e-03]
[ 2.38e-03]
[ 1.95e-03]
[ 1.07e-03]
[ 2.06e-03]
[ 3.24e-03]
[ 2.69e-03]
[ 2.55e-03]
[ 2.19e-03]
[ 2.05e-03]
[ 2.41e-03]
[ 2.19e-03]
[ 2.00e-03]
[ 2.53e-03]
[ 1.98e-03]
[ 1.47e-03]
[ 2.54e-03]
[ 2.18e-03]
[ 2.71e-03]
[ 1.81e-03]
[ 2.55e-03]
[ 2.36e-03]
[ 2.28e-03]
[ 2.25e-03]
[ 2.07e-03]
[ 2.51e-03]
[ 2.40e-03]
[ 2.17e-03]
[ 2.62e-03]
[ 1.77e-03]
[ 2.42e-03]
[ 1.92e-03]
[ 2.61e-03]
[ 2.59e-03]
[ 2.15e-03]
[ 2.71e-03]
[ 2.36e-03]
[ 2.27e-03]
[ 2.52e-03]
[ 2.92e-03]
[ 2.09e-03]
[ 1.98e-03]
[ 2.15e-03]
[ 2.01e-03]
[ 2.08e-03]
[ 3.02e-03]
[ 2.38e-03]
[ 2.76e-03]
[ 1.68e-03]
[ 2.21e-03]
[ 1.41e-03]
[ 2.56e-03]
[ 2.00e-03]
[ 2.37e-03]
[ 2.39e-03]
[ 2.13e-03]
[ 1.33e-03]
[ 7.64e-04]
[ 2.24e-03]
[ 1.97e-03]
[ 2.68e-03]
[ 9.39e-04]
[ 2.42e-03]
[ 2.77e-03]
[ 1.07e-03]
[ 3.40e-03]
[ 2.72e-03]
[ 1.97e-03]
[ 1.72e-03]
[ 2.64e-03]
[ 2.47e-03]
[ 9.82e-04]
[ 2.40e-03]
[ 2.28e-03]
[ 2.78e-03]
[ 2.65e-03]
[ 1.92e-03]
[ 2.02e-03]
[ 2.30e-03]
[ 2.03e-03]
[ 2.06e-03]
[ 2.56e-03]
[ 2.72e-03]
[ 1.88e-03]
[ 2.50e-03]
[ 1.35e-03]
[ 1.61e-03]
[ 2.43e-03]
[ 1.29e-03]
[ 1.58e-03]
[ 1.59e-03]
[ 9.84e-04]
[ 2.27e-03]
[ 2.10e-03]
[ 2.62e-03]
[ 2.43e-03]
[ 2.49e-03]
[ 2.26e-03]
[ 2.25e-03]
[ 2.49e-03]
[ 2.15e-03]
[ 1.51e-03]
[ 1.75e-03]
[ 2.72e-03]
[ 1.34e-03]
[ 1.37e-03]
[ 2.71e-03]
[ 2.52e-03]
[ 2.84e-03]
[ 1.57e-03]
[ 2.12e-03]
[ 3.06e-03]
[ 2.32e-03]
[ 2.28e-03]
[ 1.62e-03]
[ 2.28e-03]
[ 2.16e-03]
[ 1.49e-03]
[ 2.32e-03]
[ 2.41e-03]
[ 2.37e-03]
[ 1.53e-03]
[ 2.56e-03]
[ 3.11e-03]
[ 2.32e-03]
[ 1.53e-03]
[ 2.14e-03]
[ 2.33e-03]
[ 1.73e-03]
[ 2.05e-03]
[ 2.75e-03]
[ 2.22e-03]
[ 2.52e-03]
[ 1.88e-03]
[ 2.61e-03]
[ 7.67e-04]
[ 1.84e-03]
[ 1.70e-03]
[ 2.39e-03]
[ 2.40e-03]
[ 2.41e-03]
[ 2.24e-03]
[ 2.91e-03]
[ 1.76e-03]
[ 3.22e-03]
[ 2.43e-03]
[ 1.38e-03]
[ 2.16e-03]
[ 2.69e-03]
[ 1.89e-03]
[ 3.61e-03]
[ 2.42e-03]
[ 2.61e-03]
[ 2.38e-03]
[ 2.64e-03]
[ 1.70e-03]
[ 2.19e-03]
[ 2.27e-03]
[ 1.50e-03]
[ 1.96e-03]
[ 2.52e-03]
[ 3.01e-03]
[ 2.57e-03]
[ 2.51e-03]
[ 2.16e-03]
[ 1.94e-03]
[ 1.86e-03]
[ 1.90e-03]
[ 1.51e-03]
[ 2.49e-03]
[ 2.16e-03]
[ 2.23e-03]
[ 2.11e-03]
[ 2.52e-03]
[ 1.18e-03]
[ 1.42e-03]
[ 1.11e-03]
[ 2.43e-03]
[ 1.74e-03]
[ 1.36e-03]
[ 2.78e-03]
[ 7.76e-04]
[ 1.52e-03]
[ 1.68e-03]
[ 1.84e-03]
[ 3.23e-03]
[ 1.44e-03]
[ 1.28e-03]
[ 2.42e-03]
[ 2.62e-03]
[ 1.67e-03]
[ 3.21e-03]
[ 2.17e-03]
[ 2.24e-03]
[ 2.30e-03]
[ 2.22e-03]
[ 1.93e-03]
[ 2.46e-03]
[ 1.99e-03]
[ 2.53e-03]
[ 2.26e-03]
[ 2.87e-03]
[ 1.86e-03]
[ 2.15e-03]
[ 2.98e-03]
[ 2.38e-03]
[ 2.42e-03]
[ 2.47e-03]
[ 1.76e-03]
[ 1.89e-03]
[ 2.16e-03]
[ 2.07e-03]
[ 2.19e-03]
[ 2.92e-03]
[ 1.58e-03]
[ 3.59e-03]
[ 2.57e-03]
[ 1.43e-03]
[ 1.86e-03]
[ 2.31e-03]
[ 1.53e-03]
[ 2.47e-03]
[ 2.13e-03]
[ 2.22e-03]
[ 2.34e-03]
[ 1.78e-03]
[ 2.13e-03]
[ 2.11e-03]
[ 2.14e-03]
[ 2.04e-03]
[ 2.09e-03]
[ 1.10e-03]
[ 3.21e-03]
[ 1.19e-03]
[ 2.50e-03]
[ 2.78e-03]
[ 2.39e-03]
[ 2.31e-03]
[ 2.51e-03]
[ 2.10e-03]
[ 1.61e-03]
[ 3.49e-03]
[ 2.44e-03]
[ 2.02e-03]
[ 9.73e-04]
[ 2.61e-03]
[ 2.98e-03]
[ 3.41e-03]
[ 3.29e-03]
[ 1.65e-03]
[ 3.10e-03]
[ 2.35e-03]
[ 1.54e-03]
[ 2.79e-03]
[ 1.56e-03]
[ 1.08e-03]
[ 1.83e-03]
[ 1.83e-03]
[ 2.37e-03]
[ 1.78e-03]
[ 2.89e-03]
[ 1.24e-03]
[ 2.04e-03]
[ 2.37e-03]
[ 9.83e-04]
[ 2.26e-03]
[ 1.27e-03]
[ 1.73e-03]
[ 3.54e-03]
[ 2.05e-03]
[ 2.52e-03]
[ 1.70e-03]
[ 1.69e-03]
[ 2.66e-03]
[ 1.62e-03]
[ 2.40e-03]


In [92]:
len(sol['x'])


Out[92]:
455

In [93]:
####
dates = [pd.Timestamp('2012-05-01'), pd.Timestamp('2012-05-02'), pd.Timestamp('2012-05-03')]
s = pd.DataFrame(index = dates ,data =[[5,6,7],[8,6,0],[1,2,3]],columns=[1,2,3] )
d = pd.DataFrame(index = dates,data =[[1,2,3,1],[2,3,1,2],[3,1,2,3]],columns=['hs','hc','hv','hg'] )

In [94]:
dd =d.copy()
for i in dates:    
    sSlice = s.loc[i]
    dSlice = d.loc[i]
    dd.loc[i] = sSlice.loc[dSlice].values
print dd


            hs  hc  hv  hg
2012-05-01   5   6   7   5
2012-05-02   6   0   8   6
2012-05-03   3   1   2   3

In [ ]:


In [95]:
#d.apply(lambda x: s[x.values] ,axis=0)

In [96]:
color_set=sns.light_palette((210, 90, 60), input="husl")
(factorPvalue[factorPvalue < 0.05].count()/len(factorPvalue)).plot(figsize=(18,12),kind='bar',color=sns.color_palette(color_set,10))


Out[96]:
<matplotlib.axes._subplots.AxesSubplot at 0x3b98ab70>

In [97]:
factorReturn.cumsum().plot(figsize=(20,14))


Out[97]:
<matplotlib.axes._subplots.AxesSubplot at 0x3921a128>

In [98]:
factorReturn.describe()


Out[98]:
LFCA PB YOYBPS AMOUNTAVG1MData TURNOVER1M PROFITOOP
count 1213.000000 1213.000000 1213.000000 1213.000000 1213.000000 1213.000000
mean 0.000138 0.001844 -0.000530 -0.000184 -0.000306 -0.002801
std 0.003104 0.018440 0.023450 0.001884 0.004886 0.026907
min -0.018767 -0.125413 -0.164897 -0.008586 -0.025073 -0.214041
25% -0.001447 -0.001921 -0.001335 -0.001211 -0.002268 -0.001897
50% -0.000213 0.000765 -0.000054 -0.000234 -0.000122 -0.000158
75% 0.001137 0.003673 0.001293 0.000902 0.001962 0.000922
max 0.023948 0.167759 0.166723 0.007942 0.022233 0.134320

In [99]:
result2 = sm.OLS(factorReturn['PB'],factorReturn['LFCA']).fit()

In [100]:
result2.summary()


Out[100]:
OLS Regression Results
Dep. Variable: PB R-squared: 0.001
Model: OLS Adj. R-squared: -0.000
Method: Least Squares F-statistic: 0.6427
Date: Wed, 26 Apr 2017 Prob (F-statistic): 0.423
Time: 09:40:43 Log-Likelihood: 3117.4
No. Observations: 1213 AIC: -6233.
Df Residuals: 1212 BIC: -6228.
Df Model: 1
Covariance Type: nonrobust
coef std err t P>|t| [0.025 0.975]
LFCA -0.1373 0.171 -0.802 0.423 -0.473 0.199
Omnibus: 527.561 Durbin-Watson: 1.762
Prob(Omnibus): 0.000 Jarque-Bera (JB): 18261.231
Skew: 1.346 Prob(JB): 0.00
Kurtosis: 21.817 Cond. No. 1.00

In [101]:
specificReturn


Out[101]:
600507.SH 002344.SZ 000793.SZ 300039.SZ 600059.SH 600501.SH 000713.SZ 002233.SZ 600360.SH 600565.SH ... 600150.SH 600469.SH 600282.SH 600739.SH 600406.SH 600687.SH 600866.SH 000860.SZ 601908.SH 002195.SZ
Specifc_Return_for_ZX500
2012-01-05 0.025697 -0.003473 0.037547 0.008942 -0.016753 -0.008696 -0.063853 -0.037908 0.003391 0.043417 ... -0.006358 0.025833 0.017932 0.015733 0.014046 0.047862 -0.010460 -0.016782 -0.034919 -0.028392
2012-01-06 0.009798 -0.002888 -0.014237 -0.001026 0.008056 0.008518 -0.076295 0.035727 0.012290 0.042268 ... 0.007569 0.025506 0.007685 0.032604 0.004787 -0.002140 -0.026344 -0.000980 0.006110 0.020083
2012-01-09 -0.002461 -0.003984 -0.008911 0.008975 -0.001940 0.004855 -0.009167 0.023284 0.001697 -0.023664 ... 0.002377 -0.014051 -0.012759 0.004765 -0.013659 -0.037539 0.002730 0.019514 0.008412 -0.039856
2012-01-10 -0.006802 -0.005576 -0.014091 -0.018444 -0.002437 -0.000084 0.061007 0.024528 -0.000246 -0.021472 ... -0.000985 0.005040 0.000618 -0.019920 -0.011203 -0.040650 0.030107 -0.000083 0.021606 0.021835
2012-01-11 0.045727 0.012534 -0.004737 -0.021131 -0.011484 0.000324 0.017528 -0.022103 -0.006171 -0.014216 ... -0.007070 0.005367 0.003865 -0.006986 0.004961 -0.005496 -0.012906 -0.007782 -0.008659 0.094105
2012-01-12 -0.009627 -0.009251 -0.003970 -0.016977 -0.002378 0.007949 -0.016876 0.007746 0.001761 -0.001463 ... 0.000756 -0.014743 -0.005372 -0.002584 -0.018490 0.001313 -0.001444 -0.005423 0.036531 -0.017246
2012-01-13 -0.010242 0.020970 -0.002322 -0.040364 -0.000066 0.000146 0.017963 -0.008312 -0.005817 0.007578 ... -0.004806 -0.007751 0.008295 0.002108 -0.022852 0.039016 -0.015669 -0.015496 0.032646 -0.026736
2012-01-16 0.020199 -0.021679 0.007341 -0.001592 -0.010316 -0.006683 0.018280 -0.001341 0.008870 0.003953 ... 0.005323 0.008468 0.018731 0.021012 -0.070429 0.035611 -0.011880 0.010993 -0.011707 -0.003663
2012-01-17 -0.054877 -0.000032 -0.011086 -0.017507 0.003734 -0.005409 0.000674 0.026957 0.001241 -0.006605 ... 0.004167 0.006175 0.001760 0.006243 -0.022848 -0.051361 0.002953 -0.003269 0.002274 0.025790
2012-01-18 0.022522 0.011270 0.009700 -0.068346 -0.007530 0.042251 -0.008548 0.026919 0.008811 0.014793 ... 0.004430 0.021011 0.000996 -0.006043 -0.054979 0.027621 -0.003274 -0.001775 0.001269 -0.014766
2012-01-19 0.060079 -0.006803 -0.028688 0.011397 0.002379 -0.002305 -0.012110 -0.001179 0.006911 0.002572 ... -0.000286 0.009633 0.001779 0.009646 0.052840 -0.009797 -0.005038 0.000501 0.018976 -0.001058
2012-01-20 -0.019647 -0.008150 -0.000180 0.012686 0.015826 -0.004234 0.027664 0.013963 0.000335 -0.001984 ... 0.021521 -0.005428 -0.004488 0.007368 0.001899 -0.014612 0.011480 0.006558 -0.008054 -0.012639
2012-01-30 0.011053 -0.013475 0.009726 -0.004199 0.012627 0.001401 -0.003782 -0.028172 0.004519 -0.006218 ... -0.010550 -0.017300 -0.000519 0.004420 0.002340 0.000927 -0.003856 0.025063 -0.012913 -0.002350
2012-01-31 -0.003756 -0.017357 0.020712 -0.029218 -0.003476 0.014373 -0.004233 -0.003062 0.003812 0.013702 ... 0.018583 0.014493 -0.015569 -0.002926 -0.016167 -0.000671 -0.006074 0.009975 -0.044988 -0.003558
2012-02-01 -0.010210 0.005883 -0.001170 0.009586 -0.009513 -0.014536 0.010392 -0.023494 0.011447 0.011954 ... -0.011139 0.011274 0.001201 -0.002798 0.005141 0.003310 0.006928 0.001441 -0.012411 -0.002608
2012-02-02 -0.006556 -0.005135 -0.001330 0.037808 -0.010369 -0.001339 -0.009855 0.001722 0.002519 -0.000582 ... -0.005014 -0.002695 -0.005149 -0.007672 -0.010057 -0.016110 0.000715 -0.000305 0.004030 0.006156
2012-02-03 -0.007349 0.003108 -0.016817 -0.011857 -0.004797 -0.007903 -0.016840 -0.015055 0.020752 -0.014320 ... 0.006986 -0.006016 -0.010460 -0.010506 0.039603 -0.021608 0.041952 -0.020348 0.012629 0.001543
2012-02-06 -0.005528 0.005469 -0.011822 0.029207 -0.003050 -0.011378 0.006300 0.017259 -0.015340 -0.015194 ... -0.007103 -0.010491 -0.010896 0.004785 0.027431 -0.011732 -0.011777 -0.003412 0.028627 -0.007435
2012-02-07 0.008390 -0.003556 0.010067 -0.007387 -0.009078 -0.002071 -0.000861 -0.013572 -0.011307 0.008977 ... -0.006898 -0.001997 0.008342 -0.024295 -0.001304 0.014379 -0.013875 -0.005976 -0.004512 -0.011058
2012-02-08 -0.012152 -0.010044 -0.014624 -0.003835 0.002906 0.003406 -0.015299 0.009846 0.009580 -0.003992 ... -0.006144 0.013945 -0.004910 0.005237 -0.002903 -0.024295 0.009027 -0.005572 0.010185 0.001977
2012-02-09 0.016116 -0.005459 -0.002377 -0.014785 0.011079 -0.012502 -0.007977 -0.000302 0.002661 0.005397 ... 0.001038 -0.015223 -0.004035 -0.009586 0.006196 -0.009539 0.021959 0.000662 -0.010483 0.007370
2012-02-10 0.001162 0.001826 -0.003241 -0.016826 -0.008935 -0.001425 0.010385 0.002829 -0.006626 -0.001218 ... -0.005290 -0.003878 0.004429 0.005094 -0.006322 -0.007867 -0.012987 0.017081 0.006077 -0.007489
2012-02-13 -0.004348 -0.009434 -0.002377 0.041533 0.011631 -0.002109 -0.020070 -0.020366 0.029998 -0.011101 ... -0.002728 -0.001064 -0.011708 -0.001984 -0.002504 -0.014350 0.007706 -0.003517 -0.023715 -0.001887
2012-02-14 -0.005020 0.005827 -0.000060 0.031157 -0.002835 0.007338 -0.007546 0.014853 -0.014081 0.012637 ... 0.010812 0.016797 -0.010790 -0.005326 -0.006415 -0.003178 -0.007490 -0.000516 -0.014311 -0.005706
2012-02-15 -0.001737 -0.005584 0.007412 -0.003420 -0.014295 0.004322 -0.012637 -0.006615 0.020089 -0.011643 ... 0.007085 -0.009986 0.007822 0.023290 -0.016891 -0.016486 0.028790 -0.007172 0.010785 -0.003552
2012-02-16 0.019497 0.002845 0.005799 -0.003650 0.000985 -0.006408 0.014222 -0.006275 -0.009168 0.015122 ... -0.008492 0.011382 -0.007275 -0.007312 -0.003675 -0.002756 -0.009829 -0.011589 0.029805 -0.003292
2012-02-17 -0.004990 -0.000247 -0.006921 -0.012979 -0.006523 0.019146 -0.014689 -0.010776 -0.013079 0.007198 ... 0.006536 -0.002213 0.000637 0.017015 0.003368 0.004459 -0.013537 -0.006585 0.010342 -0.019308
2012-02-20 -0.000762 -0.011651 -0.007823 -0.040286 0.006905 -0.008681 -0.004858 0.000353 -0.009046 -0.019164 ... 0.000677 -0.011483 -0.005031 -0.014838 0.032045 -0.002110 -0.003969 0.003308 -0.013040 -0.002108
2012-02-21 -0.016275 -0.008949 0.004663 -0.000365 0.032768 -0.006971 -0.009862 -0.005791 0.002142 0.006485 ... -0.008162 -0.009223 -0.003224 0.004059 -0.000326 -0.010086 -0.001350 0.016590 -0.006795 0.014290
2012-02-22 -0.011953 -0.000159 -0.005044 -0.000245 -0.013014 0.017540 -0.004819 -0.004893 -0.010375 -0.009904 ... -0.004839 -0.005477 -0.009693 0.003160 -0.000570 -0.019620 -0.000302 -0.007680 0.020105 0.007744
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2016-11-21 0.004116 -0.012315 -0.000965 0.002540 -0.001069 0.015198 -0.003783 -0.009837 0.002850 -0.005221 ... 0.006744 0.012791 0.010766 0.007151 -0.021069 -0.003086 -0.000848 -0.000633 0.029898 0.018065
2016-11-22 0.008588 -0.006524 -0.014546 0.002471 -0.006451 -0.001184 0.001560 -0.024366 -0.014749 -0.006824 ... 0.011174 0.001036 0.041534 0.051665 -0.012534 -0.006076 -0.002769 -0.002800 0.052490 -0.027845
2016-11-23 0.003757 -0.026598 -0.005973 -0.006287 0.002678 0.017555 -0.006563 -0.002171 0.007746 -0.002714 ... -0.007023 -0.007030 0.021765 -0.008500 -0.002021 -0.000128 -0.008328 0.009204 -0.021191 -0.000150
2016-11-24 0.002655 0.010088 -0.001484 -0.007074 0.021118 0.001684 -0.008638 0.002739 0.023288 -0.000461 ... -0.019155 -0.011349 0.020292 0.068609 -0.025388 -0.001966 -0.016330 0.010067 -0.030220 -0.035994
2016-11-25 0.035908 -0.014605 0.000058 -0.001145 -0.013527 -0.007813 -0.008431 -0.011698 -0.019321 -0.009498 ... 0.004688 0.010013 0.002062 -0.015354 -0.006859 -0.006832 -0.011420 -0.010807 -0.011395 0.011546
2016-11-28 -0.009264 -0.018041 0.009752 0.007162 -0.000162 -0.014589 0.001061 0.008392 -0.020504 0.032465 ... 0.006745 -0.008057 -0.000886 -0.006892 0.010231 -0.000727 -0.011330 -0.001330 0.005123 -0.014616
2016-11-29 0.032540 0.012524 -0.021000 0.002891 0.013319 0.049836 0.000907 -0.018818 -0.010295 -0.003335 ... 0.026431 -0.021797 -0.023068 -0.009793 -0.004073 0.001587 0.002279 0.015202 -0.019326 0.001329
2016-11-30 -0.010226 -0.026371 0.014858 0.037224 0.000731 -0.001730 0.005836 -0.010111 0.014362 -0.008539 ... -0.019896 0.007475 -0.005221 0.016167 0.002437 0.004305 0.002454 -0.014744 -0.013338 0.037680
2016-12-01 0.013128 0.000494 -0.014953 -0.009253 -0.009240 -0.005666 0.000146 0.005404 -0.001360 -0.011849 ... 0.024119 0.019769 0.007970 -0.007834 -0.006012 -0.007108 0.003505 -0.009391 0.000424 -0.007404
2016-12-02 -0.031747 -0.003301 0.015371 -0.011835 -0.012148 -0.015657 0.001290 0.001381 -0.003682 0.015541 ... 0.042484 0.025365 -0.004533 0.014798 0.017513 0.010304 -0.004684 -0.003220 -0.010651 -0.002368
2016-12-05 0.005434 -0.023616 0.001484 -0.014046 0.010283 0.005787 0.005068 0.004562 0.002820 0.007331 ... 0.084771 0.010870 0.001622 -0.089297 0.021249 0.003972 0.007877 0.009958 0.001822 0.019856
2016-12-06 -0.006845 -0.000693 -0.007595 -0.005681 -0.009284 -0.020962 0.004289 0.014763 0.018684 -0.008087 ... -0.014768 0.005650 0.003751 -0.009610 0.017321 0.000288 0.010379 -0.001049 0.002666 0.010346
2016-12-07 0.045892 0.020282 -0.015689 0.000494 -0.004245 -0.008839 -0.001693 0.018272 -0.015131 -0.010187 ... 0.018825 -0.009593 0.018710 -0.006145 -0.002597 -0.007274 0.002232 -0.002943 -0.000263 -0.004393
2016-12-08 0.005831 -0.004326 0.029605 -0.008784 0.006654 -0.016217 0.000350 -0.014138 0.002712 0.025956 ... -0.012993 0.021909 -0.008978 -0.006309 -0.013237 0.003997 -0.006220 0.011827 -0.006600 -0.001618
2016-12-09 -0.018018 0.000732 -0.004448 -0.004510 0.001487 0.002110 -0.002175 -0.020003 -0.008717 0.000906 ... 0.026872 0.004223 0.007711 0.003453 -0.004103 0.000866 0.002818 0.005212 -0.016663 -0.000147
2016-12-12 0.013583 -0.009366 0.003169 -0.012749 -0.009388 0.010733 -0.007133 -0.016055 -0.022612 0.019399 ... 0.003842 -0.001923 0.008784 -0.026577 0.024233 0.029109 0.000933 0.015489 -0.011285 -0.014813
2016-12-13 0.052545 -0.001282 -0.005146 0.000161 0.012430 0.015913 0.012024 0.030629 -0.013771 -0.006450 ... 0.067248 -0.005695 0.008372 0.003918 -0.029522 -0.002800 -0.000237 0.024233 -0.013403 -0.001608
2016-12-14 -0.021991 -0.003708 -0.004227 -0.001113 -0.000090 0.030691 -0.026090 -0.013705 -0.001227 -0.015985 ... -0.021127 0.063488 -0.014712 -0.010451 0.071338 0.005249 0.012816 0.003353 0.004883 -0.012642
2016-12-15 0.093530 0.031947 0.010375 -0.004773 -0.005439 0.002772 -0.002247 -0.007773 0.015203 0.041862 ... -0.009560 -0.000193 0.011235 -0.004244 0.009400 -0.000135 0.007963 0.003303 0.002096 0.002556
2016-12-16 0.049880 0.003535 0.049998 0.002677 0.007463 0.004271 0.042843 0.005243 -0.005540 0.023208 ... -0.047765 -0.018137 -0.009253 0.020822 -0.016290 -0.006583 0.006597 -0.010722 0.005390 0.019541
2016-12-19 -0.034419 -0.017775 0.024785 -0.015057 -0.005119 0.001086 0.007792 -0.001322 -0.021083 -0.002237 ... 0.015954 0.011016 0.019557 -0.006675 0.004989 -0.000995 -0.001658 0.011185 -0.001744 -0.015854
2016-12-20 -0.044345 0.011837 0.003587 0.006492 -0.007609 -0.008795 -0.021780 -0.016357 0.025412 -0.007512 ... 0.001017 -0.022421 -0.000326 -0.000752 -0.020449 0.002981 0.009770 -0.001188 -0.003776 0.011593
2016-12-21 -0.008973 -0.003105 -0.011989 -0.000767 -0.000366 0.014113 0.006825 -0.006050 -0.003281 -0.007760 ... 0.064926 0.063497 0.007640 0.002840 0.004354 -0.009241 -0.006415 -0.003403 -0.010551 -0.003575
2016-12-22 -0.002591 -0.003378 -0.008123 -0.004816 0.002814 -0.019702 -0.011148 0.056149 -0.016243 0.022487 ... 0.026384 0.009699 0.047396 -0.000297 0.034828 -0.000194 -0.001773 -0.011049 -0.001616 -0.018613
2016-12-23 -0.029777 -0.015928 0.036201 0.000889 0.023664 0.005538 -0.012470 -0.015434 0.010483 0.015981 ... 0.017602 -0.011120 0.011213 -0.001032 0.020064 0.008623 -0.001696 -0.004138 0.001410 0.001846
2016-12-26 -0.023122 0.010769 -0.009817 0.006947 0.012481 0.006357 0.008649 0.008887 -0.003876 -0.004927 ... 0.002493 0.002654 -0.026140 -0.001668 -0.009431 -0.001582 0.010529 -0.005836 0.008052 0.019346
2016-12-27 -0.004435 -0.000807 0.002591 -0.001878 0.006556 0.001184 0.009099 0.002489 0.005987 0.025400 ... -0.019135 -0.001682 -0.007102 -0.004429 0.004407 0.000556 0.012094 0.007637 -0.007560 -0.007801
2016-12-28 -0.012017 0.002621 -0.020772 -0.006607 -0.004481 0.007649 0.002448 -0.011259 0.005490 -0.010482 ... 0.001505 0.034261 -0.000343 -0.006536 -0.005476 0.002957 0.017636 0.008229 0.004232 -0.001179
2016-12-29 0.008727 0.013987 -0.004611 0.008750 0.006758 0.004271 0.006866 0.004027 -0.013295 -0.020404 ... -0.022136 -0.011416 0.042035 0.026898 0.001633 0.001583 -0.010350 0.006314 0.022208 -0.005476
2016-12-30 -0.009606 -0.004526 -0.011325 -0.003919 -0.002088 -0.018438 0.012067 -0.020959 -0.012541 0.006351 ... -0.028871 -0.005890 -0.000246 -0.008862 -0.002014 -0.006388 0.010013 0.047173 0.021147 -0.005549

1213 rows × 1071 columns


In [102]:
result1 = sm.OLS(returnOfBench, factorReturn).fit()

In [103]:
result1 .summary()


Out[103]:
OLS Regression Results
Dep. Variable: 000905.SH R-squared: 0.626
Model: OLS Adj. R-squared: 0.624
Method: Least Squares F-statistic: 336.2
Date: Wed, 26 Apr 2017 Prob (F-statistic): 2.15e-253
Time: 09:40:44 Log-Likelihood: 3696.9
No. Observations: 1213 AIC: -7382.
Df Residuals: 1207 BIC: -7351.
Df Model: 6
Covariance Type: nonrobust
coef std err t P>|t| [0.025 0.975]
LFCA -0.8877 0.110 -8.092 0.000 -1.103 -0.672
PB -0.0405 0.022 -1.871 0.062 -0.083 0.002
YOYBPS -0.0398 0.015 -2.708 0.007 -0.069 -0.011
AMOUNTAVG1MData 0.9825 0.191 5.140 0.000 0.607 1.357
TURNOVER1M 3.0035 0.074 40.779 0.000 2.859 3.148
PROFITOOP 0.0772 0.015 5.298 0.000 0.049 0.106
Omnibus: 77.445 Durbin-Watson: 1.694
Prob(Omnibus): 0.000 Jarque-Bera (JB): 306.322
Skew: -0.130 Prob(JB): 3.04e-67
Kurtosis: 5.448 Cond. No. 17.4

In [104]:
result1.resid.head(10)


Out[104]:
Specifc_Return_for_ZX500
2012-01-05   -0.030171
2012-01-06   -0.001059
2012-01-09    0.032445
2012-01-10    0.041967
2012-01-11    0.000153
2012-01-12   -0.000846
2012-01-13   -0.028417
2012-01-16   -0.024800
2012-01-17    0.050525
2012-01-18   -0.021567
dtype: float64

In [105]:
1.247**5


Out[105]:
3.0153120786310086

In [106]:
print PBData.shape,YOYBPSData.shape,AMOUNTAVG1MData .shape, TURNOVER1MData.shape,PROFITOOPData.shape


(1214, 1071) (1214, 1071) (1214, 1071) (1214, 1071) (1214, 1071)

In [107]:
PriceDF


Out[107]:
600507.SH 002344.SZ 000793.SZ 300039.SZ 600059.SH 600501.SH 000713.SZ 002233.SZ 600360.SH 600565.SH ... 600150.SH 600469.SH 600282.SH 600739.SH 600406.SH 600687.SH 600866.SH 000860.SZ 601908.SH 002195.SZ
LZ_GPA_DERI_AdjustedPriceForward_20-d
2012-01-04 2.95251 10.25091 5.49539 5.93078 9.33043 7.62428 13.27401 8.09095 3.81523 2.97514 ... 19.48821 4.54020 2.65200 12.10778 14.57299 4.87935 5.69 13.19030 5.08136 3.17793
2012-01-05 2.92215 9.79264 5.53478 5.73013 8.86761 7.20070 11.94563 7.51623 3.66887 2.97514 ... 18.98636 4.47361 2.60325 12.03819 14.45932 4.87935 5.40 12.52060 4.66601 2.93332
2012-01-06 2.96010 9.79264 5.48554 5.73899 8.98794 7.28936 11.11907 7.85747 3.72742 3.11126 ... 19.19927 4.60679 2.63250 12.51535 14.55935 4.87935 5.28 12.55942 4.73645 3.00377
2012-01-09 3.07395 10.12067 5.65296 6.01635 9.33043 7.63413 11.47331 8.36933 3.89329 3.16959 ... 19.98244 4.73997 2.71050 13.07203 14.68666 4.87935 5.52 13.31648 4.98663 3.00377
2012-01-10 3.18021 10.47764 5.80068 6.15798 9.68217 7.95919 12.62458 8.90813 4.05917 3.23765 ... 20.75802 4.96395 2.82750 13.32055 15.00040 4.87935 5.92 13.86001 5.26596 3.19358
2012-01-11 3.32442 10.65130 5.77114 6.04880 9.57110 7.98874 12.86074 8.71955 4.03966 3.19876 ... 20.51470 4.99422 2.83725 13.18138 15.13681 4.87935 5.85 13.74354 5.21738 3.51255
2012-01-12 3.28647 10.55965 5.74159 5.94553 9.53407 8.03800 12.61474 8.77343 4.03966 3.18904 ... 20.52991 4.90947 2.81775 13.12173 14.91856 4.87935 5.83 13.64648 5.34854 3.44993
2012-01-13 3.14226 10.41010 5.55448 5.47343 9.22861 7.69323 12.40810 8.39627 3.85426 3.08209 ... 19.99765 4.67944 2.73975 12.83345 14.43658 4.87935 5.51 12.98648 5.31940 3.21511
2012-01-16 3.11190 9.84088 5.43630 5.28459 8.85836 7.37801 12.23098 8.12687 3.76645 2.99458 ... 19.62507 4.57047 2.71050 12.78375 13.00429 4.87935 5.27 12.74383 5.04250 3.08596
2012-01-17 3.11190 10.34739 5.67266 5.47343 9.37671 7.74248 12.90993 8.80935 3.98111 3.14042 ... 20.77323 4.85499 2.86650 13.58894 13.28620 4.87935 5.58 13.40383 5.34126 3.32665
2012-01-18 3.11190 10.23644 5.61357 4.97182 9.10828 7.87054 12.50650 8.88119 3.92257 3.11126 ... 20.56032 4.84288 2.80800 13.28078 12.34953 4.87935 5.43 13.09324 5.13237 3.19163
2012-01-19 3.33960 10.24609 5.52493 5.06919 9.23787 7.91979 12.46714 8.93507 3.99087 3.15015 ... 20.86447 4.93974 2.84700 13.61877 13.14525 4.87935 5.46 13.25824 5.31211 3.20532
2012-01-20 3.32442 10.31363 5.60372 5.20787 9.51556 7.99859 12.97881 9.15957 4.04942 3.18904 ... 21.64765 4.98212 2.87625 13.89711 13.37259 4.87935 5.60 13.53971 5.34126 3.20924
2012-01-30 3.33201 10.12067 5.60372 5.15771 9.55258 7.97889 12.85090 8.82731 4.03966 3.15015 ... 21.06217 4.86104 2.84700 13.76788 13.29529 4.87935 5.54 13.75324 5.29511 3.19750
2012-01-31 3.31683 9.95665 5.72190 5.00428 9.52481 8.08725 12.82138 8.82731 4.04942 3.18904 ... 21.45756 4.92763 2.79825 13.74800 13.18162 4.87935 5.50 13.88913 5.06436 3.19163
2012-02-01 3.25611 9.95665 5.66281 5.02493 9.34894 7.92964 12.84106 8.52199 4.06893 3.20848 ... 20.93290 4.94579 2.77875 13.52930 13.11796 4.87935 5.50 13.78236 4.96963 3.16814
2012-02-02 3.29406 10.08690 5.76129 5.30819 9.43225 8.06755 12.97881 8.73751 4.15675 3.26682 ... 21.23705 5.03054 2.81775 13.70823 13.20436 4.87935 5.61 14.04442 5.07407 3.24838
2012-02-03 3.32442 10.31845 5.75144 5.35540 9.53407 8.17590 12.96897 8.73751 4.32263 3.28626 ... 21.60203 5.09108 2.83725 13.69829 13.86821 4.87935 5.95 13.97648 5.21252 3.32274
2012-02-06 3.33201 10.46799 5.72190 5.56195 9.57110 8.16605 13.14609 8.93507 4.29336 3.26682 ... 21.51839 5.07897 2.82750 13.80764 14.31836 4.87935 5.93 14.02501 5.42870 3.33252
2012-02-07 3.30165 10.27503 5.68250 5.42917 9.32117 8.00844 12.91977 8.65669 4.16651 3.23765 ... 20.98613 4.97606 2.79825 13.22114 14.16376 4.87935 5.74 13.69501 5.32183 3.24642
2012-02-08 3.34719 10.43422 5.75144 5.54424 9.59887 8.23501 13.07721 8.98895 4.31287 3.30571 ... 21.44995 5.17583 2.85675 13.67841 14.53207 4.87935 5.94 13.98618 5.52343 3.33643
2012-02-09 3.42309 10.46799 5.77114 5.51474 9.76548 8.21530 13.06737 9.05181 4.36166 3.35432 ... 21.52599 5.13951 2.86650 13.58894 14.64574 4.87935 6.12 14.08324 5.49671 3.39514
2012-02-10 3.44586 10.55000 5.78099 5.45868 9.72846 8.26456 13.27401 9.12365 4.36166 3.37377 ... 21.45756 5.15162 2.89575 13.70823 14.58208 4.87935 6.08 14.39383 5.56958 3.39318
2012-02-13 3.46104 10.55965 5.81053 5.74489 9.92284 8.35321 13.14609 9.01589 4.53730 3.37377 ... 21.44235 5.20005 2.88600 13.73805 14.60936 4.87935 6.19 14.46177 5.55743 3.43428
2012-02-14 3.44586 10.63683 5.81053 5.93373 9.89507 8.43202 13.04769 9.14161 4.47875 3.42238 ... 21.62484 5.29085 2.85675 13.63865 14.49569 4.87935 6.15 14.45207 5.48457 3.42058
2012-02-15 3.49140 10.75743 5.93856 6.01635 9.90433 8.61917 13.09689 9.24039 4.64463 3.44183 ... 22.05064 5.32717 2.92500 14.13568 14.41385 4.87935 6.43 14.56854 5.61330 3.47146
2012-02-16 3.55971 10.80085 5.96811 6.00454 9.90433 8.57977 13.26417 9.15957 4.60560 3.50016 ... 21.79212 5.38771 2.90550 13.97663 14.30472 4.87935 6.37 14.38413 5.75661 3.46167
2012-02-17 3.52935 10.75743 5.90902 5.90127 9.81176 8.70783 13.03785 9.04283 4.52754 3.50989 ... 21.89097 5.35744 2.89575 14.19533 14.34564 4.87935 6.26 14.24824 5.81733 3.38340
2012-02-20 3.52935 10.66095 5.86962 5.67997 9.89507 8.65858 13.00833 9.07875 4.49827 3.45155 ... 21.89857 5.30901 2.88600 13.99651 14.80488 4.87935 6.25 14.31618 5.74203 3.38927
2012-02-21 3.50658 10.68989 5.95826 5.74194 10.33012 8.69798 13.04769 9.15059 4.55681 3.50989 ... 21.95179 5.32112 2.90550 14.20527 14.98222 4.87935 6.31 14.71413 5.78576 3.48320
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2016-11-21 6.46000 12.79000 11.44000 11.27000 10.23000 18.34000 12.14000 10.41000 10.24000 7.16000 ... 23.61000 10.78000 2.71000 19.53000 15.89000 16.42000 7.19 20.71000 7.76000 12.84000
2016-11-22 6.57000 12.83000 11.39000 11.40000 10.25000 18.47000 12.28000 10.26000 10.20000 7.19000 ... 24.04000 10.89000 2.85000 20.70000 15.80000 16.42000 7.24 20.82000 8.23000 12.62000
2016-11-23 6.57000 12.41000 11.26000 11.26000 10.24000 18.72000 12.11000 10.17000 10.19000 7.12000 ... 23.86000 10.76000 2.90000 20.46000 15.76000 16.42000 7.13 20.94000 8.03000 12.51000
2016-11-24 6.59000 12.52000 11.24000 11.16000 10.45000 18.72000 11.95000 10.17000 10.38000 7.10000 ... 23.43000 10.60000 2.96000 21.87000 15.39000 16.42000 6.99 21.15000 7.79000 11.99000
2016-11-25 6.86000 12.38000 11.29000 11.18000 10.35000 18.63000 11.85000 10.07000 10.18000 7.05000 ... 23.68000 10.72000 2.98000 21.64000 15.39000 16.42000 6.92 21.02000 7.74000 12.12000
2016-11-28 6.81000 12.19000 11.45000 11.28000 10.37000 18.39000 11.89000 10.18000 10.00000 7.31000 ... 23.88000 10.67000 3.00000 21.55000 15.58000 16.42000 6.86 21.01000 7.80000 11.99000
2016-11-29 6.98000 12.23000 11.14000 11.18000 10.42000 19.12000 11.70000 9.86000 9.74000 7.21000 ... 24.50000 10.31000 2.91000 21.25000 15.52000 16.42000 6.77 21.18000 7.61000 11.83000
2016-11-30 6.87000 11.81000 11.21000 11.53000 10.37000 18.98000 11.70000 9.69000 9.80000 7.09000 ... 23.84000 10.33000 2.87000 21.41000 15.46000 16.42000 6.75 20.74000 7.46000 12.17000
2016-12-01 7.01000 11.90000 11.13000 11.50000 10.35000 19.00000 11.78000 9.81000 9.85000 7.06000 ... 24.59000 10.61000 2.92000 21.40000 15.48000 16.42000 6.82 20.69000 7.52000 12.16000
2016-12-02 6.68000 11.66000 11.14000 11.16000 10.07000 18.40000 11.57000 9.65000 9.62000 7.05000 ... 25.38000 10.72000 2.86000 21.43000 15.60000 16.42000 6.66 20.32000 7.34000 11.91000
2016-12-05 6.67000 11.27000 11.05000 10.92000 10.11000 18.39000 11.55000 9.61000 9.55000 7.03000 ... 27.31000 10.78000 2.83000 19.29000 15.83000 16.42000 6.67 20.37000 7.30000 12.03000
2016-12-06 6.63000 11.27000 10.96000 10.88000 10.03000 18.04000 11.64000 9.77000 9.75000 6.98000 ... 26.87000 10.87000 2.84000 19.09000 16.08000 16.42000 6.76 20.36000 7.32000 12.18000
2016-12-07 7.01000 11.64000 10.90000 11.03000 10.10000 18.10000 11.79000 10.08000 9.75000 7.00000 ... 27.62000 10.89000 2.93000 19.18000 16.15000 16.42000 6.87 20.53000 7.39000 12.29000
2016-12-08 7.02000 11.54000 11.18000 10.88000 10.12000 17.72000 11.73000 9.89000 9.73000 7.15000 ... 27.17000 11.07000 2.89000 18.99000 15.88000 16.42000 6.79 20.69000 7.31000 12.21000
2016-12-09 6.89000 11.55000 11.14000 10.82000 10.13000 17.74000 11.69000 9.69000 9.64000 7.16000 ... 27.94000 11.11000 2.92000 19.08000 15.82000 16.42000 6.80 20.79000 7.19000 12.21000
2016-12-12 6.70000 10.95000 10.76000 10.16000 9.61000 17.12000 10.99000 9.06000 8.95000 6.98000 ... 27.04000 10.58000 2.82000 17.82000 15.76000 16.42000 6.46 20.28000 6.84000 11.38000
2016-12-13 7.09000 11.00000 10.76000 10.23000 9.78000 17.50000 11.20000 9.40000 8.89000 6.98000 ... 29.04000 10.57000 2.86000 18.01000 15.35000 16.42000 6.50 20.90000 6.78000 11.45000
2016-12-14 6.90000 10.91000 10.66000 10.18000 9.74000 17.98000 10.88000 9.24000 8.85000 6.84000 ... 28.32000 11.21000 2.80000 17.75000 16.36000 16.42000 6.56 20.89000 6.78000 11.28000
2016-12-15 7.59000 11.32000 10.80000 10.24000 9.76000 18.20000 11.02000 9.26000 9.08000 7.18000 ... 28.12000 11.32000 2.85000 17.74000 16.48000 16.42000 6.70 21.08000 6.82000 11.44000
2016-12-16 8.02000 11.43000 11.39000 10.35000 9.91000 18.42000 11.60000 9.38000 9.10000 7.39000 ... 26.82000 11.21000 2.84000 18.17000 16.27000 16.42000 6.81 20.99000 6.90000 11.73000
2016-12-19 7.76000 11.25000 11.68000 10.23000 9.89000 18.50000 11.75000 9.40000 8.94000 7.39000 ... 27.24000 11.38000 2.90000 18.06000 16.34000 16.42000 6.83 21.27000 6.90000 11.58000
2016-12-20 7.39000 11.34000 11.66000 10.27000 9.79000 18.28000 11.47000 9.22000 9.14000 7.30000 ... 27.01000 11.09000 2.89000 17.92000 15.91000 16.42000 6.89 21.15000 6.85000 11.65000
2016-12-21 7.38000 11.40000 11.62000 10.34000 9.87000 18.68000 11.63000 9.24000 9.18000 7.30000 ... 28.95000 11.89000 2.94000 18.11000 16.12000 16.42000 6.90 21.23000 6.84000 11.70000
2016-12-22 7.36000 11.36000 11.52000 10.29000 9.90000 18.31000 11.50000 9.76000 9.03000 7.46000 ... 29.66000 12.00000 3.08000 18.09000 16.67000 16.42000 6.89 20.99000 6.83000 11.47000
2016-12-23 7.05000 11.05000 11.81000 10.17000 10.02000 18.19000 11.19000 9.49000 9.01000 7.48000 ... 29.78000 11.71000 3.08000 17.86000 16.85000 16.42000 6.79 20.64000 6.77000 11.34000
2016-12-26 6.91000 11.20000 11.73000 10.27000 10.17000 18.35000 11.32000 9.60000 9.00000 7.47000 ... 29.97000 11.77000 3.01000 17.88000 16.73000 16.42000 6.88 20.58000 6.84000 11.59000
2016-12-27 6.89000 11.20000 11.76000 10.27000 10.25000 18.40000 11.46000 9.64000 9.07000 7.67000 ... 29.40000 11.77000 2.99000 17.80000 16.78000 16.42000 6.98 20.77000 6.79000 11.51000
2016-12-28 6.79000 11.20000 11.48000 10.18000 10.18000 18.50000 11.47000 9.51000 9.10000 7.57000 ... 29.35000 12.15000 2.98000 17.63000 16.63000 16.42000 7.09 20.89000 6.80000 11.47000
2016-12-29 6.84000 11.34000 11.41000 10.25000 10.23000 18.54000 11.52000 9.53000 8.96000 7.40000 ... 28.65000 11.97000 3.10000 18.08000 16.63000 16.42000 7.00 21.00000 6.94000 11.37000
2016-12-30 6.77000 11.32000 11.29000 10.23000 10.24000 18.24000 11.65000 9.35000 8.86000 7.42000 ... 27.61000 11.90000 3.10000 17.96000 16.63000 16.42000 7.08 22.00000 7.12000 11.32000

1214 rows × 1071 columns


In [108]:
def f(series, i, l):                                   
    s = rc.iloc[(i*l):((i+1)*l)]
    try:
        return s.loc[[s.idxmax()]]
    except:
        return None

In [109]:
len(PriceDF.iloc[:,0])


Out[109]:
1214

In [110]:
%timeit a = pd.concat([f(PriceDF.iloc[:,0], i, 20) for i in range(len(PriceDF.iloc[:,0]))])


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-110-d690aed19933> in <module>()
----> 1 get_ipython().magic(u'timeit a = pd.concat([f(PriceDF.iloc[:,0], i, 20) for i in range(len(PriceDF.iloc[:,0]))])')

c:\python27\lib\site-packages\IPython\core\interactiveshell.pyc in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------

c:\python27\lib\site-packages\IPython\core\interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2077                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2078             with self.builtin_trap:
-> 2079                 result = fn(*args,**kwargs)
   2080             return result
   2081 

<decorator-gen-59> in timeit(self, line, cell)

c:\python27\lib\site-packages\IPython\core\magic.pyc in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

c:\python27\lib\site-packages\IPython\core\magics\execution.pyc in timeit(self, line, cell)
   1047             number = 1
   1048             for _ in range(1, 10):
-> 1049                 time_number = timer.timeit(number)
   1050                 worst_tuning = max(worst_tuning, time_number / number)
   1051                 if time_number >= 0.2:

c:\python27\lib\site-packages\IPython\core\magics\execution.pyc in timeit(self, number)
    137         gc.disable()
    138         try:
--> 139             timing = self.inner(it, self.timer)
    140         finally:
    141             if gcold:

<magic-timeit> in inner(_it, _timer)

<ipython-input-108-6d1e4e9c5e78> in f(series, i, l)
      1 def f(series, i, l):
----> 2     s = rc.iloc[(i*l):((i+1)*l)]
      3     try:
      4         return s.loc[[s.idxmax()]]
      5     except:

NameError: global name 'rc' is not defined

In [1]:
from __future__ import print_function
import sys
print(sys.argv, len(sys.argv))


['c:\\python27\\lib\\site-packages\\ipykernel\\__main__.py', '-f', 'C:\\Users\\LZJF_02\\AppData\\Roaming\\jupyter\\runtime\\kernel-edbf3667-ffdf-4939-b13f-716e7e28e5bb.json'] 3

In [3]:
import requests
from bs4 import BeautifulSoup

In [69]:
url = 'http://gs.amac.org.cn/amac-infodisc/res/pof/manager/managerList.html'
r = requests.get(url)
r.headers['content-type']


Out[69]:
'text/html'

In [81]:
url = 'http://gs.amac.org.cn/amac-infodisc/res/pof/manager/managerList.html'
r = requests.get(url)
r.encoding = 'utf-8'
html_doc = BeautifulSoup(r.text,"html")

In [82]:
html_doc


Out[82]:
<!DOCTYPE html>\n<html><head lang="en">\n    <meta charset="unicode-escape"/>\n    <title>\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u5206\u7c7b\u516c\u793a - \u4e2d\u56fd\u57fa\u91d1\u4e1a\u534f\u4f1a</title>\n    <link href="../../common/css/reset.css" rel="stylesheet" type="text/css"/>\n    <link href="../../common/css/unit.css" rel="stylesheet" type="text/css"/>\n    <link href="../../common/css/grid.css" rel="stylesheet" type="text/css"/>\n    <link href="../../common/css/global.css" rel="stylesheet" type="text/css"/>\n    <link href="../../common/css/module.css" rel="stylesheet" type="text/css"/>\n    <link href="../../lib/dataTable/css/jquery.dataTables.css" rel="stylesheet" type="text/css"/>\n    <style type="text/css">\n        .w100 {\n            width: 100px;\n        }\n\n        .controls ul li {\n            cursor: pointer;\n            line-height: 180%;\n        }\n\n        .controls ul li:hover {\n            background: #eee;\n        }\n\n        #controls div {\n            display: inline-block;\n        }\n\n        #controls div {\n            *display: inline;\n        }\n\n        .a1 {\n            color: #173bf4;\n            font-size: 1.1em;\n        }\n\n        #aa table tr td {\n            width: 30%;\n        }\n\n        .ui-dialog .ui-dialog-buttonpane {\n            height: 40px;\n        }\n\n        .controls a:hover {\n            text-decoration: none !important;\n            background-color: #dbdbdb;\n        }\n\n        .active:hover {\n            background-color: #c3d7f3 !important;\n        }\n\n        #aa a {\n            color: blue;\n            text-decoration: none !important;\n        }\n\n        #managerList_length {\n            margin-left: 10px;\n            margin-top: 6px;\n        }\n\n        #managerList_length select {\n            width: 70px;\n        }\n    </style>\n    <script language="javascript" src="../../lib/dataTable/js/jquery.js" type="text/javascript"></script>\n    <script language="javascript" src="../../lib/jquery/plugins/jquery-ui-1.11.4/external/jquery/jquery.js" type="text/javascript"></script>\n    <script language="javascript" src="../../lib/dataTable/js/jquery.dataTables.js" type="text/javascript"></script>\n    <script language="javascript" src="../../lib/dataTable/js/ellipses.js" type="text/javascript"></script>\n    <!--\n    <script type="text/javascript" language="javascript" src="../../../lib/dataTable/js/shCore.js"></script>\n    -->\n    <link href="../../lib/jquery/plugins/artDialog4/skins/blue.css" rel="stylesheet" type="text/css"/>\n    <script language="javascript" src="../../lib/jquery/plugins/artDialog4/artDialog.js" type="text/javascript"></script>\n    <script language="javascript" src="../../lib/jquery/plugins/artDialog4/jquery.artDialog.js" type="text/javascript"></script>\n    <script language="javascript" src="../../lib/jquery/plugins/artDialog4/plugins/iframeTools.js" type="text/javascript"></script>\n    <script language="javascript" src="../../lib/jquery/plugins/jquery-ui-1.11.4/jquery-ui.js" type="text/javascript"></script>\n    <link href="../../lib/jquery/plugins/jquery-ui-1.11.4/jquery-ui.css" rel="stylesheet" type="text/css"/>\n    <script language="javascript" src="../../lib/datepicker/WdatePicker.js" type="text/javascript"></script>\n    <script language="javascript" src="../../common/js/xdate.js" type="text/javascript"></script>\n    <!--[if lt IE 8]>\n    <script type="text/javascript" language="javascript" src="../../common/js/json2.js"></script>\n    <![endif]-->\n\n    <script language="javascript" src="js/manager_list.js" type="text/javascript"></script>\n</head>\n<body class="g-container">\n<div>\n    <!-- header start -->\n    <div class="g-header clearfix">\n        <a class="logo pull-left" href="/"><img alt="\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a" src="../../common/images/logo.png"/></a>\n        <div class="info pull-right">\n            <span id="IE67" style="display:none;"><span class="fontSpace">\u7ec4\u7ec7\u673a\u6784\u4ee3\u7801</span>\uff1a71783348<br/></span>\n            <span id="otherBrowser"><span class="fontSpace">\u7ec4\u7ec7\u673a\u6784\u4ee3</span>\u7801\uff1a71783348<br/></span>\n            \u793e\u4f1a\u56e2\u4f53\u6cd5\u4eba\u767b\u8bb0\u8bc1\u4e66\uff1a\u793e\u8bc1\u5b57\u7b2c4951\u53f7\n        </div>\n    </div>\n    <!-- header end -->\n\n    <!-- body start -->\n    <div class="g-body">\n        <!-- \u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u516c\u793a start -->\n        <div class="m-manager-list">\n            <h3 class="text-center font-xbig text-bold mb30">\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u5206\u7c7b\u516c\u793a</h3>\n            <p class="mb15"><a class="text-danger ml15" href="#" onclick="openAMACInfo();">&lt;\n                &lt;\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a\u63d0\u793a&gt;&gt;\n            </a></p>\n            <div id="tooggleAMACInfo" style="display:none;">\n\n            </div>\n\n            <!-- \u67e5\u8be2\u6761\u4ef6\u533a\u57df start -->\n            <div class="m-search-bar clearfix mb15">\n                <!-- <a href="javascript:openMap();" class="btn-map">\u6309\u5730\u56fe\u67e5\u8be2</a> -->\n                <form action="" class="form-horizontal" name="manager-list-form">\n                    <input id="fundType" type="hidden"/>\n                    <input id="remindItem" type="hidden"/>\n                    <input id="faithInfo" type="hidden"/>\n                    <input id="fundScaleFrom" type="hidden"/>\n                    <input id="fundScaleTo" type="hidden"/>\n                    <div class="control-group">\n                        <div class="control-label w100"><img onmouseout="hide(this,'fundTypeHint')" onmouseover="javascript:show(this,'fundTypeHint');" src="../../common/images/icon_tips.jpg" style="vertical-align:middle;"/>\u57fa\u91d1\u89c4\u6a21\uff1a\n                        </div>\n                        <div class="m-modal" id="fundTypeHint" style="display:none;position:absolute;width:650px;">\n                            <div class="modal-title">\u57fa\u91d1\u89c4\u6a21</div>\n                            <div class="modal-content">\n                                <p>1\u3001 \u5404\u533a\u95f4\u5185\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u4ee5\u5728\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a\u7684\u767b\u8bb0\u65f6\u95f4\u987a\u5e8f\u8fdb\u884c\u6392\u5217\uff1b</p>\n                                <p>2\u3001 \u57fa\u91d1\u89c4\u6a21\u4ee5\u7ba1\u7406\u4eba\u5728\u767b\u8bb0\u5907\u6848\u7cfb\u7edf\u4e2d\u586b\u62a5\u7684\u8ba4\u7f34\u89c4\u6a21\u4e3a\u51c6\uff1b</p>\n                                <p>3\u3001 \u57fa\u91d1\u6307\u6b63\u5728\u8fd0\u4f5c\u7684\u57fa\u91d1\uff0c\u4e0d\u5305\u62ec\u5df2\u7ecf\u6e05\u76d8\u7684\u57fa\u91d1\uff1b</p>\n                                <p>4\u3001 \u6839\u636e\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u6240\u7ba1\u7406\u57fa\u91d1\u7684\u4e0d\u540c\u7c7b\u578b\uff0c\u89c4\u6a21\u7c7b\u516c\u793a\u9009\u53d6\u4e0d\u540c\u7684\u5212\u5206\u6807\u51c6\uff0c\u7ba1\u7406\u89c4\u6a21\u5728\u533a\u95f4\u4e0b\u9650\u4ee5\u4e0b\u7684\u7ba1\u7406\u4eba\u4e0d\u5217\u5165\u5206\u7c7b\u516c\u793a\u8303\u56f4\uff1b</p>\n                                <p>5\u3001 \u7ba1\u7406\u4eba\u7ba1\u7406\u4e0d\u540c\u7c7b\u578b\u79c1\u52df\u57fa\u91d1\u7684\uff0c\u6839\u636e\u6240\u7ba1\u7406\u7684\u4e0d\u540c\u7c7b\u578b\u57fa\u91d1\u89c4\u6a21\u5206\u522b\u8fdb\u884c\u7edf\u8ba1\uff1b</p>\n                                <p>6\u3001 \u5176\u4ed6\u79c1\u52df\u57fa\u91d1\u4e3b\u8981\u662f\u6307\u4ece\u4e8b\u827a\u672f\u54c1\u3001\u5546\u54c1\u7b49\u6295\u8d44\u7684\u79c1\u52df\u57fa\u91d1\uff1b </p>\n                                <p>7\u3001 \u533a\u95f4\u5212\u5206\u6807\u51c6\u5c06\u6839\u636e\u884c\u4e1a\u53d1\u5c55\u60c5\u51b5\u8fdb\u884c\u52a8\u6001\u8c03\u6574 \u3002</p>\n                            </div>\n                        </div>\n                        <div class="controls" id="controls">\n                            <div onmouseout="hide(this,'showFundScale1')" onmouseover="javascript:chooseFundType(this,'showFundScale1');" value="\u79c1\u52df\u8bc1\u5238\u81ea\u4e3b\u53d1\u884c">\n                                <a class="btn-link mr10" href="javascript:void(0);" onclick="removeFundType(this);" value="\u79c1\u52df\u8bc1\u5238\u57fa\u91d1(\u81ea\u4e3b\u53d1\u884c)">\u79c1\u52df\u8bc1\u5238\u57fa\u91d1(\u81ea\u4e3b\u53d1\u884c)</a>\n                                <ul id="showFundScale1" style="display:none;background-color:rgb(222,230,248);position:absolute;">\n                                    <li onclick="javascript:chooseFundScale(this,'','');">\u5168\u90e8</li>\n                                    <li onclick="javascript:chooseFundScale(this,'500000','');">50 \u4ebf\u4ee5\u4e0a</li>\n                                    <li onclick="javascript:chooseFundScale(this,'200000','500000');">20-50 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'100000','200000');">10-20 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'10000','100000');">1-10 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'0','10000');">0-1 \u4ebf</li>\n                                </ul>\n                            </div>\n\n                            <div onmouseout="hide(this,'showFundScale2')" onmouseover="javascript:chooseFundType(this,'showFundScale2');" value="\u79c1\u52df\u8bc1\u5238\u987e\u95ee\u7ba1\u7406">\n                                <a class="btn-link mr10" href="javascript:void(0);" onclick="removeFundType(this);" value="\u79c1\u52df\u8bc1\u5238\u57fa\u91d1(\u987e\u95ee\u7ba1\u7406)">\u79c1\u52df\u8bc1\u5238\u57fa\u91d1(\u987e\u95ee\u7ba1\u7406)</a>\n                                <ul id="showFundScale2" style="display:none;background-color:rgb(222,230,248);position:absolute;">\n                                    <li onclick="javascript:chooseFundScale(this,'','');">\u5168\u90e8</li>\n                                    <li onclick="javascript:chooseFundScale(this,'500000','');">50 \u4ebf\u4ee5\u4e0a</li>\n                                    <li onclick="javascript:chooseFundScale(this,'200000','500000');">20-50 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'100000','200000');">10-20 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'10000','100000');">1-10 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'0','10000');">0-1 \u4ebf</li>\n                                </ul>\n\n                            </div>\n\n                            <div onmouseout="hide(this,'showFundScale3')" onmouseover="javascript:chooseFundType(this,'showFundScale3');" value="\u79c1\u52df\u80a1\u6743">\n                                <a class="btn-link mr10" href="javascript:void(0);" onclick="removeFundType(this);" value="\u79c1\u52df\u80a1\u6743\u57fa\u91d1">\u79c1\u52df\u80a1\u6743\u57fa\u91d1</a>\n                                <ul id="showFundScale3" style="display:none;background-color:rgb(222,230,248);position:absolute;">\n                                    <li onclick="javascript:chooseFundScale(this,'','');">\u5168\u90e8</li>\n                                    <li onclick="javascript:chooseFundScale(this,'1000000','');">100 \u4ebf\u4ee5\u4e0a</li>\n                                    <li onclick="javascript:chooseFundScale(this,'500000','1000000');">50-100 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'200000','500000');">20-50 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'0','200000');">0-20 \u4ebf</li>\n                                </ul>\n                            </div>\n\n                            <div onmouseout="hide(this,'showFundScale4')" onmouseover="javascript:chooseFundType(this,'showFundScale4');" value="\u521b\u4e1a\u6295\u8d44">\n                                <a class="btn-link mr10" href="javascript:void(0);" onclick="removeFundType(this);" value="\u521b\u4e1a\u6295\u8d44\u57fa\u91d1">\u521b\u4e1a\u6295\u8d44\u57fa\u91d1</a>\n                                <ul id="showFundScale4" style="display:none;background-color:rgb(222,230,248);position:absolute;">\n                                    <li onclick="javascript:chooseFundScale(this,'','');">\u5168\u90e8</li>\n                                    <li onclick="javascript:chooseFundScale(this,'100000','');">10 \u4ebf\u4ee5\u4e0a</li>\n                                    <li onclick="javascript:chooseFundScale(this,'50000','100000');">5-10 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'20000','50000');">2-5 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'0','20000');">0-2 \u4ebf</li>\n                                </ul>\n                            </div>\n\n                            <div onmouseout="hide(this,'showFundScale5')" onmouseover="javascript:chooseFundType(this,'showFundScale5');" value="\u5176\u5b83\u79c1\u52df">\n                                <a class="btn-link mr10" href="javascript:void(0);" onclick="removeFundType(this);" value="\u5176\u4ed6\u79c1\u52df\u57fa\u91d1">\u5176\u4ed6\u79c1\u52df\u57fa\u91d1</a>\n                                <ul id="showFundScale5" style="display:none;background-color:rgb(222,230,248);position:absolute;">\n                                    <li onclick="javascript:chooseFundScale(this,'','');">\u5168\u90e8</li>\n                                    <li onclick="javascript:chooseFundScale(this,'100000','');">10 \u4ebf\u4ee5\u4e0a</li>\n                                    <li onclick="javascript:chooseFundScale(this,'50000','100000');">5-10 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'20000','50000');">2-5 \u4ebf</li>\n                                    <li onclick="javascript:chooseFundScale(this,'0','20000');">0-2 \u4ebf</li>\n                                </ul>\n                            </div>\n                        </div>\n                    </div>\n\n                    <div class="control-group">\n                        <div class="control-label w100">\u63d0\u793a\u4e8b\u9879\uff1a</div>\n                        <div id="itemHint" style="display:none;position:absolute;solid:silver;background-color:#CCCCCC">\n                            \u8bf4\u660e\uff1a\u6b64\u7c7b\u516c\u793a\u4ee5\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u6210\u7acb\u65f6\u95f4\u5148\u540e\u987a\u5e8f\u8fdb\u884c\u6392\u5217\n                        </div>\n\n                        <div class="controls">\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseRemindItem(this);" value="manageScalaZero">\u7ba1\u7406\u89c4\u6a21\u4e3a\u96f6</a>\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseRemindItem(this);" value="oneYearManageScalaZero">\u767b\u8bb0\u4e00\u5e74\u4ee5\u4e0a\u7ba1\u7406\u89c4\u6a21\u4e3a\u96f6</a>\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseRemindItem(this);" value="handInUnderRegister25P">\u7ba1\u7406\u4eba\u5b9e\u7f34\u8d44\u672c\u4f4e\u4e8e\u6ce8\u518c\u8d44\u672c25%</a>\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseRemindItem(this);" value="handInLe100W">\u7ba1\u7406\u4eba\u5b9e\u7f34\u8d44\u672c\u4f4e\u4e8e100\u4e07</a>\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseRemindItem(this);" value="notNormalLiquidation">\u975e\u6b63\u5e38\u6e05\u7b97</a>\n                        </div>\n                    </div>\n\n                    <div class="control-group">\n                        <div class="control-label w100"><img onmouseout="hide(this,'faithInfoHint')" onmouseover="javascript:show(this,'faithInfoHint');" src="../../common/images/icon_tips.jpg" style="vertical-align:middle;"/>\u8bda\u4fe1\u4fe1\u606f\uff1a\n                        </div>\n                        <div class="m-modal" id="faithInfoHint" style="display:none;position:absolute;width:700px;z-index:10000;">\n                            <div class="modal-title">\u8bda\u4fe1\u4fe1\u606f</div>\n                            <div class="modal-content">\n                                <p>1\u3001\u6b64\u7c7b\u516c\u793a\u4ee5\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u5728\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a\u7684\u767b\u8bb0\u65f6\u95f4\u987a\u5e8f\u8fdb\u884c\u6392\u5217\uff1b</p>\n                                <p>\n                                    2\u3001\u4e0d\u826f\u8bda\u4fe1\u8bb0\u5f55\u4e3b\u8981\u5305\u62ec\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u3001\u5b9e\u9645\u63a7\u5236\u4eba\u3001\u76f8\u5173\u9ad8\u7ba1\u4eba\u5458\u53d7\u5230\u4e2d\u56fd\u8bc1\u76d1\u4f1a\u884c\u653f\u5904\u7f5a\u6216\u8005\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a\u7eaa\u5f8b\u5904\u5206\uff0c\u672c\u516c\u793a\u63d0\u4f9b\u8bc1\u76d1\u4f1a\u4fe1\u606f\u516c\u5f00\u548c\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a\u7eaa\u5f8b\u5904\u5206\u7684\u67e5\u8be2\u94fe\u63a5\uff1b</p>\n                                <p>3\u3001\u5217\u5165\u865a\u5047\u586b\u62a5\u3001\u91cd\u5927\u9057\u6f0f\u3001\u8fdd\u53cd\u4e09\u6761\u5e95\u7ebf\u7684\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\uff0c\u5982\u5df2\u7ecf\u5b8c\u6210\u6574\u6539\uff0c\u5219\u4e0d\u518d\u5217\u5165\u6b64\u7c7b\u516c\u793a\u3002</p>\n                            </div>\n                        </div>\n                        <div class="controls">\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseFaithInfo(this);" value="isLostContactMechanism">\u5931\u8054\u673a\u6784</a>\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseFaithInfo(this);" value="identification">\u5f02\u5e38\u673a\u6784</a>\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseFaithInfo(this);" value="shamStatement">\u865a\u5047\u586b\u62a5</a>\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseFaithInfo(this);" value="materRialOmission">\u91cd\u5927\u9057\u6f0f</a>\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseFaithInfo(this);" value="eightLine">\u8fdd\u53cd\u516b\u6761\u5e95\u7ebf</a>\n                            <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseFaithInfo(this);" value="badCredit">\u76f8\u5173\u4e3b\u4f53\u5b58\u5728\u4e0d\u826f\u8bda\u4fe1\u8bb0\u5f55</a>\n                        </div>\n                    </div>\n\n                    <div id="foldArea" style="display:none;">\n                        <div class="control-group">\n                            <div class="control-label w100">\u6210\u7acb\u65f6\u95f4\uff1a</div>\n                            <div class="controls">\n                                <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:choosePeriods(this);" value="1">\u6700\u8fd1\u4e00\u5b63\u5ea6</a>\n                                <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:choosePeriods(this);" value="2">\u6700\u8fd1\u4e00\u5e74</a>\n                                <input class="datepicker" id="foundBeginDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text" value=""/>\xa0-\xa0\n                                <input class="datepicker" id="foundEndDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text" value=""/>\n                            </div>\n                        </div>\n                        <div class="control-group">\n                            <div class="control-label w100">\u767b\u8bb0\u65f6\u95f4\uff1a</div>\n                            <div class="controls">\n                                <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseCheckTime(this);" value="1">\u6700\u8fd1\u4e00\u6708</a>\n                                <a class="btn-link mr10" href="javascript:void(0);" onclick="javascript:chooseCheckTime(this);" value="2">\u6700\u8fd1\u4e00\u5b63\u5ea6</a>\n                                <input class="datepicker" id="checkBeginDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text" value=""/>\xa0-\xa0\n                                <input class="datepicker" id="checkEndDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text" value=""/>\n                            </div>\n                        </div>\n                    </div>\n                    <!--     <div  style="text-align:center;top:-1px;border-top: 1px solid #ddd;padding-top:0px;">\n                            <span onclick="queryCollapsed(this);" style="cursor:pointer;width:100px;background:#F6F6F6;display:inline-block;margin-top:-1px;line-height:28px; text-align:center;border: 1px solid #ddd;padding:0px 10px 4px 10px;border-top:0px;">\u66f4\u591a\u9009\u9879\u2193</span>\n                        </div> -->\n\n                    <div class="control-group text-right">\n                        <input class="btn btn-primary" onclick="gotoManagerList();" style="padding:0px;" type="button" value="\u7efc\u5408\u67e5\u8be2"/>\n                        <input class="btn btn-primary" onclick="reload();" style="display:none;" type="button" value="\u67e5\u8be2"/>\n                        <input class="btn btn-clear ml10 mr40" id="reset" style="display:none;" type="button" value="\u6e05\u7a7a\u6761\u4ef6"/>\n                    </div>\n                </form>\n            </div>\n            <!-- \u67e5\u8be2\u6761\u4ef6\u533a\u57df end -->\n\n            <!-- \u8bf4\u660e -->\n            <div class="m-pager">\n                <span class="label-tips text-mult pull-left text-danger">\u6ce8\uff1a\u5e26\xa0<span class="text-danger">*</span>\xa0\u53f7\u7684\u673a\u6784\u76ee\u524d\u6ca1\u6709\u6b63\u5728\u7ba1\u7406\u7684\u79c1\u52df\u57fa\u91d1</span>\n                <br/>\n            </div>\n            <!-- \u6570\u636e\u8868\u683c start -->\n            <table class="table table-center" id="managerList">\n                <colgroup>\n                    <col width="7%"/>\n                    <col width="27%"/>\n                    <col width="18%"/>\n                    <col width="14%"/>\n                    <col width="12%"/>\n                    <col width="12%"/>\n                    <col width="12%"/>\n                </colgroup>\n                <thead>\n                <tr>\n                    <th>\u7f16\u53f7</th>\n                    <th>\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u540d\u79f0</th>\n                    <th>\u6cd5\u5b9a\u4ee3\u8868\u4eba/\u6267\u884c\u4e8b\u52a1\u5408\u4f19\u4eba(\u59d4\u6d3e\u4ee3\u8868)\u59d3\u540d</th>\n                    <th>\u6ce8\u518c\u5730</th>\n                    <th>\u767b\u8bb0\u7f16\u53f7</th>\n                    <th>\u6210\u7acb\u65f6\u95f4</th>\n                    <th>\u767b\u8bb0\u65f6\u95f4</th>\n                </tr>\n                </thead>\n            </table>\n        </div>\n        <!-- \u6570\u636e\u8868\u683c end -->\n    </div>\n    <!-- \u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u516c\u793a end -->\n\n</div>\n<!-- body end -->\n<div align="center" class="g-body" id="dialog-title" style="display:none" title="\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a\u63d0\u793a">\n    <!-- \u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u516c\u793a start -->\n    <div class="m-manager-list">\n        <br/>\n        <div id="noticeInfo">\n            <p class="mb15" style="text-align: left;">\xa0\xa0\xa0\xa0\xa0\xa0\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u89c4\u6a21\u7c7b\u3001\u63d0\u793a\u7c7b\u516c\u793a\u4fe1\u606f\u5747\u6765\u6e90\u4e8e\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a\u5df2\u767b\u8bb0\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u63d0\u4f9b\u7684\u4fe1\u606f\uff0c\u57fa\u91d1\u7ba1\u7406\u4eba\u5df2\u4e66\u9762\u627f\u8bfa\u6240\u6709\u586b\u62a5\u4fe1\u606f\u771f\u5b9e\u3001\u51c6\u786e\u3001\u5b8c\u6574\uff0c\u5e76\u627f\u8bfa\u627f\u62c5\u6240\u6709\u76f8\u5173\u6cd5\u5f8b\u8d23\u4efb\u3002</p>\n            <p class="mb15" style="text-align: left;">\xa0\xa0\xa0\xa0\xa0\xa0\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a\u5bf9\u79c1\u52df\u57fa\u91d1\u767b\u8bb0\u5907\u6848\u4fe1\u606f\u4e0d\u505a\u5b9e\u8d28\u6027\u4e8b\u524d\u5ba1\u67e5\u3002\u516c\u793a\u4fe1\u606f\u4e0d\u6784\u6210\u5bf9\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u6295\u8d44\u7ba1\u7406\u80fd\u529b\u3001\u6301\u7eed\u5408\u89c4\u60c5\u51b5\u7684\u8ba4\u53ef\uff0c\u4e0d\u4f5c\u4e3a\u57fa\u91d1\u8d44\u4ea7\u5b89\u5168\u7684\u4fdd\u8bc1\u3002</p>\n            <p class="mb15" style="text-align: left;">\xa0\xa0\xa0\xa0\xa0\xa0\u6295\u8d44\u8005\u8fdb\u884c\u79c1\u52df\u57fa\u91d1\u6295\u8d44\u65f6\u987b\u8c28\u614e\u5224\u65ad\u548c\u8bc6\u522b\u98ce\u9669\u3002</p>\n            <p class="mb15" style="text-align: left;">\xa0\xa0\xa0\xa0\xa0\xa0\u793e\u4f1a\u516c\u4f17\u82e5\u53d1\u73b0\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u5206\u7c7b\u516c\u793a\u4fe1\u606f\u4e2d\u5b58\u5728\u4efb\u4f55\u865a\u5047\u6216\u4e0d\u5b9e\u5185\u5bb9\uff0c\u8bf7\u5c06\u76f8\u5173\u5b9e\u540d\u4e3e\u62a5\u6216\u6295\u8bc9\u60c5\u51b5\u53d1\u9001\u81f3\u90ae\u7bb1\uff1a<a class="a1" href="mailto:tousu@amac.org.cn" style="color: #173bf4;">tousu@amac.org.cn</a>\uff0c\u6216\u90ae\u5bc4\u81f3\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a\uff08\u5730\u5740\uff1a<font class="a1">\u5317\u4eac\u5e02\u897f\u57ce\u533a\u91d1\u878d\u5927\u885720\u53f7\u4ea4\u901a\u94f6\u884c\u5927\u53a6B\u5ea79\u5c42\uff0c\u90ae\u7f16100033\uff0c\u8bf7\u6807\u660e\u201c\u6cd5\u5f8b\u90e8\u6536\u201d</font>\uff09\u3002\u8be6\u89c1\u534f\u4f1a\u5b98\u7f51\u201c\u6295\u8d44\u8005\u6559\u80b2\u201d\u680f\u76ee\u4e2d\u201c\u6295\u8bc9\u987b\u77e5\u201d\u3002</p>\n            <p class="mb15" style="text-align: left;">\xa0\xa0\xa0\xa0\xa0\xa0\u5217\u5165\u5206\u7c7b\u516c\u793a\u7684\u79c1\u52df\u57fa\u91d1\u7ba1\u7406\u4eba\u5982\u5bf9\u5206\u7c7b\u516c\u793a\u6709\u5f02\u8bae\uff0c\u8bf7\u53d1\u51fd\u81f3\u90ae\u7bb1\uff1a<a class="a1" href="mailto:pf@amac.org.cn" style="color: #173bf4;">pf@amac.org.cn</a>\u3002</p>\n        </div>\n        <div id="timeShow" style="font-size:20px;font-weight:800;color:#FF9900">5 S</div>\n    </div>\n</div>\n\n<!-- footer start -->\n<div class="g-footer" style="position:relative;">\u7248\u6743\u6240\u6709\uff1a\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a \u4eacICP\u590716045718\u53f7\xa0\xa0\xa0\xa0\n    \u6d4f\u89c8\u91cf\uff1a<span id="clickCount"></span>\n</div>\n<!-- footer end -->\n\n</body></html>

In [26]:
# coding=utf-8
import urllib
import urllib2
import json

#url地址
url='https://www.baidu.com/s'
#参数
values={
        'ie':'UTF-8',
        'wd':'test'  
        }
#进行参数封装
data=urllib.urlencode(values)
#组装完整url
req=urllib2.Request(url,data)

#访问完整url
response = urllib2.urlopen(req)
html = response.read()

print (html)


<!DOCTYPE html>
<!--STATUS OK-->
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <meta content="always" name="referrer">
    <title>页面不存在_百度搜索</title>
    <style data-for="result">
        body {color: #333; background: #fff; padding: 0; margin: 0; position: relative; min-width: 700px; font-family: arial; font-size: 12px }
        p, form, ol, ul, li, dl, dt, dd, h3 {margin: 0; padding: 0; list-style: none }
        input {padding-top: 0; padding-bottom: 0; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box } img {border: none; }
        .logo {width: 117px; height: 38px; cursor: pointer }
         #wrapper {_zoom: 1 }
        #head {padding-left: 35px; margin-bottom: 20px; width: 900px }
        .fm {clear: both; position: relative; z-index: 297 }
        .btn, #more {font-size: 14px } 
        .s_btn {width: 95px; height: 32px; padding-top: 2px\9; font-size: 14px; padding: 0; background-color: #ddd; background-position: 0 -48px; border: 0; cursor: pointer }
        .s_btn_h {background-position: -240px -48px }
        .s_btn_wr {width: 97px; height: 34px; display: inline-block; background-position: -120px -48px; *position: relative; z-index: 0; vertical-align: top }
        #foot {}
        #foot span {color: #666 }
        .s_ipt_wr {height: 32px }
        .s_form:after, .s_tab:after {content: "."; display: block; height: 0; clear: both; visibility: hidden }
        .s_form {zoom: 1; height: 55px; padding: 0 0 0 10px }
        #result_logo {float: left; margin: 7px 0 0 }
        #result_logo img {width: 101px }
        #head {padding: 0; margin: 0; width: 100%; position: absolute; z-index: 301; min-width: 1000px; background: #fff; border-bottom: 1px solid #ebebeb; position: fixed; _position: absolute; -webkit-transform: translateZ(0) }
        #head .head_wrapper {_width: 1000px }
        #head.s_down {box-shadow: 0 0 5px #888 }
        .fm {clear: none; float: left; margin: 11px 0 0 10px }
        #s_tab {background: #f8f8f8; line-height: 36px; height: 38px; padding: 55px 0 0 121px; float: none; zoom: 1 }
        #s_tab a, #s_tab b {width: 54px; display: inline-block; text-decoration: none; text-align: center; color: #666; font-size: 14px }
        #s_tab b {border-bottom: 2px solid #38f; font-weight: bold; color: #323232 }
        #s_tab a:hover {color: #323232 }
        #content_left {width: 540px; padding-left: 121px; padding-top: 5px }
        .to_tieba, .to_zhidao_bottom {margin: 10px 0 0 121px }
        #help {background: #f5f6f5; zoom: 1; padding: 0 0 0 50px; float: right }
        #help a {color: #777; padding: 0 15px; text-decoration: none }
        #help a:hover {color: #333 }
        #foot {position: fixed; bottom:0; width: 100%; background: #f5f6f5; border-top: 1px solid #ebebeb; text-align: left; height: 42px; line-height: 42px; margin-top: 40px; *margin-top: 0; _position:absolute; _bottom:auto; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0))); }

        .content_none {padding: 45px 0 25px 121px } .s_ipt_wr.bg,
        .s_btn_wr.bg, #su.bg {background-image: none }
        .s_ipt_wr.bg {background: 0 }
        .s_btn_wr {width: auto; height: auto; border-bottom: 1px solid transparent; *border-bottom: 0 }
        .s_btn {width: 100px; height: 34px; color: white; letter-spacing: 1px; background: #3385ff; border-bottom: 1px solid #2d78f4; outline: medium; *border-bottom: 0; -webkit-appearance: none; -webkit-border-radius: 0 }
        .s_btn:hover {background: #317ef3; border-bottom: 1px solid #2868c8; *border-bottom: 0; box-shadow: 1px 1px 1px #ccc }
        .s_btn:active {background: #3075dc; box-shadow: inset 1px 1px 3px #2964bb; -webkit-box-shadow: inset 1px 1px 3px #2964bb; -moz-box-shadow: inset 1px 1px 3px #2964bb; -o-box-shadow: inset 1px 1px 3px #2964bb }
        #lg {display: none }
        #head .headBlock {margin: -5px 0 6px 121px }
        #content_left .leftBlock {margin-bottom: 14px; padding-bottom: 5px; border-bottom: 1px solid #f3f3f3 }
        .s_ipt_wr {border: 1px solid #b6b6b6; border-color: #7b7b7b #b6b6b6 #b6b6b6 #7b7b7b; background: #fff; display: inline-block; vertical-align: top; width: 539px; margin-right: 0; border-right-width: 0; border-color: #b8b8b8 transparent #ccc #b8b8b8; overflow: hidden }
        .s_ipt_wr.ip_short {width: 439px; }
        .s_ipt_wr:hover, .s_ipt_wr.ipthover {border-color: #999 transparent #b3b3b3 #999 }
        .s_ipt_wr.iptfocus {border-color: #4791ff transparent #4791ff #4791ff }
        .s_ipt_tip {color: #aaa; position: absolute; z-index: -10; font: 16px/22px arial; height: 32px; line-height: 32px; padding-left: 7px; overflow: hidden; width: 526px }
        .s_ipt {width: 526px; height: 22px; font: 16px/18px arial; line-height: 22px\9; margin: 6px 0 0 7px; padding: 0; background: transparent; border: 0; outline: 0; -webkit-appearance: none }
        #kw {position: relative;display: inline-block;}
        input::-ms-clear {display: none }
        /*Error page css*/
        .norsSuggest {display: inline-block; color: #333; font-family: arial; font-size: 13px; position: relative; } 
        .norsTitle {font-size: 22px; font-family: Microsoft Yahei; font-weight: normal; color: #333; margin: 35px 0 25px 0; }
        .norsTitle2 {font-family: arial; font-size: 13px; color: #666; }
        .norsSuggest ol {margin-left: 47px; }
        .norsSuggest li {margin: 13px 0; }
    </style>
</head>

<body link="#0000cc">
    <div id="wrapper" class="wrapper_l">
        <div id="head">
            <div class="head_wrapper">
                <div class="s_form">
                    <div class="s_form_wrapper">
                        <a href="/" id="result_logo"><img src="//www.baidu.com/img/baidu_jgylogo3.gif" alt="到百度首页" title="到百度首页"></a>
                        <form id="form" name="f" action="/s" class="fm">
                            <input type="hidden" name="ie" value="utf-8">
                            <input type="hidden" name="f" value="8">
                            <input type="hidden" name="rsv_bp" value="1">
                            <input type="hidden" name="ch" value="">
                            <input type="hidden" name="tn" value="baiduerr">
                            <input type="hidden" name="bar" value="">
                            <span class="bg s_ipt_wr iptfocus">
                            	<input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off" autofocus>
                            </span><span class="bg s_btn_wr">
                            	<input type="submit" id="su" value="百度一下" class="bg s_btn">
                            </span>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="s_tab" id="s_tab"><b>网页</b><a href="http://news.baidu.com/ns?cl=2&rn=20&tn=news&word=" wdfield="word">新闻</a><a href="http://tieba.baidu.com/f?kw=&fr=wwwt" wdfield="kw">贴吧</a><a href="http://zhidao.baidu.com/q?ct=17&pn=0&tn=ikaslist&rn=10&word=&fr=wwwt" wdfield="word">知道</a><a href="http://music.baidu.com/search?fr=ps&ie=utf-8&key=" wdfield="key">音乐</a><a href="http://image.baidu.com/i?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&ie=utf-8&word=" wdfield="word">图片</a><a href="http://v.baidu.com/v?ct=301989888&rn=20&pn=0&db=0&s=25&ie=utf-8&word=" wdfield="word">视频</a><a href="http://map.baidu.com/m?word=&fr=ps01000" wdfield="word">地图</a><a href="http://wenku.baidu.com/search?word=&lm=0&od=0&ie=utf-8" wdfield="word">文库</a><a href="//www.baidu.com/more/">更多»</a></div>
    <div id="wrapper_wrapper">
        <div id="content_left">
            <div class="nors">
                <div class="norsSuggest">
                    <h3 class="norsTitle">很抱歉,您要访问的页面不存在!</h3>
                    <p class="norsTitle2">温馨提示:</p>
                    <ol>
                        <li>请检查您访问的网址是否正确</li>
                        <li>如果您不能确认访问的网址,请浏览<a href="//www.baidu.com/more/index.html">百度更多</a>页面查看更多网址。</li>
                        <li>回到顶部重新发起搜索</li>
                        <li>如有任何意见或建议,请及时<a href="http://qingting.baidu.com/index">反馈给我们</a>。</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
    <div id="foot">
		<span id="help" style="float:left;padding-left:121px">
			<a href="http://help.baidu.com/question" target="_blank">帮助</a>
			<a href="http://www.baidu.com/search/jubao.html" target="_blank">举报</a>
            <a href="http://jianyi.baidu.com" target="_blank">给百度提建议</a>
		</span>
    </div>
</body>
<script>
(function(){
    var bds = {
        util: {}
    };
    var c = document.getElementById('kw').parentNode;

    bds.util.getWinWidth = function(){
        return window.document.documentElement.clientWidth;
    };

    bds.util.setFormWidth = function(){
        var width = bds.util.getWinWidth();
        if(width < 1217)    {bds.util.setClass(c, 'ip_short', 'add')}
        else                {bds.util.setClass(c, 'ip_short', 'remove')};
    };

    bds.util.setClass = function(obj, class_name, set) {
        var ori_class = obj.className,
            has_class_p = -1,
            ori_class_arr = [],
            new_class = '';

        if(ori_class.length) ori_class_arr = ori_class.split(' ');

        for( i in ori_class_arr) {
            if(ori_class_arr[i] == class_name) has_class_p = i;
        }

        if( set == 'remove' && has_class_p >= 0) {
            ori_class_arr.splice(has_class_p, 1);
            new_class = ori_class_arr.join(' ');
            obj.className = new_class;
        } else if( set == 'add' && has_class_p < 0) {
            ori_class_arr.push(class_name);
            new_class = ori_class_arr.join(' ');
            obj.className = new_class;
        }
    }
    bds.util.setFormWidth();

    if (typeof document.addEventListener != "undefined") {
        window.addEventListener('resize', bds.util.setFormWidth, false);
        document.getElementById('kw').addEventListener('focus', function(){bds.util.setClass(c,'iptfocus', 'add');}, false);
        document.getElementById('kw').addEventListener('blur', function(){bds.util.setClass(c,'iptfocus', 'remove');}, false);
    } else {
        window.attachEvent('onresize', bds.util.setFormWidth, false);
        document.getElementById('kw').attachEvent('onfocus', function(){bds.util.setClass(c,'iptfocus', 'add');}, false);
        document.getElementById('kw').attachEvent('onblur', function(){bds.util.setClass(c,'iptfocus', 'remove');}, false);
    } 

})();

</script>

</html>


In [31]:
json.loads(response.read())


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-31-90e1349c89f5> in <module>()
----> 1 json.loads(response.read())

c:\python27\lib\json\__init__.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    337             parse_int is None and parse_float is None and
    338             parse_constant is None and object_pairs_hook is None and not kw):
--> 339         return _default_decoder.decode(s)
    340     if cls is None:
    341         cls = JSONDecoder

c:\python27\lib\json\decoder.pyc in decode(self, s, _w)
    362 
    363         """
--> 364         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    365         end = _w(s, end).end()
    366         if end != len(s):

c:\python27\lib\json\decoder.pyc in raw_decode(self, s, idx)
    380             obj, end = self.scan_once(s, idx)
    381         except StopIteration:
--> 382             raise ValueError("No JSON object could be decoded")
    383         return obj, end

ValueError: No JSON object could be decoded

In [127]:
import requests
from bs4 import BeautifulSoup
import json
import re

# 确定测试爬虫页面
#page_index = input('Pls input the page_index you want to try:')
surl = 'http://gs.amac.org.cn/amac-infodisc/res/pof/manager/101000000138.html'

# 使用requests获取网页
r = requests.get( surl)
#content = re.sub(r'(?m)^\<!--.*\n?', '', r.content)
#content = re.sub(r'(?m)^\-->.*\n?', '', content)
soup = BeautifulSoup(r.content, 'html.parser')
#print len(soup.find_all('table'))
for table in soup.find_all('table'):
    if table.findParent("table") is None:
        print "\n\n", str(table)

# 使用BS提取内容
#soup = BeautifulSoup(req.content,'lxml')

# 使用json将其转换为dict
#res_json = json.loads(res)
#json.dumps(res_json, indent = 4)



<table class="table table-center table-info">
<colgroup>
<col width="25%"/>
<col width="25%"/>
<col width="25%"/>
<col width="25%"/>
</colgroup>
<tbody>
<tr>
<td class="td-title">机构诚信信息:</td>
<td class="td-content" colspan="3">
<table class="table table-center table-info">
</table>
</td>
</tr>
<tr>
<td colspan="4" style="padding: 0px 0px;text-align: left;">
<div style="background-color: #DFDFDF;padding: 8px 10px;font-weight:bold;">机构信息</div>
</td>
</tr>
<tr>
<td class="td-title">基金管理人全称(中文):</td>
<td class="td-content" colspan="2">
<div id="complaint1" style="display: none;">平安道远投资管理(上海)有限公司  </div>
<div id="complaint2">平安道远投资管理(上海)有限公司   <input id="complaint" onclick="complain();" style="border:none;background-color:#b64545;color:#FFF;width:50px;border-radius:4px;" type="button" value="投诉"/>
</div>
</td>
<td class="td-code" rowspan="3">
<div id="qrcode"></div>
</td>
</tr>
<tr>
<td class="td-title">基金管理人全称(英文):</td>
<td class="td-content" colspan="2">Ping An DaoYuan Investment Management (Shanghai) Co., Ltd.</td>
</tr>
<tr>
<td class="td-title">登记编号:</td>
<td class="td-content" colspan="2">P1000182</td>
</tr>
<tr>
<td class="td-title">组织机构代码:</td>
<td class="td-content" colspan="3">57075680-3</td>
</tr>
<tr>
<td class="td-title">登记时间:</td>
<td class="td-content">
                        2014-03-17
                    </td>
<td class="td-title">成立时间:</td>
<td class="td-content">
                        2011-03-15
                    </td>
</tr>
<tr>
<td class="td-title">注册地址:</td>
<td class="td-content" colspan="3">上海市浦东新区浦东新区张杨路707号生命人寿大厦39楼03室</td>
</tr>
<tr>
<td class="td-title">办公地址:</td>
<td class="td-content" colspan="3">上海市浦东新区浦东新区陆家嘴环路1333号平安金融大厦11楼</td>
</tr>
<tr>
<td class="td-title">注册资本(万元)(人民币):</td>
<td class="td-content">20,000</td>
<td class="td-title">实缴资本(万元)(人民币):</td>
<td class="td-content">20,000</td>
</tr>
<tr>
<td class="td-title">企业性质:</td>
<td class="td-content">内资企业</td>
<td class="td-title">注册资本实缴比例:</td>
<td class="td-content">
                                100%
                    </td>
</tr>
<tr>
<td class="td-title">管理基金主要类别:</td>
<td class="td-content">证券投资基金</td>
<td class="td-title">申请的其他业务类型:</td>
<td class="td-content">
</td>
</tr>
<tr>
<td class="td-title">员工人数:</td>
<td class="td-content">34</td>
<td class="td-title">机构网址:</td>
<td class="td-content">
<a href="javascript:void(0);" onclick="javascript:gotoWebsite('http://russell.pingan.com/index.shtml');">http://russell.pingan.com/index.shtml</a>
</td>
</tr>
<!-- 会员开始 -->
<tr>
<td colspan="4" style="padding: 0px 0px;text-align: left;">
<div style="background-color: #DFDFDF;padding: 8px 10px;font-weight:bold;">会员信息</div>
</td>
</tr>
<tr>
<td class="td-title">是否为会员:</td>
<td class="td-content" colspan="3">是</td>
</tr>
<tr>
<td class="td-title">当前会员类型:</td>
<td class="td-content">观察会员</td>
<td class="td-title">入会时间:</td>
<td class="td-content">2013-05-08</td>
</tr>
<!-- 会员结束 -->
<!-- 法律意见书信息开始 -->
<tr>
<td colspan="4" style="padding: 0px 0px;text-align: left;">
<div style="background-color: #DFDFDF;padding: 8px 10px;font-weight:bold;">法律意见书信息</div>
</td>
</tr>
<tr>
<td class="td-title">法律意见书状态:</td>
<td class="td-content" colspan="3">
</td>
</tr>
<!-- 法律意见书信息结束 -->
<tr>
<td colspan="4" style="padding: 0px 0px;text-align: left;">
<div style="background-color: #DFDFDF;padding: 8px 10px;font-weight:bold;">高管信息</div>
</td>
</tr>
<tr>
<td class="td-title">法定代表人/执行事务合伙人(委派代表)姓名:</td>
<td class="td-content" colspan="3">杨晓华</td>
</tr>
<tr>
<td class="td-title">是否有从业资格:</td>
<td class="td-content">
                            是
                    </td>
<td class="td-title">资格取得方式:</td>
<td class="td-content">资格认定</td>
</tr>
<tr>
<td class="td-title">法定代表人/执行事务合伙人(委派代表)工作履历:</td>
<td class="td-content" colspan="3">
<table class="table table-center table-noborder" style="width:80%;">
<colgroup>
<col width="30%"/>
<col width="40%"/>
<col width="30%"/>
</colgroup>
<thead>
<tr>
<th>时间</th>
<th>任职单位</th>
<th>职务</th>
</tr>
</thead>
<tbody>
<tr>
<td>2015.09 -
                                                2017.04
                                        </td>
<td>平安道远投资管理(上海)有限公司</td>
<td>董事长兼总经理</td>
</tr>
<tr>
<td>2010.10 -
                                                2015.09
                                        </td>
<td>平安罗素</td>
<td>董事长兼总经理</td>
</tr>
<tr>
<td>2009.11 -
                                                2010.08
                                        </td>
<td>平安香港投资管理公司</td>
<td>董事常务副总</td>
</tr>
<tr>
<td>1999.10 -
                                                2009.10
                                        </td>
<td>平安香港保险</td>
<td>董事总经理</td>
</tr>
<tr>
<td>1996.11 -
                                                1999.10
                                        </td>
<td>平安香港海外</td>
<td>负责人</td>
</tr>
<tr>
<td>1996.02 -
                                                1996.11
                                        </td>
<td>平安总部核赔部</td>
<td>总经理</td>
</tr>
<tr>
<td>1995.03 -
                                                1996.02
                                        </td>
<td>平安总部核保部</td>
<td>总经理</td>
</tr>
<tr>
<td>1992.04 -
                                                1995.03
                                        </td>
<td>平安总部国际部</td>
<td>总经理</td>
</tr>
<tr>
<td>1989.09 -
                                                1992.04
                                        </td>
<td>深圳平安公司对外业务部</td>
<td>副经理</td>
</tr>
<tr>
<td>1987.09 -
                                                1989.09
                                        </td>
<td>大连海运学院</td>
<td>教师</td>
</tr>
<tr>
<td>1983.09 -
                                                1985.09
                                        </td>
<td>大连海运学院</td>
<td>教师</td>
</tr>
</tbody>
</table>
<table class="table table-noborder table-responsive">
<tbody>
<tr>
<td>时间:2015.09 -
                                                2017.04
                                        </td>
</tr>
<tr>
<td>任职单位:平安道远投资管理(上海)有限公司</td>
</tr>
<tr>
<td>职务:董事长兼总经理</td>
</tr>
<tr>
<td>时间:2010.10 -
                                                2015.09
                                        </td>
</tr>
<tr>
<td>任职单位:平安罗素</td>
</tr>
<tr>
<td>职务:董事长兼总经理</td>
</tr>
<tr>
<td>时间:2009.11 -
                                                2010.08
                                        </td>
</tr>
<tr>
<td>任职单位:平安香港投资管理公司</td>
</tr>
<tr>
<td>职务:董事常务副总</td>
</tr>
<tr>
<td>时间:1999.10 -
                                                2009.10
                                        </td>
</tr>
<tr>
<td>任职单位:平安香港保险</td>
</tr>
<tr>
<td>职务:董事总经理</td>
</tr>
<tr>
<td>时间:1996.11 -
                                                1999.10
                                        </td>
</tr>
<tr>
<td>任职单位:平安香港海外</td>
</tr>
<tr>
<td>职务:负责人</td>
</tr>
<tr>
<td>时间:1996.02 -
                                                1996.11
                                        </td>
</tr>
<tr>
<td>任职单位:平安总部核赔部</td>
</tr>
<tr>
<td>职务:总经理</td>
</tr>
<tr>
<td>时间:1995.03 -
                                                1996.02
                                        </td>
</tr>
<tr>
<td>任职单位:平安总部核保部</td>
</tr>
<tr>
<td>职务:总经理</td>
</tr>
<tr>
<td>时间:1992.04 -
                                                1995.03
                                        </td>
</tr>
<tr>
<td>任职单位:平安总部国际部</td>
</tr>
<tr>
<td>职务:总经理</td>
</tr>
<tr>
<td>时间:1989.09 -
                                                1992.04
                                        </td>
</tr>
<tr>
<td>任职单位:深圳平安公司对外业务部</td>
</tr>
<tr>
<td>职务:副经理</td>
</tr>
<tr>
<td>时间:1987.09 -
                                                1989.09
                                        </td>
</tr>
<tr>
<td>任职单位:大连海运学院</td>
</tr>
<tr>
<td>职务:教师</td>
</tr>
<tr>
<td>时间:1983.09 -
                                                1985.09
                                        </td>
</tr>
<tr>
<td>任职单位:大连海运学院</td>
</tr>
<tr>
<td>职务:教师</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="td-title">高管情况:</td>
<td class="td-content" colspan="3">
<table class="table table-center table-noborder" style="width:80%;">
<colgroup>
<col width="30%"/>
<col width="40%"/>
<col width="30%"/>
</colgroup>
<thead>
<tr>
<th>高管姓名</th>
<th>职务</th>
<th>是否具有基金从业资格</th>
</tr>
</thead>
<tbody>
<tr>
<td>杨晓华</td>
<td>法定代表人  董事长  总经理  其他</td>
<td>
                                                是(资格认定)
                                        </td>
</tr>
<tr>
<td>周娟</td>
<td>合规风控  信息填报负责人  其他</td>
<td>
                                                是(通过考试)
                                        </td>
</tr>
<tr>
<td>张存相</td>
<td>其他</td>
<td>
                                                是(通过考试)
                                        </td>
</tr>
<tr>
<td>瞿立杰</td>
<td>其他</td>
<td>
                                                是(通过考试)
                                        </td>
</tr>
</tbody>
</table>
<table class="table table-noborder table-responsive">
<tbody>
<tr>
<td>高管姓名:杨晓华</td>
</tr>
<tr>
<td>职务:法定代表人  董事长  总经理  其他</td>
</tr>
<tr>
<td>
                                            是否具有基金从业资格:
                                                是(资格认定)
                                        </td>
</tr>
<tr>
<td>高管姓名:周娟</td>
</tr>
<tr>
<td>职务:合规风控  信息填报负责人  其他</td>
</tr>
<tr>
<td>
                                            是否具有基金从业资格:
                                                是(通过考试)
                                        </td>
</tr>
<tr>
<td>高管姓名:张存相</td>
</tr>
<tr>
<td>职务:其他</td>
</tr>
<tr>
<td>
                                            是否具有基金从业资格:
                                                是(通过考试)
                                        </td>
</tr>
<tr>
<td>高管姓名:瞿立杰</td>
</tr>
<tr>
<td>职务:其他</td>
</tr>
<tr>
<td>
                                            是否具有基金从业资格:
                                                是(通过考试)
                                        </td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td colspan="4" style="padding: 0px 0px;text-align: left;">
<div style="background-color: #DFDFDF;padding: 8px 10px;font-weight:bold;">产品信息</div>
</td>
</tr>
<tr>
<td class="td-title">暂行办法实施前成立的基金:</td>
<td class="td-content" colspan="3">
<p><a href="../fund/351000131340.html">平安资产MOM1号资产管理产品</a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000128351.html">罗素投资合格投资者中国基金</a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000128367.html">平安人寿绝对收益账户</a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000128350.html">交银国信 平安罗素MOM一期多元投资集合资金信托计划</a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000144727.html">平安资产MOM2号保险资产管理产品</a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000144730.html">平安资产MOM3号保险资产管理产品</a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
</td>
</tr>
<tr>
<td class="td-title">暂行办法实施后成立的基金:</td>
<td class="td-content" colspan="3">
<p><a href="../fund/1705030955106523.html">平安道远STAR21号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000411156.html">平安道远STAR27号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露7条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000398101.html">平安道远STAR19号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露7条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000337686.html">平安道远STAR2号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露6条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000411159.html">平安道远STAR28号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000337690.html">平安道远STAR3号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000398107.html">平安道远STAR20号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露7条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000337693.html">平安道远STAR4号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000398044.html">平安道远STAR10号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000411165.html">平安道远STAR29号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000747226.html">平安道远投资管理(上海)有限公司稳盈1号私募投资基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露1条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000221216.html">平安养老-平安罗素道远1号资产管理产品 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000398083.html">平安道远STAR17号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000398027.html">平安道远STAR8号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000411149.html">平安道远STAR26号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露7条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000398095.html">平安道远STAR18号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露2条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000337328.html">平安道远STAR1号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000398070.html">平安道远STAR15号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000264901.html">平安道远金锁2号基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000398079.html">平安道远STAR16号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000398143.html">平安道远STAR25号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000337697.html">平安道远STAR5号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000144734.html">民生通惠优选1号保险资产管理产品 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000411170.html">平安道远STAR30号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/1705111733104153.html">平安道远投资管理(上海)有限公司安享1号私募投资基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000337698.html">平安道远STAR6号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000337700.html">平安道远STAR7号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000767714.html">平安道远投资管理(上海)有限公司稳盈2号私募投资基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000398054.html">平安道远STAR11号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露8条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000227027.html">平安道远金锁1号资产管理计划 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露0条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露0条;</p>
<p><a href="../fund/351000398063.html">平安道远STAR12号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
<p><a href="../fund/351000398127.html">平安道远STAR22号私募基金 </a></p>
<p><span class="fontweightB">月报:</span>应披露0条;<span class="fontweightB">季报:</span>应披露3条;<span class="fontweightB">半年报:</span>应披露0条;<span class="fontweightB">年报:</span>应披露1条;</p>
</td>
</tr>
<tr>
<td colspan="4" style="padding: 0px 0px;text-align: left;">
<div style="background-color: #DFDFDF;padding: 8px 10px;font-weight:bold;">诚信信息</div>
</td>
</tr>
<tr>
<td class="td-title">机构信息最后更新时间:</td>
<td class="td-content" colspan="3">2017-04-28</td>
</tr>
<tr>
<td class="td-title">特别提示信息:</td>
<td class="td-content" colspan="3" id="specialInfos">
<!-- 法律意见书 -->
<!-- 法律意见书 -->
</td>
</tr>
</tbody>
</table>

In [167]:
soup.find_all('a')


Out[167]:
[<a class="logo pull-left" href="/">\n<img alt="\u4e2d\u56fd\u57fa\u91d1\u4e1a\u534f\u4f1a\u4fe1\u606f\u516c\u793a" class="img-desktop" src="../../common/images/logo.png"/>\n<img alt="\u4e2d\u56fd\u57fa\u91d1\u4e1a\u534f\u4f1a\u4fe1\u606f\u516c\u793a" class="img-responsive" src="../../common/images/logo_mobile.png"/>\n</a>,
 <a class="text-danger ml15" href="#" id="comfirmMsg" onclick="openAMACInfo();">&lt;\r\n                    &lt;\u4e2d\u56fd\u8bc1\u5238\u6295\u8d44\u57fa\u91d1\u4e1a\u534f\u4f1a\u63d0\u793a&gt;&gt;\r\n                </a>,
 <a class="a1" href="mailto:pf@amac.org.cn" style="color: #173bf4;">pf@amac.org.cn</a>,
 <a class="a1" href="mailto:pf@amac.org.cn" style="color: #173bf4;">pf@amac.org.cn</a>,
 <a href="javascript:void(0);" onclick="javascript:gotoWebsite('http://russell.pingan.com/index.shtml');">http://russell.pingan.com/index.shtml</a>,
 <a href="../fund/351000131340.html">\u5e73\u5b89\u8d44\u4ea7MOM1\u53f7\u8d44\u4ea7\u7ba1\u7406\u4ea7\u54c1</a>,
 <a href="../fund/351000128351.html">\u7f57\u7d20\u6295\u8d44\u5408\u683c\u6295\u8d44\u8005\u4e2d\u56fd\u57fa\u91d1</a>,
 <a href="../fund/351000128367.html">\u5e73\u5b89\u4eba\u5bff\u7edd\u5bf9\u6536\u76ca\u8d26\u6237</a>,
 <a href="../fund/351000128350.html">\u4ea4\u94f6\u56fd\u4fe1 \u5e73\u5b89\u7f57\u7d20MOM\u4e00\u671f\u591a\u5143\u6295\u8d44\u96c6\u5408\u8d44\u91d1\u4fe1\u6258\u8ba1\u5212</a>,
 <a href="../fund/351000144727.html">\u5e73\u5b89\u8d44\u4ea7MOM2\u53f7\u4fdd\u9669\u8d44\u4ea7\u7ba1\u7406\u4ea7\u54c1</a>,
 <a href="../fund/351000144730.html">\u5e73\u5b89\u8d44\u4ea7MOM3\u53f7\u4fdd\u9669\u8d44\u4ea7\u7ba1\u7406\u4ea7\u54c1</a>,
 <a href="../fund/1705030955106523.html">\u5e73\u5b89\u9053\u8fdcSTAR21\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000411156.html">\u5e73\u5b89\u9053\u8fdcSTAR27\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000398101.html">\u5e73\u5b89\u9053\u8fdcSTAR19\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000337686.html">\u5e73\u5b89\u9053\u8fdcSTAR2\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000411159.html">\u5e73\u5b89\u9053\u8fdcSTAR28\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000337690.html">\u5e73\u5b89\u9053\u8fdcSTAR3\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000398107.html">\u5e73\u5b89\u9053\u8fdcSTAR20\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000337693.html">\u5e73\u5b89\u9053\u8fdcSTAR4\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000398044.html">\u5e73\u5b89\u9053\u8fdcSTAR10\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000411165.html">\u5e73\u5b89\u9053\u8fdcSTAR29\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000747226.html">\u5e73\u5b89\u9053\u8fdc\u6295\u8d44\u7ba1\u7406\uff08\u4e0a\u6d77\uff09\u6709\u9650\u516c\u53f8\u7a33\u76c81\u53f7\u79c1\u52df\u6295\u8d44\u57fa\u91d1 </a>,
 <a href="../fund/351000221216.html">\u5e73\u5b89\u517b\u8001-\u5e73\u5b89\u7f57\u7d20\u9053\u8fdc1\u53f7\u8d44\u4ea7\u7ba1\u7406\u4ea7\u54c1 </a>,
 <a href="../fund/351000398083.html">\u5e73\u5b89\u9053\u8fdcSTAR17\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000398027.html">\u5e73\u5b89\u9053\u8fdcSTAR8\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000411149.html">\u5e73\u5b89\u9053\u8fdcSTAR26\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000398095.html">\u5e73\u5b89\u9053\u8fdcSTAR18\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000337328.html">\u5e73\u5b89\u9053\u8fdcSTAR1\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000398070.html">\u5e73\u5b89\u9053\u8fdcSTAR15\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000264901.html">\u5e73\u5b89\u9053\u8fdc\u91d1\u95012\u53f7\u57fa\u91d1 </a>,
 <a href="../fund/351000398079.html">\u5e73\u5b89\u9053\u8fdcSTAR16\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000398143.html">\u5e73\u5b89\u9053\u8fdcSTAR25\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000337697.html">\u5e73\u5b89\u9053\u8fdcSTAR5\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000144734.html">\u6c11\u751f\u901a\u60e0\u4f18\u90091\u53f7\u4fdd\u9669\u8d44\u4ea7\u7ba1\u7406\u4ea7\u54c1 </a>,
 <a href="../fund/351000411170.html">\u5e73\u5b89\u9053\u8fdcSTAR30\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/1705111733104153.html">\u5e73\u5b89\u9053\u8fdc\u6295\u8d44\u7ba1\u7406\uff08\u4e0a\u6d77\uff09\u6709\u9650\u516c\u53f8\u5b89\u4eab1\u53f7\u79c1\u52df\u6295\u8d44\u57fa\u91d1 </a>,
 <a href="../fund/351000337698.html">\u5e73\u5b89\u9053\u8fdcSTAR6\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000337700.html">\u5e73\u5b89\u9053\u8fdcSTAR7\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000767714.html">\u5e73\u5b89\u9053\u8fdc\u6295\u8d44\u7ba1\u7406\uff08\u4e0a\u6d77\uff09\u6709\u9650\u516c\u53f8\u7a33\u76c82\u53f7\u79c1\u52df\u6295\u8d44\u57fa\u91d1 </a>,
 <a href="../fund/351000398054.html">\u5e73\u5b89\u9053\u8fdcSTAR11\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000227027.html">\u5e73\u5b89\u9053\u8fdc\u91d1\u95011\u53f7\u8d44\u4ea7\u7ba1\u7406\u8ba1\u5212 </a>,
 <a href="../fund/351000398063.html">\u5e73\u5b89\u9053\u8fdcSTAR12\u53f7\u79c1\u52df\u57fa\u91d1 </a>,
 <a href="../fund/351000398127.html">\u5e73\u5b89\u9053\u8fdcSTAR22\u53f7\u79c1\u52df\u57fa\u91d1 </a>]

In [174]:
soup.find_all('a', class_=re.compile(ur'bgwhite\st-[\u4e00-\u9fff]+'))


Out[174]:
[]

In [228]:
u'量化'


Out[228]:
u'\u91cf\u5316'

In [193]:
u'对冲'.decode('gb2312')


---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-193-85351923c68c> in <module>()
----> 1 u'对冲'.decode('gb2312')

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

In [277]:
import requests
from bs4 import BeautifulSoup

suffix = '101000000138.html'
target = [u'量化',u'对冲']

def is_true_quant(suffix):
    Flag = False
    surl = 'http://gs.amac.org.cn/amac-infodisc/res/pof/manager/' + suffix

    # 使用requests获取网页
    r = requests.get( surl)
    soup = BeautifulSoup(r.content, 'html.parser')
    
    for item in soup.find_all('a', href=True):
        if item['href'].endswith('html'):
            base = soup('a',{'href':item['href']})[0].contents[0] # 返回 href后面对应的文字
            print base  
            if  target[0] in base or target[1] in base:
                Flag = True
                break
    return Flag

In [278]:
is_true_quant(suffix)


平安资产MOM1号资产管理产品
罗素投资合格投资者中国基金
平安人寿绝对收益账户
交银国信 平安罗素MOM一期多元投资集合资金信托计划
平安资产MOM2号保险资产管理产品
平安资产MOM3号保险资产管理产品
平安道远STAR21号私募基金 
平安道远STAR27号私募基金 
平安道远STAR19号私募基金 
平安道远STAR2号私募基金 
平安道远STAR28号私募基金 
平安道远STAR3号私募基金 
平安道远STAR20号私募基金 
平安道远STAR4号私募基金 
平安道远STAR10号私募基金 
平安道远STAR29号私募基金 
平安道远投资管理(上海)有限公司稳盈1号私募投资基金 
平安养老-平安罗素道远1号资产管理产品 
平安道远STAR17号私募基金 
平安道远STAR8号私募基金 
平安道远STAR26号私募基金 
平安道远STAR18号私募基金 
平安道远STAR1号私募基金 
平安道远STAR15号私募基金 
平安道远金锁2号基金 
平安道远STAR16号私募基金 
平安道远STAR25号私募基金 
平安道远STAR5号私募基金 
民生通惠优选1号保险资产管理产品 
平安道远STAR30号私募基金 
平安道远投资管理(上海)有限公司安享1号私募投资基金 
平安道远STAR6号私募基金 
平安道远STAR7号私募基金 
平安道远投资管理(上海)有限公司稳盈2号私募投资基金 
平安道远STAR11号私募基金 
平安道远金锁1号资产管理计划 
平安道远STAR12号私募基金 
平安道远STAR22号私募基金 
Out[278]:
False

In [281]:
#soup('a',{'href':})[0].contents[0]

In [ ]:


In [282]:
fund_path = 'C:/Users/LZJF_02/Desktop/myjob/web_crawling/fundlist'
filename0 = 'zizhu1-10.csv'
filename1 = 'guwen1-10.csv'

In [337]:
data1 = pd.read_csv(fund_path+'/'+filename0,encoding ='gbk')

In [341]:
data1['type'] = u'自主'
data1['size']

In [342]:
data1.fundScale


Out[342]:
0       9.309265e+05
1       3.418153e+05
2       7.501422e+04
3       6.705248e+05
4       9.839621e+05
5       5.485847e+05
6       8.902925e+04
7       1.089406e+05
8       3.135787e+05
9       2.021778e+04
10      1.600695e+05
11      1.244000e+04
12      4.315295e+04
13      7.704000e+05
14      9.407056e+04
15      1.247753e+06
16      9.224500e+04
17      1.619245e+05
18      9.789640e+04
19      1.650072e+04
20      3.279377e+05
21      1.111600e+05
22      3.677000e+04
23      9.428028e+04
24      8.609573e+04
25      5.747272e+05
26      3.516764e+04
27      4.683099e+04
28      1.246248e+05
29      1.156022e+05
            ...     
1190    1.996811e+04
1191    5.888500e+04
1192    1.471550e+04
1193    2.870986e+05
1194    1.325998e+04
1195    2.740000e+04
1196    3.820738e+04
1197    3.401300e+04
1198    3.020000e+04
1199    2.000050e+04
1200    1.719913e+04
1201    1.100000e+04
1202    7.480869e+04
1203    1.836200e+04
1204    1.200027e+04
1205    1.153000e+04
1206    1.905600e+04
1207    1.740746e+04
1208    1.465000e+04
1209    1.261800e+04
1210    1.912123e+04
1211    1.192374e+04
1212    1.033000e+04
1213    1.178000e+04
1214    1.042800e+04
1215    1.357800e+04
1216    1.500000e+04
1217    1.510000e+04
1218    1.484900e+04
1219    2.000000e+04
Name: fundScale, dtype: float64

In [344]:



Out[344]:
930926.5

In [331]:
city = u'上海'

In [332]:
data1['city'] =  data1['managerName'].apply(lambda x : 1 if city in x else 0 )

In [333]:
data1[(data1['city'] ==1) & (data1[u'含量化或对冲'] ==True )]


Out[333]:
id managerName fundScale 含量化或对冲 city type
0 101000000172 富舜资产管理(上海)有限公司 9.309265e+05 True 1 自主
2 101000000578 上海尚雅投资管理有限公司 7.501422e+04 True 1 自主
5 101000000196 上海国富投资管理有限公司 5.485847e+05 True 1 自主
6 101000000458 上海万丰友方投资管理有限公司 8.902925e+04 True 1 自主
14 101000000374 上海涌峰投资管理有限公司 9.407056e+04 True 1 自主
31 101000001316 浙商控股集团上海资产管理有限公司 2.754900e+04 True 1 自主
34 101000000694 上海游马地投资中心(有限合伙) 4.192697e+04 True 1 自主
39 101000001661 上海鼎锋资产管理有限公司 1.778855e+05 True 1 自主
44 101000000491 上海理石投资管理有限公司 2.301286e+05 True 1 自主
45 101000001221 上海恒如投资管理有限公司 6.176445e+04 True 1 自主
47 101000002228 上海仁和智本资产管理有限公司 8.046300e+04 True 1 自主
49 101000000534 上海睿信投资管理有限公司 1.142423e+05 True 1 自主
54 101000000934 上海弈泰资产管理有限公司 1.474782e+04 True 1 自主
71 101000000229 上海通晟资产管理有限公司 8.136947e+04 True 1 自主
72 101000000500 上海无花果资产管理中心(普通合伙) 1.669681e+04 True 1 自主
81 101000002351 上海玖歌投资管理有限公司 3.814694e+05 True 1 自主
83 101000002708 上海毅扬投资管理有限公司 8.954819e+04 True 1 自主
84 101000003353 上海天迪资产管理有限公司 8.088482e+04 True 1 自主
89 101000001632 上海元葵资产管理中心(有限合伙) 5.547037e+04 True 1 自主
105 101000001084 上海明湾资产管理有限公司 2.461179e+04 True 1 自主
106 101000001726 上海珺容投资管理有限公司 9.309078e+04 True 1 自主
109 101000001974 德骏达隆(上海)资产管理有限公司 1.383652e+04 True 1 自主
115 101000000375 上海银叶投资有限公司 1.038920e+06 True 1 自主
117 101000002967 上海喜世润投资管理有限公司 4.107349e+04 True 1 自主
128 101000002204 上海知几投资发展中心(有限合伙) 1.931802e+04 True 1 自主
161 101000001702 上海远策投资管理中心(有限合伙) 6.716260e+05 True 1 自主
162 101000002244 上海河东资产管理咨询有限公司 3.060343e+04 True 1 自主
179 101000001003 上海国时资产管理有限公司 2.704305e+04 True 1 自主
182 101000003885 上海天倚道投资管理有限公司 2.873217e+04 True 1 自主
187 101000004064 上海和君股权投资管理合伙企业(有限合伙) 5.502301e+04 True 1 自主
... ... ... ... ... ... ...
801 101000023324 上海量金资产管理有限公司 7.369595e+04 True 1 自主
805 101000021686 上海璞琢资产管理有限公司 1.341200e+04 True 1 自主
832 101000023458 上海砥俊资产管理中心(有限合伙) 2.422734e+04 True 1 自主
838 101000019197 上海洛书投资管理有限公司 3.950401e+04 True 1 自主
856 101000025638 上海珺容资产管理有限公司 1.287097e+05 True 1 自主
857 101000019574 上海融启投资管理有限公司 4.746424e+04 True 1 自主
858 101000023239 上海汇贝投资管理有限公司 1.262950e+04 True 1 自主
871 101000025565 上海永柏联投投资管理有限公司 8.764566e+04 True 1 自主
887 101000017063 上海道亨资产管理有限公司 3.451567e+04 True 1 自主
905 101000027980 上海小鳄资产管理有限公司 3.308000e+04 True 1 自主
949 101000030443 上海千波资产管理有限公司 2.074652e+04 True 1 自主
970 101000030365 上海邦孚资产管理有限公司 2.280638e+04 True 1 自主
974 101000032177 上海盈衡资产管理有限公司 1.882030e+04 True 1 自主
983 101000033374 和瑾(上海)资产管理有限公司 9.219357e+04 True 1 自主
988 101000030655 上海招焱投资管理有限公司 3.744824e+04 True 1 自主
991 101000032835 上海迎水投资管理有限公司 1.306746e+04 True 1 自主
1059 101000037020 上海钜澎资产管理有限公司 3.840371e+05 True 1 自主
1061 101000038007 上海步耘投资管理有限公司 3.250000e+04 True 1 自主
1099 101000023875 上海涌乐股权投资基金管理有限公司 1.114872e+04 True 1 自主
1103 101000039741 贝莱德海外投资基金管理(上海)有限公司 7.717569e+04 True 1 自主
1119 101000030090 上海稳博投资管理有限公司 1.197616e+04 True 1 自主
1132 101000044810 石担(上海)资产管理有限公司 1.077336e+04 True 1 自主
1135 101000044746 锐汇(上海)资产管理有限公司 1.552799e+04 True 1 自主
1149 101000043338 上海联创永泉资产管理有限公司 3.423920e+04 True 1 自主
1155 101000045294 上海弘润资产管理有限责任公司 9.536936e+04 True 1 自主
1162 101000043772 上海久期量和投资有限公司 5.856086e+04 True 1 自主
1168 101000051261 上海岳海资产管理有限公司 1.099564e+04 True 1 自主
1187 101000063062 上海橘颂资产管理有限公司 1.378692e+04 True 1 自主
1196 101000050644 上海思勰投资管理有限公司 3.820738e+04 True 1 自主
1217 1612231709102433 上海崇正投资管理合伙企业(有限合伙) 1.510000e+04 True 1 自主

119 rows × 6 columns


In [ ]:
data

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [19]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: