# 【实例】R语言如何做银行财务数据分析？

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

#### 具体分析

(源数据在文件夹内)

`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```
`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
## ```
##### 样本描述

`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"```

##### 因子分析

`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

##        股价
##  [1,] FALSE
##  [2,] FALSE
##  [3,] FALSE```

`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])   # 绘制碎石图寻找合适因子个数`
`## Parallel analysis suggests that the number of factors =  2  and the number of components =  1`

`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

##### 回归分析

`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```

`#install.packages("lmtest")#install.packages("zoo")library(lmtest)   # 导入程序包lmtestdwtest(lm.aic)`
```##
## 	Durbin-Watson test
##
## data:  lm.aic
## DW = 2.202, p-value = 0.5286
## alternative hypothesis: true autocorrelation is greater than 0```

#### 研究结论

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

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

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

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

822 篇文章226 人订阅

0 条评论

## 相关文章

### 科学瞎想系列之七十九 永磁电机（2）

【图片部分来自网络如有侵权敬请邮箱联系。欢迎原文转发到朋友圈，未经许可的媒体平台谢绝转载，如需转载或合作请邮件联系。联系邮箱laolicsiem@126.com...

28020

33640

### 【史上最强世界杯预测】AI毒奶，EA封神！

【新智元导读】世界杯终于结束了。本届世界杯中，AI预测的夺冠热门德国、巴西、阿根廷等强队都被“毒奶”回家。而EA居然预测对了连续两届世界杯冠军，真的这么准？

8520

29970

56050

8600

18710

23180

31840

### 《基于机器学习的企业定价算法研究》阅读笔记

http://blog.csdn.net/u011239443/article/details/78126591 《基于机器学习的企业定价算法研究》 冯...

40640