R在银行财务数据分析中的应用.

原文地址:http://supstat.com.cn/blog/2015/01/07/use-r-in-banking-industry/

研究方法

搜集银行业上市公司的财务数据分析股票价格的财务影响因素,观测流动比率、净资产负债比率、资产固定资产比率、每股收益、净利润、增长率、股价和公布时间等数据。首先描述性分析对银行业上市公司的财务数据进行基础性描述,以便对整个行业形成直观的印象,然后利用因子分析提取对银行业上市公司股价影响较为明显的因素,分析银行业上市公司股价的决定因素,最后利用回归分析方法确定这些因素对股票价格的影响方向和强弱。

统计方法

  • 描述性分析
  • 因子分析
  • 回归分析

具体分析

本案例为了研究的准确性和普遍性,一共搜集了23家上市的金融银行类股票一定是可的股票价格。同时为了准确反映上市公司财务报表呈现的财务信息与股票价格的关系,我们搜集了流动比率、净资产负债比率、资产固定资产比率、每股收益、净利润、增长率等财务指标。可以点击
这里 下载数据。

    dataf <- read.csv("bank.csv") # 导入数据
    dataf
    ##    流动比率 净资产负债比率 资产固定资产比率 每股收益 净利润 增长率  股价
    ## 1    1.0716       0.020515            27.04   0.1925  17.77 -3.942 18.56
    ## 2    1.0181       0.009379           113.22   0.1300  14.77 46.914 18.86
    ## 3    1.0469       0.013588            85.34   0.2230  14.30 25.433 13.65
    ## 4    1.0398       0.013137            93.34   0.2752  14.72 30.732 15.21
    ## 5    1.0216       0.013970            88.40   0.1197  14.10 30.578 13.73
    ## 6    0.9607       0.013284            93.59   0.1850  16.60 14.550 12.43
    ## 7    0.9256       0.011708           102.88   0.2365  14.98 13.879 13.89
    ## 8    0.9424       0.011860           103.24   0.3040  13.52 21.894 11.10
    ## 9    0.9164       0.011641           103.53   0.0915  14.45 27.488 11.42
    ## 10   0.8754       0.010129           112.47   0.1720  13.29 19.168 12.14
    ## 11   0.9008       0.009532           127.28   0.2605  12.81 21.915 10.43
    ## 12   0.8814       0.009450           133.40   0.3240  11.51 23.687  8.56
    ## 13   0.8907       0.008080           128.08   0.1116  12.96 44.718 10.24
    ## 14   0.8629       0.009338           236.14   0.1902  11.82 37.542  9.02
    ## 15   0.8634       0.009430           117.57   0.2846  11.62 35.189  7.55
    ## 16   0.8494       0.010992           107.08   0.3470  10.31 21.157  6.65
    ## 17   0.8637       0.010824           105.04   0.1119  12.08 14.875  6.49
    ## 18   0.8577       0.011688           110.31   0.1849  10.91 10.622  6.14
    ## 19   0.8743       0.009964            98.12   0.3066  11.58 22.350  6.12
    ## 20   0.8848       0.010763           116.04   0.3744  10.42 26.894  5.67
    ## 21   0.8962       0.009194            97.98   0.1158  11.39 28.249  6.98
    ## 22   0.7740       0.009581           105.11   0.2456  11.51 64.610  6.68
    ## 23       NA       0.006989           156.92   0.3900  11.79 52.344  6.39
    summary(dataf)
    ##     流动比率     净资产负债比率    资产固定资产比率    每股收益     
    ##  Min.   :0.774   Min.   :0.00699   Min.   : 27      Min.   :0.0915  
    ##  1st Qu.:0.866   1st Qu.:0.00944   1st Qu.: 98      1st Qu.:0.1510  
    ##  Median :0.893   Median :0.01076   Median :105      Median :0.2230  
    ##  Mean   :0.919   Mean   :0.01109   Mean   :111      Mean   :0.2251  
    ##  3rd Qu.:0.956   3rd Qu.:0.01178   3rd Qu.:117      3rd Qu.:0.2943  
    ##  Max.   :1.072   Max.   :0.02051   Max.   :236      Max.   :0.3900  
    ##  NA's   :1                                                          
    ##      净利润         增长率           股价      
    ##  Min.   :10.3   Min.   :-3.94   Min.   : 5.67  
    ##  1st Qu.:11.5   1st Qu.:20.16   1st Qu.: 6.66  
    ##  Median :12.8   Median :25.43   Median :10.24  
    ##  Mean   :13.0   Mean   :27.43   Mean   :10.34  
    ##  3rd Qu.:14.4   3rd Qu.:32.96   3rd Qu.:13.04  
    ##  Max.   :17.8   Max.   :64.61   Max.   :18.86  
    ## 
样本描述

由R语言自带的summary我们能知道数据的最小值、25%分位数、中位数、均值、75%分位数、最大值以及缺失值数目。但是我们知道,仅仅通过这7个统计值我们不能很好的了解到数据的概貌,因此本章通过利用R语言的其他函数,制作一个样本描述表。

    d1 = c(dataf[, 1])
    d2 = c(dataf[, 2])
    d3 = c(dataf[, 3])
    d4 = c(dataf[, 4])
    d5 = c(dataf[, 5])
    d6 = c(dataf[, 6])
    d7 = c(dataf[, 7])
    #包括7个项目,分别为最小值,25%分位数,中位数,均值,75%分位数,最大值以及缺失值数目
    sum1 = summary(d1)
    sum2 = summary(d2)
    sum3 = summary(d3)
    sum4 = summary(d4)
    sum5 = summary(d5)
    sum6 = summary(d6)
    sum7 = summary(d7)
    #样本数
    N1 = length(d1)-sum1[7]
    N2 = length(d2)
    N3 = length(d3)
    N4 = length(d4)
    N5 = length(d5)
    N6 = length(d6)
    N7 = length(d7)
    
    head = c("变量名","流动比率","净资产负债比率","资产固定资产比率","每股收益","净利润","增长率","股价")
    row1 = c("样本数",N1,N2,N3,N4,N5,N6,N7)
    row2 = c("全距",sum1[6]-sum1[1],sum2[6]-sum2[1],sum3[6]-sum3[1],sum4[6]-sum4[1],sum5[6]-sum5[1],sum6[6]-sum6[1],sum7[6]-sum7[1])
    row3 = c("最小值",sum1[1],sum2[1],sum3[1],sum4[1],sum5[1],sum6[1],sum7[1])
    row4 = c("最大值",sum1[6],sum2[6],sum3[6],sum4[6],sum5[6],sum6[6],sum7[6])
    row5 = c("均值",sum1[4],sum2[4],sum3[4],sum4[4],sum5[4],sum6[4],sum7[4])
    row6 = c("中位数",sum1[3],sum2[3],sum3[3],sum4[3],sum5[3],sum6[3],sum7[3])
    row7 = c("标准差",sd(d1,na.rm=T),sd(d2),sd(d3),sd(d4),sd(d5),sd(d6),sd(d7))
    
    result = matrix(c(head, row1, row2, row3, row4, row5, row6, row7),ncol=8,byrow = T)
    print(t(result))
    ##      [,1]               [,2]     [,3]      [,4]      [,5]     [,6]    
    ## [1,] "变量名"           "样本数" "全距"    "最小值"  "最大值" "均值"  
    ## [2,] "流动比率"         "22"     "0.296"   "0.774"   "1.07"   "0.919" 
    ## [3,] "净资产负债比率"   "23"     "0.01351" "0.00699" "0.0205" "0.0111"
    ## [4,] "资产固定资产比率" "23"     "209"     "27"      "236"    "111"   
    ## [5,] "每股收益"         "23"     "0.2985"  "0.0915"  "0.39"   "0.225" 
    ## [6,] "净利润"           "23"     "7.5"     "10.3"    "17.8"   "13"    
    ## [7,] "增长率"           "23"     "68.54"   "-3.94"   "64.6"   "27.4"  
    ## [8,] "股价"             "23"     "13.23"   "5.67"    "18.9"   "10.3"  
    ##      [,7]     [,8]                 
    ## [1,] "中位数" "标准差"             
    ## [2,] "0.893"  "0.0768336436285581" 
    ## [3,] "0.0108" "0.00271362995517017"
    ## [4,] "105"    "35.8888061503178"   
    ## [5,] "0.223"  "0.0901580500060493" 
    ## [6,] "12.8"   "1.9540104480683"    
    ## [7,] "25.4"   "14.8509587755514"   
    ## [8,] "10.2"   "3.97134479070255"

由上表可知,在从2001到2008年各个季度中,我国银行业上市公司的平均值为10.3439,最大值与最小值之间的全距为13.19元,标准差为3.97元,可见我国银行业上市公司的股价在样本期间波动幅度较大。另外,就净利润指标看,我国银行业公司净利润均值为13亿元,可见在样本期间我国银行业经营状况良好。

因子分析

由于因子分析对缺失值非常的敏感,在进行因子分析之前我们先对数据进行缺失值的检查。

    is.na(dataf)
    ##       流动比率 净资产负债比率 资产固定资产比率 每股收益 净利润 增长率
    ##  [1,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ##  [2,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ##  [3,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ##  [4,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ##  [5,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ##  [6,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ##  [7,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ##  [8,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ##  [9,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [10,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [11,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [12,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [13,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [14,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [15,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [16,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [17,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [18,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [19,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [20,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [21,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [22,]    FALSE          FALSE            FALSE    FALSE  FALSE  FALSE
    ## [23,]     TRUE          FALSE            FALSE    FALSE  FALSE  FALSE
    ##        股价
    ##  [1,] FALSE
    ##  [2,] FALSE
    ##  [3,] FALSE
    ##  [4,] FALSE
    ##  [5,] FALSE
    ##  [6,] FALSE
    ##  [7,] FALSE
    ##  [8,] FALSE
    ##  [9,] FALSE
    ## [10,] FALSE
    ## [11,] FALSE
    ## [12,] FALSE
    ## [13,] FALSE
    ## [14,] FALSE
    ## [15,] FALSE
    ## [16,] FALSE
    ## [17,] FALSE
    ## [18,] FALSE
    ## [19,] FALSE
    ## [20,] FALSE
    ## [21,] FALSE
    ## [22,] FALSE
    ## [23,] FALSE

这时我们发现流动比率变量第23个数据缺失,因此在进行因子分析的时候,我们对缺失值进行整行删除处理,即在因子分析时排除第23行整行的7个数据。

然后,我们对剩余的流动比率、净资产负债比率、资产固定资产比率、每股收益、净利润和增长率这些公司财务变量进行KMO检验,检验选取的财务变量是否适合进行因子分析。

    library(psych)         # 导入psych程序包
    KMO(dataf[-23,-7])     # 排除股价变量和第23行数据
    ## Kaiser-Meyer-Olkin factor adequacy
    ## Call: KMO(r = dataf[-23, -7])
    ## Overall MSA =  0.75
    ## MSA for each item = 
    ##         流动比率   净资产负债比率 资产固定资产比率         每股收益 
    ##             0.79             0.74             0.87             0.47 
    ##           净利润           增长率 
    ##             0.73             0.74

KMO检验值为0.75,这说明这些财务变量适合做因子分析。

    fa.parallel(dataf[-23,-7])   # 绘制碎石图寻找合适因子个数

plot of chunk factor2

    ## Parallel analysis suggests that the number of factors =  2  and the number of components =  1

由碎石图看出,对于因子分析,合适的因子个数为2。因此我们利用psych程序包中的fa函数对所选取的变量做因子分析,利用极大似然法(ml)提取公因子,运用最大方差旋转法(varimax),找出其中2个因子。

    fa(dataf[-23,-7], nfactors=2, fm="ml", rotate="varimax",score=T)
    ## Loading required package: GPArotation
    ## Factor Analysis using method =  ml
    ## Call: fa(r = dataf[-23, -7], nfactors = 2, rotate = "varimax", scores = T, 
    ##     fm = "ml")
    ## Standardized loadings (pattern matrix) based upon correlation matrix
    ##                    ML1   ML2   h2    u2 com
    ## 流动比率          0.60  0.56 0.67 0.331 2.0
    ## 净资产负债比率    0.98  0.21 1.00 0.005 1.1
    ## 资产固定资产比率 -0.65 -0.17 0.45 0.547 1.1
    ## 每股收益          0.05 -0.48 0.23 0.772 1.0
    ## 净利润            0.53  0.84 1.00 0.005 1.7
    ## 增长率           -0.63  0.02 0.39 0.609 1.0
    ## 
    ##                        ML1  ML2
    ## SS loadings           2.41 1.32
    ## Proportion Var        0.40 0.22
    ## Cumulative Var        0.40 0.62
    ## Proportion Explained  0.65 0.35
    ## Cumulative Proportion 0.65 1.00
    ## 
    ## Mean item complexity =  1.3
    ## Test of the hypothesis that 2 factors are sufficient.
    ## 
    ## The degrees of freedom for the null model are  15  and the objective function was  3.13 with Chi Square of  56.79
    ## The degrees of freedom for the model are 4  and the objective function was  0.02 
    ## 
    ## The root mean square of the residuals (RMSR) is  0.02 
    ## The df corrected root mean square of the residuals is  0.04 
    ## 
    ## The harmonic number of observations is  22 with the empirical chi square  0.22  with prob <  0.99 
    ## The total number of observations was  22  with MLE Chi Square =  0.38  with prob <  0.98 
    ## 
    ## Tucker Lewis Index of factoring reliability =  1.361
    ## RMSEA index =  0  and the 90 % confidence intervals are  NA NA
    ## BIC =  -11.98
    ## Fit based upon off diagonal values = 1
    ## Measures of factor score adequacy             
    ##                                                 ML1  ML2
    ## Correlation of scores with factors             1.00 0.99
    ## Multiple R square of scores with factors       0.99 0.99
    ## Minimum correlation of possible factor scores  0.99 0.98

结果说明:

  1. 从表格可知,两个因子的累计贡献方差(Cumulative Var)为62%,说明得到的两个因子能解释所有变量62%的信息。
  2. 各变量与两个因子的关系如下:
  • 流动比率 = 0.60 × 因子A + 0.56 × 因子B
  • 净资产负债比率 = 0.98 × 因子A + 0.21 × 因子B
  • 资产固定资产比率 = -0.65 × 因子A - 0.17 × 因子B
  • 每股收益 = 0.05 × 因子A - 0.48 × 因子B
  • 净利润 = 0.53 × 因子A + 0.84 × 因子B
  • 增长率 = -0.63 × 因子A - 0.02 × 因子B

因子A主要影响流动比率、净资产负债比率、资产固定资产比率和增长率。其中因子A对流动比率和净资产负债比率有正向影响而对资产固定资产比率和增长率有负向影响。我们将它称为
资产因子 。

因子B主要影响每股收益、净利润。其中因子B对净利润有正向作用而对每股收益则为负向作用。我们将它称为 收益因子 。

回归分析

现在利用所选取的财务变量,通过回归分析进一步发掘我国银行业股价与其主要财务指标的关系。

    lm <- lm(股价~., data=dataf)
    lm.aic <- step(lm, trace=FALSE)    # AIC准则
    lm.bic <- step(lm, k=log(length(dataf[,1])), trace=FALSE)  # BIC准则
    summary(lm.aic)
    ## 
    ## Call:
    ## lm(formula = 股价 ~ 流动比率 + 净利润 + 增长率, data = dataf)
    ## 
    ## Residuals:
    ##    Min     1Q Median     3Q    Max 
    ## -2.670 -0.890 -0.365  0.808  2.953 
    ## 
    ## Coefficients:
    ##             Estimate Std. Error t value Pr(>|t|)    
    ## (Intercept) -27.4868     4.4273   -6.21  7.4e-06 ***
    ## 流动比率     22.8340     6.7784    3.37  0.00342 ** 
    ## 净利润        1.1980     0.2636    4.54  0.00025 ***
    ## 增长率        0.0522     0.0238    2.19  0.04187 *  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## Residual standard error: 1.46 on 18 degrees of freedom
    ##   (1 observation deleted due to missingness)
    ## Multiple R-squared:  0.884,	Adjusted R-squared:  0.865 
    ## F-statistic: 45.8 on 3 and 18 DF,  p-value: 1.26e-08

    summary(lm.bic)

    ## 
    ## Call:
    ## lm(formula = 股价 ~ 流动比率 + 净利润 + 增长率, data = dataf)
    ## 
    ## Residuals:
    ##    Min     1Q Median     3Q    Max 
    ## -2.670 -0.890 -0.365  0.808  2.953 
    ## 
    ## Coefficients:
    ##             Estimate Std. Error t value Pr(>|t|)    
    ## (Intercept) -27.4868     4.4273   -6.21  7.4e-06 ***
    ## 流动比率     22.8340     6.7784    3.37  0.00342 ** 
    ## 净利润        1.1980     0.2636    4.54  0.00025 ***
    ## 增长率        0.0522     0.0238    2.19  0.04187 *  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## Residual standard error: 1.46 on 18 degrees of freedom
    ##   (1 observation deleted due to missingness)
    ## Multiple R-squared:  0.884,	Adjusted R-squared:  0.865 
    ## F-statistic: 45.8 on 3 and 18 DF,  p-value: 1.26e-08

通过AIC和BIC准则的检验,我们能得到所选取的财务变量中,流动比率、净利润和增长率对股价有显著的影响。为了保证线性模型的准确率,我们还需要考察该模型中是否存在自相关关系。以下通过lmtest程序包中的dwtest函数,对模型进行Durbin-
Watson检验。

    #install.packages("lmtest")
    #install.packages("zoo")
    library(lmtest)   # 导入程序包lmtest
    dwtest(lm.aic)

    ## 
    ## 	Durbin-Watson test
    ## 
    ## data:  lm.aic
    ## DW = 2.202, p-value = 0.5286
    ## alternative hypothesis: true autocorrelation is greater than 0

由检验得到,DW统计量为2,202,p值为0.5286,说明模型中不存在自相关关系。

则股价与流动比率、净利润和增长率的关系为: 股价 = -27.4868 + 22.8340 × 流动比率 + 1.1980 × 净利润 + 0.0522 ×
增长率

其中三个变量的系数均在0.01的显著性水平下显著。

研究结论

根据以上所做的分析,我们可以比较有把握地得出以下结论:

(1)通过银行业上市公司股价及财务指标的描述统计分析发现,一般而言,我国银行业上市公司的股价在样本期间波动幅度较大,但相对其他行业较小。另外,就净利润指标看,我国银行业上市公司净利润均值为13亿元,可见我国银行业经营状况良好。

(2)通过银行业上市的各个财务指标的因子分析发现: 在银行业数据中,可以用两个主因子(收益因子、资产因子)来代替解释所有六个财务指标提供的62%的信息。

(3)通过对银行业股票价格与财务指标的回归分析发现:
银行业股价高度受流动比率、净利润和增长率这三个指标影响。其中流动比率1个单位的增加会带动银行业上市公司股价21个单位的增长。

总结:

  • 银行业股票价格总体波动性相对较小,盈利水平较高
  • 银行业财务信息中主要的变量是流动性比率、净利润和增长率
  • 影响银行业股价的最主要因素是银行资产的流动性水平

在这里插入图片描述

posted @ 2021-07-06 18:17  老酱  阅读(271)  评论(0编辑  收藏  举报