├── .idea ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml ├── vcs.xml ├── workspace.xml └── 新浪财经数据.iml ├── README.md ├── demo.py ├── pictures ├── analysis.png ├── img ├── window1.png ├── window2.png └── 动态展示2.gif ├── pyqt ├── HTML │ ├── comment.css │ ├── comment.html │ ├── rate_index.css │ ├── rate_index.html │ ├── zfb_index.css │ ├── zfb_index.html │ └── 财报分析.html ├── __pycache__ │ ├── html_maker.cpython-36.pyc │ ├── indexData.cpython-36.pyc │ ├── main.cpython-36.pyc │ └── regionRp.cpython-36.pyc ├── cb.html ├── html_maker.py ├── img │ ├── close.png │ └── start.png ├── indexData.py ├── main.py ├── null ├── rate_index_副本.html ├── regionRp.py └── start.py ├── stockCode.txt ├── 数据处理入库.py ├── 新浪财经数据.py ├── 新浪财经数据_mg_n12.py ├── 新浪财经数据_mg_year.py ├── 新浪财经数据_mg_财务摘要.py ├── 说明.md ├── 财务摘要数据库处理.py └── 财报分析 ├── 原始报表 ├── __pycache__ │ └── 原始报表.cpython-36.pyc ├── 原始报表.py └── 重要财务指标.py ├── 原始财报处理.py └── 杜邦分析 ├── __pycache__ ├── impt_index.cpython-36.pyc ├── 原始报表.cpython-36.pyc └── 重要财务指标.cpython-36.pyc ├── impt_index.py ├── 原始报表.py ├── 杜邦分析.py └── 重要财务指标.py /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/新浪财经数据.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FinanceReportAnalysis 2 | 获取3775家上市公司近5年财务报表,建立财务报表分析模型,借助pyqt生成窗口化展示页面。 3 | ## 程序GUI效果: 4 | ![Alt text](pictures/window1.png) 5 | ![Alt text](pictures/window2.png) 6 | ![Alt text](pictures/analysis.png) 7 | ![Alt text](pictures/动态展示2.gif) 8 | -------------------------------------------------------------------------------- /demo.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | import numpy 5 | 6 | from fake_useragent import UserAgent 7 | 8 | li=[1,2,3] 9 | html_text=''' 10 | hasdhausdh{},dafjio{}akjdkja{}jakf 11 | '''.format(*li) 12 | 13 | print(html_text) -------------------------------------------------------------------------------- /pictures/analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pictures/analysis.png -------------------------------------------------------------------------------- /pictures/img: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /pictures/window1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pictures/window1.png -------------------------------------------------------------------------------- /pictures/window2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pictures/window2.png -------------------------------------------------------------------------------- /pictures/动态展示2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pictures/动态展示2.gif -------------------------------------------------------------------------------- /pyqt/HTML/comment.css: -------------------------------------------------------------------------------- 1 | td { border-top: 1px solid #dee2e6;box-sizing: border-box; border-color: rgba(239,242,246,0.8); padding: 0.3rem; display: table-cell;border-spacing: 2px;font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; font-size: 1.1375rem;line-height: 1.5;} 2 | 3 | th { background-color: lightblue; color: #868e96; border-top: 1px solid #dee2e6;box-sizing: border-box; border-color: rgba(239,242,246,0.8); padding: 0.3rem; display: table-cell;border-spacing: 2px;font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;font-size: 1.2375rem; 4 | font-weight: 400; 5 | line-height: 1.5;} 6 | 7 | .span_l{ font-size: 1.9rem;font-weight: bold;} 8 | 9 | .span_m{font-size: 1.5rem;font-weight: bold;} 10 | 11 | .span_s{ font-size: 1.2rem;font-weight: bold;} 12 | 13 | .best{ color: #87d068;font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;} 14 | 15 | .better{ color: #108ee9;font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;} 16 | 17 | .good{color: #00CCCC;} 18 | 19 | .normal{ color: #666666;} 20 | 21 | 22 | 23 | .worse{ color: #DE0C2D;font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;} -------------------------------------------------------------------------------- /pyqt/HTML/comment.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 25 | 26 | 27 | 28 | 29 | 32 | 60 | 61 | 62 | 63 | 64 | 67 | 96 | 97 | 98 | 99 | 100 | 103 | 117 | 118 | 119 | 120 | 121 | 122 | 128 | 129 | 130 | 131 |
6 | 现金流 7 | 9 |
10 | 11 | 现金超级多 12 | 13 | 14 | 15 | 现金流状况一般. 16 | 17 | 18 | 19 | 天天收现金! 20 | 21 | 22 | 23 |
24 |
30 | 盈利能力 31 | 33 |
34 | 35 | 36 | 毛利堪比卖白粉,毛利率91.6个点 37 | 38 | 39 | 40 | 市 41 | 42 | 43 | 44 | 45 | 即使税后也非常赚钱, 46 | 47 | 48 | 49 | 50 | 很牛逼的回报率. 51 | 52 | 53 | 54 | 每一股在去年为公司赚了31.35元钱 55 | 56 | 57 | 58 |
59 |
65 | 营运能力 66 | 68 |
69 | 70 | 重资产,周转很慢,风险高!还好现金超级多! 71 | 72 | 73 | 74 | 产品可能不好卖,特殊产业除外(酒类,地产等). 75 | 76 | 77 | 78 | 一轮生意要1257.2天.生意完整周期偏长.还好现金超级多! 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |
95 |
101 | 财务结构 102 | 104 | 105 |
106 | 107 | 108 | 基本没什么杆杠,看来股东非常看好公司, 109 | 110 | 111 | 112 | 长期资金源源不断! 113 | 114 | 115 |
116 |
偿债能力 123 | 124 | 短期外债偏高,公司目前有6成是现金资产. 125 | 126 | 127 |
-------------------------------------------------------------------------------- /pyqt/HTML/rate_index.css: -------------------------------------------------------------------------------- 1 | th { 2 | font-size: 1.4rem; 3 | text-align: inherit; 4 | font-weight: 500; 5 | margin: 0; 6 | width: auto; 7 | font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; 8 | background-color: lightblue; 9 | border-color: rgb(239, 242, 246); 10 | border-top-width: 1px; 11 | border-top-style:solid; 12 | white-space: nowrap; 13 | line-height: 1; 14 | vertical-align: middle; 15 | border: 0; 16 | color: #868e96; 17 | } 18 | .sheet-header__title { 19 | font-size: 1.9rem; 20 | 21 | 22 | } 23 | td { 24 | border-color: rgb(239, 242, 246); 25 | border-top-width: 1px; 26 | border-top-style:solid; 27 | 28 | font-size: 1.4rem; 29 | text-align: inherit; 30 | /*font-weight: 500;*/ 31 | margin: 0; 32 | width: auto; 33 | font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; 34 | 35 | white-space: nowrap; 36 | line-height: 1; 37 | vertical-align: middle; 38 | border: 0; 39 | color: #868e96; 40 | } 41 | h1 { 42 | color: white; 43 | text-align: center; 44 | } 45 | 46 | p { 47 | font-family: verdana; 48 | font-size: 20px; 49 | } -------------------------------------------------------------------------------- /pyqt/HTML/rate_index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |

五大财务比率(+成长能力)

5 |

  

6 |
7 |
8 |
9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 23 | 26 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 133 | 134 | 135 | 136 | 137 |
  类别财务比率趋势 18 | 2015 19 | 21 | 2016 22 | 24 | 2017 25 | 27 | 2018 28 | 30 | 近12个月 31 |
43 | 44 | 财务结构 45 | 46 | 负债占资产比率(%)23.2532.7928.6726.5527.56
长期资金占重资产比率(%)406.16441.39556.39682.49683.07
54 | 55 | 偿债能力 56 | 57 | 流动比率(%)324.18243.6290.99324.85313.72
速动比率(%)183.77180.8231.04265.54255.99
利息保障倍数
68 | 运营能力 69 | 应收款项周转率(次/年)6.268.2757.0982.49113.9
应收款项周转天数(天)58.2944.136.394.423.2
存货周转率(次/年)0.150.180.280.290.29
存货周转天数(天)2372.32067.681311.191274.811253.96
固定资产周转率(次/年)3.03.03.924.835.33
应付款项周转天数(天)114.21102.8462.4560.7267.86
总资产周转率(次/年)0.430.390.470.50.54
92 | 盈利能力 93 | ROA=资产收益率(%)21.6318.023.4425.6928.54
ROE=净资产收益率(%)28.1826.7832.8534.9839.4
毛利率(%)92.2391.2389.891.1491.58
营业利润率(%)67.8562.4466.8969.7271.32
净利率(%)50.3846.1449.8251.3752.81
营业费用率(%)18.916.8512.1610.449.96
经营安全边际率(%)73.5768.4574.4976.577.87
EPS=基本每股收益(元)12.3413.3121.5628.0231.35
119 | 成长能力 120 | 营收增长率(%)3.8220.0652.0726.4316.8
营业利润增长率(%)0.259.5160.4731.8524.12
净资本增长率(%)19.7514.5926.5122.2823.94
131 | 现金流量 132 | 现金流量比率(%)86.96101.1657.4397.52105.06
138 |
139 |
140 |
141 |
-------------------------------------------------------------------------------- /pyqt/HTML/zfb_index.css: -------------------------------------------------------------------------------- 1 | th { 2 | font-size: 1.4rem; 3 | text-align: inherit; 4 | font-weight: 500; 5 | margin: 0; 6 | width: auto; 7 | font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; 8 | background-color: lightblue; 9 | border-color: rgb(239, 242, 246); 10 | border-top-width: 1px; 11 | border-top-style:solid; 12 | white-space: nowrap; 13 | line-height: 1; 14 | vertical-align: middle; 15 | border: 0; 16 | color: #868e96; 17 | } 18 | .sheet-header__title { 19 | font-size: 1.9rem; 20 | 21 | 22 | } 23 | td { 24 | border-color: rgb(239, 242, 246); 25 | border-top-width: 1px; 26 | border-top-style:solid; 27 | 28 | font-size: 1.4rem; 29 | text-align: inherit; 30 | /*font-weight: 500;*/ 31 | margin: 0; 32 | width: auto; 33 | font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; 34 | 35 | white-space: nowrap; 36 | line-height: 1; 37 | vertical-align: middle; 38 | border: 0; 39 | color: #868e96; 40 | } 41 | h1 { 42 | color: white; 43 | text-align: center; 44 | } 45 | 46 | p { 47 | font-family: verdana; 48 | font-size: 20px; 49 | } -------------------------------------------------------------------------------- /pyqt/HTML/zfb_index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 |

资产负债比率(重要科目)

6 |
7 |
8 |
9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 32 | 37 | 41 | 45 | 49 | 53 | 57 | 58 | 59 | 60 | 65 | 69 | 73 | 77 | 81 | 85 | 86 | 87 | 88 | 93 | 97 | 101 | 105 | 109 | 113 | 114 | 115 | 116 | 117 | 122 | 126 | 130 | 134 | 138 | 142 | 143 | 144 | 145 | 150 | 154 | 158 | 162 | 166 | 170 | 171 | 172 | 173 | 174 | 179 | 183 | 187 | 191 | 195 | 199 | 200 | 201 | 202 | 207 | 211 | 215 | 219 | 223 | 227 | 228 | 229 | 230 | 231 | 232 | 239 | 244 | 248 | 252 | 256 | 260 | 264 | 265 | 266 | 267 | 272 | 276 | 280 | 284 | 288 | 292 | 293 | 294 | 295 | 300 | 304 | 308 | 312 | 316 | 320 | 321 | 322 | 323 | 328 | 333 | 337 | 341 | 345 | 349 | 353 | 354 | 355 | 356 | 357 | 358 |
类别比率(占总资产%)20152016201720182019-06
26 | 29 | 30 | 资产 31 | 33 | 34 | 现金与约当现金(%) 35 | 36 | 38 | 39 | 42.64 40 | 42 | 43 | 59.2 44 | 46 | 47 | 65.28 48 | 50 | 51 | 70.11 52 | 54 | 55 | 69.98 56 |
61 | 62 | 应收款项(%) 63 | 64 | 66 | 67 | 0.0 68 | 70 | 71 | 0.0 72 | 74 | 75 | 0.91 76 | 78 | 79 | 0.35 80 | 82 | 83 | 0.43 84 |
89 | 90 | 存货(%) 91 | 92 | 94 | 95 | 20.87 96 | 98 | 99 | 18.26 100 | 102 | 103 | 16.39 104 | 106 | 107 | 14.71 108 | 110 | 111 | 14.54 112 |
118 | 119 | 其他流动资产(%) 120 | 121 | 123 | 124 | 0.0 125 | 127 | 128 | 0.2 129 | 131 | 132 | 0.03 133 | 135 | 136 | 0.09 137 | 139 | 140 | 0.01 141 |
146 | 147 | 流动资产(%) 148 | 149 | 151 | 152 | 75.32 153 | 155 | 156 | 79.85 157 | 159 | 160 | 83.39 161 | 163 | 164 | 86.25 165 | 167 | 168 | 86.33 169 |
175 | 176 | 商誉(%) 177 | 178 | 180 | 181 | 0.0 182 | 184 | 185 | 0.0 186 | 188 | 189 | 0.0 190 | 192 | 193 | 0.0 194 | 196 | 197 | 0.0 198 |
203 | 204 | 非流动资产(%) 205 | 206 | 208 | 209 | 24.68 210 | 212 | 213 | 20.15 214 | 216 | 217 | 16.61 218 | 220 | 221 | 13.75 222 | 224 | 225 | 13.67 226 |
233 | 236 | 237 | 负债 238 | 240 | 241 | 应付款项(%) 242 | 243 | 245 | 246 | 0.0 247 | 249 | 250 | 0.0 251 | 253 | 254 | 0.74 255 | 257 | 258 | 0.74 259 | 261 | 262 | 0.8 263 |
268 | 269 | 流动负债(%) 270 | 271 | 273 | 274 | 23.23 275 | 277 | 278 | 32.78 279 | 281 | 282 | 28.66 283 | 285 | 286 | 26.55 287 | 289 | 290 | 27.52 291 |
296 | 297 | 非流动负债(%) 298 | 299 | 301 | 302 | 0.02 303 | 305 | 306 | 0.01 307 | 309 | 310 | 0.01 311 | 313 | 314 | 0.0 315 | 317 | 318 | 0.05 319 |
324 | 325 | 326 | 权益 327 | 329 | 330 | 股东权益(%) 331 | 332 | 334 | 335 | 76.75 336 | 338 | 339 | 67.21 340 | 342 | 343 | 71.33 344 | 346 | 347 | 73.45 348 | 350 | 351 | 72.44 352 |
359 |
360 | 361 | 362 | 363 |
364 |
365 |
366 | 367 |
368 |
369 |

现金流量表

370 |
371 |
372 |
373 | 374 |
375 | 376 | 377 | 378 | 379 | 383 | 386 | 389 | 392 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 410 | 415 | 418 | 421 | 424 | 427 | 430 | 431 | 432 | 433 | 442 | 447 | 450 | 453 | 456 | 459 | 462 | 463 | 464 | 465 | 474 | 479 | 482 | 485 | 488 | 491 | 494 | 495 | 496 | 497 | 506 | 511 | 514 | 517 | 520 | 523 | 526 | 527 | 528 | 529 | 538 | 543 | 546 | 549 | 552 | 555 | 558 | 559 | 560 | 561 | 570 | 575 | 578 | 581 | 584 | 587 | 590 | 591 | 592 | 593 |
类别 380 | 381 | 2015 382 | 384 | 2016 385 | 387 | 2017 388 | 390 | 2018 391 | 393 | 近12个月 394 |
402 | 403 | 期初现金 404 |
405 | 406 | 407 | 408 |
409 |
411 | 414 | 416 | 249.97亿 417 | 419 | 347.8亿 420 | 422 | 627.95亿 423 | 425 | 749.28亿 426 | 428 | 982.43亿 429 |
434 | 435 | + 营业活动现金流量 436 |
437 | 438 | (from 损益表) 439 | 440 |
441 |
443 | 446 | 448 | 174.36亿 449 | 451 | 374.51亿 452 | 454 | 221.53亿 455 | 457 | 413.85亿 458 | 460 | 477.37亿 461 |
466 | 467 | + 投资活动现金流量 468 |
469 | 470 | (from 资产负债表左) 471 | 472 |
473 |
475 | 478 | 480 | -20.49亿 481 | 483 | -11.03亿 484 | 486 | -11.21亿 487 | 489 | -16.29亿 490 | 492 | -20.26亿 493 |
498 | 499 | + 融资活动现金流量 500 |
501 | 502 | (from 资产负债表右) 503 | 504 |
505 |
507 | 510 | 512 | -55.88亿 513 | 515 | -83.35亿 516 | 518 | -88.99亿 519 | 521 | -164.41亿 522 | 524 | -216.18亿 525 |
530 | 531 | 期末现金 532 |
533 | 534 | 535 | 536 |
537 |
539 | 542 | 544 | 347.8亿 545 | 547 | 627.95亿 548 | 550 | 749.28亿 551 | 553 | 982.43亿 554 | 556 | 1223.36亿 557 |
562 | 563 | 自由现金流(FCF) 564 |
565 | 566 | 567 | 568 |
569 |
571 | 574 | 576 | 153.75亿 577 | 579 | 364.32亿 580 | 582 | 210.28亿 583 | 585 | 397.78亿 586 | 588 | 457.22亿 589 |
594 |
595 | 596 | 597 | 598 |
599 |
600 |
601 |
602 | -------------------------------------------------------------------------------- /pyqt/HTML/财报分析.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 |
6 |
7 |

{sname}({scode})近12个月财务分析报告

8 |
9 | 10 |
11 |
12 |
13 |

14 | 15 |
16 | {sname} 近 12 个月 ROE 为 {roe_12}% 17 |
18 | 19 |
{nprofit}%(净利率) x {turn_zzc} 次/年(总资产周转率) x {leverage} 倍(杠杆倍数) = {roe_12}%(ROE)
20 |
21 | {sname} 2014 ~ 2019 年的 ROE 从 {roe_2014}% 改变至 {roe_12}% 22 |
23 | 24 |
25 | 主要原因为【{reason_dupunt}】的改变。 26 |
27 | 28 |
【{t_kind}】行业
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 49 | 52 | 53 | 54 |
{sname}{t_kind}行业中位数
41 | ROE 42 | 44 | 47 | {roe_12}% 48 | 50 | {roe_mid}% 51 |
55 | 56 |
57 | 58 |

盈利状况 ({score_profit}/100)

59 | 60 |
61 | {sname}的毛利率 {gross_profit_rate}% 62 | ({comment_gpr}) 63 |
64 | 65 |
66 | {sname}的净利率 {net_profit_rate}% 67 | (comment_npr) 68 |
69 | 70 |
71 | {sname}每股税后赚到了 {eps}元 72 |
73 | 74 |
目前以 1043.33 元 投资贵州茅台,预估 33 年(P/E)会回本,年化为 3.01%(E/P)。
75 |
【白酒】行业
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 90 | 96 | 99 | 100 | 101 | 104 | 110 | 113 | 114 | 115 | 118 | 124 | 127 | 128 | 129 | 132 | 138 | 141 | 142 | 143 |
贵州茅台白酒行业中位数
88 | 毛利率 89 | 91 | 94 | 91.6% 95 | 97 | 72.7% 98 |
102 | 净利率 103 | 105 | 108 | 52.8% 109 | 111 | 20.3% 112 |
116 | 营业利润率 117 | 119 | 122 | 71.3% 123 | 125 | 26.7% 126 |
130 | 营业费用率 131 | 133 | 136 | 10.0% 137 | 139 | 24.7% 140 |
144 | 145 |
146 | 147 |

营运状况 (60.0/100)

148 | 149 |
150 | 贵州茅台的总资产周转率为 0.54 次/年 151 | (重资产,周转很慢) 152 |
153 | 154 |
155 | 贵州茅台的总资产里面有 13.7% 是固定资产 156 | 157 | 86.3% 是流动资产 158 | 159 | 有 14.5% 是存货 160 | (存货有点多) 161 | 有 0.4% 是应收帐款 162 | (几乎等于收现金) 163 |
164 | 165 |
166 | 贵州茅台的存货库存天数是 1254.0 天 167 | (下降趋势 2433.33 => 1258.62) 168 | 应收帐款天数是 3.2 天 169 | (持平) 170 |
171 | 172 |
做一轮生意需要 1257.2 天 = 1254.0 天(存货库存天数)+ 3.2 天(应收帐款天数)= 1257.2 天(完整生意周期)。
173 |
【白酒】行业
174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 188 | 194 | 197 | 198 | 199 | 202 | 208 | 211 | 212 | 213 | 216 | 222 | 225 | 226 | 227 | 230 | 236 | 239 | 240 | 241 | 244 | 250 | 253 | 254 | 255 | 258 | 264 | 267 | 268 | 269 | 272 | 278 | 281 | 282 | 283 |
贵州茅台白酒行业中位数
186 | 总资产周转率 187 | 189 | 192 | 0.54 次/年 193 | 195 | 0.58次/年 196 |
200 | 固定资产 201 | 203 | 206 | 13.7% 207 | 209 | 26.2% 210 |
214 | 流动资产 215 | 217 | 220 | 86.3% 221 | 223 | 73.8% 224 |
228 | 存货 229 | 231 | 234 | 14.5% 235 | 237 | 24.6% 238 |
242 | 应收帐款 243 | 245 | 248 | 0.4% 249 | 251 | 4.6% 252 |
256 | 存货库存天数 257 | 259 | 262 | 1254.0 天 263 | 265 | 397.33天 266 |
270 | 应收帐款天数 271 | 273 | 276 | 3.2 天 277 | 279 | 26.95天 280 |
284 | 285 |
286 | 287 |

杠杆状况 (90.0/100)

288 | 289 |
290 | 贵州茅台的杠杆倍数是 1.33 倍 291 | (基本没什么杠杆,看来股东非常看好公司) 292 |
293 | 294 |
【白酒】行业
295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 309 | 315 | 318 | 319 | 320 | 323 | 329 | 332 | 333 | 334 |
贵州茅台白酒行业中位数
307 | 权益乘数 308 | 310 | 313 | 1.33 倍 314 | 316 | 1.33 317 |
321 | 负债占资产比率 322 | 324 | 327 | 27.6% 328 | 330 | 24.0% 331 |
335 | 336 |
337 | 338 |

偿债能力 (90.0/100)

339 | 340 |
341 | 贵州茅台的流动比率是 313.7% 342 | 343 | 速动比率是 256.7% 344 | (即便发生债务纠纷,公司也能立即清偿) 345 | 利息保障倍数是 5.64 百亿倍 346 | (> 5,结构稳健) 347 |
348 | 349 |
【白酒】行业
350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 364 | 370 | 373 | 374 | 375 | 378 | 384 | 387 | 388 | 389 | 392 | 398 | 401 | 402 | 403 | 406 | 412 | 415 | 416 | 417 |
贵州茅台白酒行业中位数
362 | 流动比率 363 | 365 | 368 | 313.7% 369 | 371 | 309.7% 372 |
376 | 速动比率 377 | 379 | 382 | 256.7% 383 | 385 | 171.5% 386 |
390 | 利息保障倍数 391 | 393 | 396 | 5.64 百亿倍 397 | 399 | 8.48亿倍 400 |
404 | 负债占资产比率 405 | 407 | 410 | 27.6% 411 | 413 | 24.0% 414 |
418 | 419 |
420 | 421 |

现金流状况 (90.0/100)

422 | 423 |
424 | 贵州茅台 2018 年的现金流量比率 97.5% 425 | 426 | 现金流量允当比率 207.6% 427 | 428 | 现金再投资比率 21.2% 429 | (现金流状况一般.) 430 |
431 | 432 |
433 | 贵州茅台 2018 年的营业现金流 4.14 百亿 434 | 435 | 投资现金流 -16.29 亿 436 | 437 | 融资现金流 -1.64 百亿 438 | (将营业活动赚取的现金用再投资活动和偿还借款上。想必这家公司的营业现金流量宽裕) 439 |
440 | 441 |
【白酒】行业
442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 456 | 462 | 465 | 466 | 467 | 470 | 476 | 479 | 480 | 481 | 484 | 490 | 493 | 494 | 495 |
贵州茅台白酒行业中位数
454 | 现金流量比率 455 | 457 | 460 | 97.5% 461 | 463 | 48.5% 464 |
468 | 现金流量允当比率 469 | 471 | 474 | 207.6% 475 | 477 | 0.0% 478 |
482 | 现金再投资比率 483 | 485 | 488 | 21.2% 489 | 491 | 9.0% 492 |
496 | 497 |
498 | 499 | 500 |
501 |

总结

502 |
    503 |
  • 毛利率 91.6%:毛利堪比卖白粉
  • 504 |
  • 净利率 52.8%:即便是税后,公司也非常赚钱
  • 505 |
  • 总资产周转率 0.54 次/年:重资产,周转很慢
  • 506 |
  • 存货占总资产比率 14.5%:存货有点多
  • 507 |
  • 应收帐款 0.4%:几乎等于收现金
  • 508 |
  • 杠杆倍数 1.33 倍:基本没什么杠杆,看来股东非常看好公司
  • 509 |
  • 速动比率 256.7%:即便发生债务纠纷,公司也能立即清偿
  • 510 |
  • 利息保障倍数 5.64 百亿倍:利息保障倍数 > 5,结构稳健
  • 511 |
  • 现金与约当现金比率 70.0%:现金超多
  • 512 |
  • 现金流量比率 97.5%:现金流状况一般.
  • 513 |
  • 现金流营业 4.14 百亿, 投资 -16.29 亿, 融资 -1.64 百亿:将营业活动赚取的现金用再投资活动和偿还借款上。想必这家公司的营业现金流量宽裕
  • 514 |
  • 目前以 1043.33 元 投资贵州茅台,预估 33 年(P/E)会回本,年化为 3.01%(E/P)。
  • 515 |
516 |
517 | 518 | 519 |
520 |
521 |
522 | 532 |
533 | 534 |
535 | 536 | 537 | 539 | 540 | 545 | 546 | 548 | 549 | 551 | 552 | 554 | 555 | 556 | 557 | 559 | 560 | 562 | 563 | 565 | 566 | 568 | 569 | 571 | 572 | 573 | 574 | 576 | 577 | 579 | 580 | 582 | 583 | 585 | 586 | 588 | 589 | 590 | 591 | 593 | 594 | 596 | 597 | 599 | 600 | 602 | 603 | 605 | 606 | 607 | 608 | 610 | 611 | 613 | 614 | 616 | 617 | 619 | 620 | 622 | 623 | 624 |
538 | 541 | 542 | CBS: 94.21
PE: 33.27
543 | 544 |
547 | 550 | 553 |
558 | 561 | 564 | 567 | 570 |
575 | 578 | 581 | 584 | 587 |
592 | 595 | 598 | 601 | 604 |
609 | 612 | 615 | 618 | 621 |
625 | 626 |
627 |
628 | 629 |
630 |
631 | 632 |

633 | 以上财务分析结果仅供参考,不构成投资指导与建议
634 |

635 | 636 | 637 |
638 |
639 | 640 |
641 | 642 | 643 |
-------------------------------------------------------------------------------- /pyqt/__pycache__/html_maker.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pyqt/__pycache__/html_maker.cpython-36.pyc -------------------------------------------------------------------------------- /pyqt/__pycache__/indexData.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pyqt/__pycache__/indexData.cpython-36.pyc -------------------------------------------------------------------------------- /pyqt/__pycache__/main.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pyqt/__pycache__/main.cpython-36.pyc -------------------------------------------------------------------------------- /pyqt/__pycache__/regionRp.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pyqt/__pycache__/regionRp.cpython-36.pyc -------------------------------------------------------------------------------- /pyqt/img/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pyqt/img/close.png -------------------------------------------------------------------------------- /pyqt/img/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pyqt/img/start.png -------------------------------------------------------------------------------- /pyqt/indexData.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | from regionRp import Report_dealer 5 | import numpy as np 6 | 7 | 8 | class Report_index: 9 | def __init__(self,scode): 10 | # self.scode = input("输入股票代码:") 11 | self.scode =scode 12 | # self.year = input("输入年份:") 13 | # if self.year=="last": 14 | # self.info=self.getData(self.scode ,self.year ) 15 | # else: 16 | # self.info=self.getData(self.scode ,self.year ) 17 | # self.info0 =self.getData(self.scode, int(self.year) - 1) 18 | self.getData() 19 | '''指数数据如下''' 20 | self.five_index ={} 21 | self.cash_flow_dict={} 22 | self.alr_dict_list={} 23 | 24 | def getData(self): 25 | Rd = Report_dealer(self.scode) 26 | self.info = Rd.scheduler() 27 | 28 | def getData_cwzy(self): 29 | import pymongo 30 | from pymongo.collection import Collection 31 | # 建立连接 32 | client = pymongo.MongoClient('localhost', 27017) 33 | # 建立数据库 34 | db = client["XinlangFinance"] 35 | 36 | # 表的对象化 37 | mgtable = Collection(db, 'FinanceReport_data_cwzy') 38 | # print({"SECCODE":str(scode),"year":year}) 39 | data = mgtable.find({"SECCODE":self.scode}, {"_id": 0}) 40 | # print(data[0]) 41 | return data 42 | 43 | 44 | # 资产负债比率(重要科目) 45 | def asset_liability_ratio(self): 46 | alr_dict_list=[] 47 | info=self.info[0] 48 | 49 | '''资产部分''' 50 | alr_dict0={} 51 | # 比率(占总资产%) 52 | cap = np.array(info["资产总计"])#资产总计 53 | # 现金与约当现金(%) 54 | alr_dict0["现金与约当现金(%)"]= np.array(info["货币资金"])/cap 55 | # 应收款项( %) 56 | alr_dict0["应收款项( %)"] = np.array(info["应收票据及应收账款"])/cap 57 | # 存货( %) 58 | alr_dict0["存货( %)"] = np.array(info["存货"])/cap 59 | # 其他流动资产(%) 60 | alr_dict0["其他流动资产(%)"] = np.array(info["其他流动资产"])/cap 61 | # 流动资产( %) 62 | alr_dict0["流动资产( %)"] = np.array(info["流动资产合计"])/cap 63 | #商誉(%) 64 | alr_dict0["商誉(%)"] = np.array(info["商誉"])/ cap 65 | #非流动资产 66 | alr_dict0["非流动资产%)"] = np.array(info["非流动资产合计"])/ cap 67 | 68 | '''负债部分''' 69 | alr_dict_1 = {} 70 | #应付账款(%) 71 | alr_dict_1["应付账款(%)"]=np.array(info["应付票据及应付账款"])/cap 72 | # 流动负债(%) 73 | alr_dict_1["流动负债(%)"] = np.array(info["流动负债合计"]) / cap 74 | # 非流动资产(%) 75 | alr_dict_1["非流动资产(%)"] = np.array(info["非流动负债合计"]) / cap 76 | 77 | '''权益部分''' 78 | alr_dict_2 = {} 79 | #股东权益(%) 80 | alr_dict_2["股东权益(%)"]=np.array(info["所有者权益(或股东权益)合计"]) / cap 81 | 82 | # alr_dict_list.append(alr_dict) 83 | # alr_dict_list.append(alr_dict_1) 84 | # alr_dict_list.append(alr_dict_2) 85 | # for o in alr_dict_list: 86 | # print(o) 87 | alr_dict={} 88 | alr_dict["资产部分"]=alr_dict0 89 | alr_dict["负债部分"] =alr_dict_1 90 | alr_dict["权益部分"] =alr_dict_2 91 | self.alr_dict_list=alr_dict 92 | 93 | #现金流量表 94 | def cash_flow_st(self): 95 | info=self.info[2] 96 | cash_flow_dict={} 97 | #期初现金 98 | cash_flow_dict["期初现金"]=np.array(info["现金的期初余额"]) 99 | #+ 营业活动现金流量 (from 损益表) 100 | cash_flow_dict["+ 营业活动现金流量 (from 损益表)"] =np.array(info["经营活动产生的现金流量净额"]) 101 | #+ 投资活动现金流量 (from 资产负债表左) 102 | cash_flow_dict["+ 投资活动现金流量 (from 资产负债表左)"] =np.array(info["投资活动产生的现金流量净额"])#投资活动产生的现金流量净额 103 | #+ 融资活动现金流量 (from 资产负债表右) 104 | cash_flow_dict["+ 融资活动现金流量 (from 资产负债表右)"] =np.array(info["筹资活动产生的现金流量净额"])#筹资活动产生的现金流量净额 105 | #期末现金 106 | cash_flow_dict["期末现金"] = np.array(info["六、期末现金及现金等价物余额"]) 107 | #自由现金流(FCF)=经营活动产生的现金流量净额-购建固定资产、无形资产和其他长期资产支付的现金 108 | cash_flow_dict["自由现金流(FCF)"] = np.array(info["经营活动产生的现金流量净额"])-np.array(info["购建固定资产、无形资产和其他长期资产所支付的现金"]) 109 | # print(np.array(info["经营活动产生的现金流量净额"])) 110 | # print(np.array(["购建固定资产、无形资产和其他长期资产所支付的现金"])) 111 | # print(cash_flow_dict) 112 | self.cash_flow_dict=cash_flow_dict 113 | 114 | 115 | # #五大财务比率(+成长能力) 116 | def five_ratio(self): 117 | all_dict = {} 118 | info=self.info 119 | 120 | '''财务结构''' 121 | dict0 = {} 122 | 123 | dict0["资产负债率(%)"] = np.array(info[0]["负债合计"][:-1]) / np.array(info[0]["资产总计"][:-1]) 124 | dict0["权益乘数"] = np.array(info[0]["资产总计"][:-1]) / np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) 125 | dict0["长期资金占重资产比率(%)"] = (np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) + np.array(info[0]["非流动负债合计"][:-1])) / (np.array(info[0]["在建工程"][:-1]) + np.array(info[0]["固定资产净额"][:-1]) + np.array(info[0]["工程物资"][:-1])) # 长期资金占重资产比率(Longterm Ratio) = (股东权益+长期负债)(Total Equity + Non Current Liability) / (固定资产 + 工程物资 + 在建工程)(Fixed Assets + Construction Materials +Construction In Progress) 126 | 127 | '''偿债能力''' 128 | dict1 = {} 129 | dict1["流动比率(%)"] = np.array(info[0]["流动资产合计"][:-1]) / np.array(info[0]["流动负债合计"][:-1]) # 流动比率(Current Ratio) = 流动资产总额(Total Assets) / 流动负债总额(Current Liabilities) 130 | dict1["速动比率(%)"] =( np.array(info[0]["货币资金"][:-1])+np.array(info[0]["应收票据及应收账款"][:-1])+np.array(info[0]["其他应收款"][:-1])+np.array(info[0]["交易性金融资产"][:-1]) )/ np.array(info[0]["流动负债合计"][:-1]) 131 | 132 | '''缺利息费用,暂时用财务费用''' 133 | dict1["利息保障倍数"] = (np.array(info[1]["四、利润总额"][:-1]) - np.array(info[1]["财务费用"][:-1])) / np.array(info[1]["财务费用"][:-1]) # 利息保障倍数(Interest Coverage) = 息税前利润(EBITDA) / 利息费用(Interest Expense) 134 | 135 | '''运营能力''' 136 | dict2 = {} 137 | #平均应收账款 138 | avg_rvb=(( np.array(info[0]["应收账款"][1:])+np.array(info[0]["应收票据"][1:]) + np.array(info[0]["应收账款"][:-1])+ np.array(info[0]["应收票据"][:-1]) ) / 2) 139 | avg_rvb[0]=(info[-1]["应收账款"][0]+info[-1]["应收账款"][-1]+info[-1]["应收票据"][0]+info[-1]["应收票据"][-1])/2 140 | dict2["应收款项周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) /avg_rvb# 应收款项周转率(次/年) = 营业收入/平均应收账款 141 | # print(np.array(info[0]["应收票据及应收账款"][1:]) + np.array(info[0]["应收票据及应收账款"][:-1])) 142 | dict2["应收款项周转天数(天)"] = 365 / dict2["应收款项周转率(次/年)"] 143 | 144 | avg_inv = ((np.array(info[0]["存货"][1:])+ np.array(info[0]["存货"][:-1])) / 2) 145 | avg_inv[0] = (info[-1]["存货"][0] + info[-1]["存货"][-1] ) / 2 146 | dict2["存货周转率(次/年)"] = np.array(info[1]["营业成本"][:-1]) / avg_inv # 营业成本/平均存货 147 | dict2["存货周转天数(天)"] = 365 / dict2["存货周转率(次/年)"] 148 | 149 | avg_fa = ((np.array(info[0]["固定资产净额"][1:]) + np.array(info[0]["固定资产净额"][:-1])) / 2) 150 | avg_fa[0] = (info[-1]["固定资产净额"][0] + info[-1]["固定资产净额"][-1]) / 2 151 | dict2["固定资产周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) / avg_fa 152 | # dict2["完整生意周期(天)"] = 153 | # 销售成本÷平均应付账款 154 | 155 | avg_pbl = ((np.array(info[0]["应付账款"][1:]) + np.array(info[0]["应付票据"][1:]) + np.array(info[0]["应付账款"][:-1]) + np.array(info[0]["应付票据"][:-1])) / 2) 156 | avg_pbl[0] = (info[-1]["应付账款"][0] + info[-1]["应付账款"][-1] + info[-1]["应付票据"][0] + info[-1]["应付票据"][-1]) / 2 157 | dict2["应付款项周转天数(天)"] = avg_pbl*365/np.array(info[1]["营业成本"][:-1]) 158 | 159 | avg_ta = ((np.array(info[0]["资产总计"][1:]) + np.array(info[0]["资产总计"][:-1])) / 2) 160 | avg_ta[0] = (info[-1]["资产总计"][0] + info[-1]["资产总计"][-1]) / 2 161 | dict2["总资产周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) / avg_ta 162 | 163 | '''盈利能力''' 164 | dict3 = {} 165 | 166 | dict3["ROA=资产收益率(%)"] = np.array(info[1]["五、净利润"][:-1]) / avg_ta 167 | # dict3["ROE=净资产收益率(%)"] = np.array(info[1]["五、净利润"][:-1]) / ( 168 | # (np.array(info[0]["所有者权益(或股东权益)合计"][1:]) + np.array(info[0]["所有者权益(或股东权益)合计"][:-1])) / 2) 169 | 170 | dict3["毛利率(%)"] = (np.array(info[1]["营业收入"][:-1]) - np.array(info[1]["营业成本"][:-1])) / np.array(info[1]["营业收入"][:-1]) 171 | dict3["营业利润率(%)"] = np.array(info[1]["三、营业利润"][:-1]) / np.array(info[1]["营业收入"][:-1]) 172 | dict3["净利率(%)"] = np.array(info[1]["五、净利润"][:-1]) / np.array(info[1]["营业收入"][:-1]) 173 | dict3["营业费用率(%)"] = (np.array(info[1]["销售费用"][:1]) + np.array(info[1]["财务费用"][:-1]) + np.array(info[1]["管理费用"][:-1]) )/ np.array(info[1]["营业收入"][:-1]) 174 | dict3["经营安全边际率(%)"] = dict3["营业利润率(%)"]/ dict3["毛利率(%)"] 175 | dict3["EPS=基本每股收益(元)"] =np.array(info[1]["基本每股收益(元/股)"][:-1]) 176 | 177 | '''成长能力''' 178 | dict4 = {} 179 | cwzy_info=self.getData_cwzy()[0] 180 | main_income=(cwzy_info[info[0]["报表日期"][0]]["主营业务收入"]-cwzy_info[info[0]["报表日期"][0].replace("2019","2018")]["主营业务收入"])/cwzy_info[info[0]["报表日期"][0].replace("2019","2018")]["主营业务收入"] 181 | main_2018=(cwzy_info["2018-12-31"]["主营业务收入"]-cwzy_info["2017-12-31"]["主营业务收入"])/cwzy_info["2017-12-31"]["主营业务收入"] 182 | main_2017=(cwzy_info["2017-12-31"]["主营业务收入"]-cwzy_info["2016-12-31"]["主营业务收入"])/cwzy_info["2016-12-31"]["主营业务收入"] 183 | main_2016=(cwzy_info["2016-12-31"]["主营业务收入"]-cwzy_info["2015-12-31"]["主营业务收入"])/cwzy_info["2015-12-31"]["主营业务收入"] 184 | main_2015=(cwzy_info["2015-12-31"]["主营业务收入"]-cwzy_info["2014-12-31"]["主营业务收入"])/cwzy_info["2014-12-31"]["主营业务收入"] 185 | main_r=np.array([main_income,main_2018,main_2017,main_2016,main_2015]) 186 | # print(cwzy_info[info[0]["报表日期"][-1]]["主营业务收入"],info[0]["报表日期"]) 187 | dict4["营收增长率(%)"] = main_r 188 | 189 | profit=(np.array(info[1]["三、营业利润"][:-1]) - np.array(info[1]["三、营业利润"][1:])) / np.array(info[1]["三、营业利润"][1:]) 190 | profit[0]=(self.info[3]["三、营业利润"][0] - self.info[3]["三、营业利润"][-1]) / self.info[3]["三、营业利润"][-1] 191 | dict4["营业利润增长率(%)"] =profit 192 | # print(dict4["营业利润增长率(%)"]) 193 | 194 | nzb=(np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) - np.array(info[0]["所有者权益(或股东权益)合计"][1:])) / np.array(info[0]["所有者权益(或股东权益)合计"][1:]) 195 | nzb[0]=(self.info[3]["所有者权益(或股东权益)合计"][0] - self.info[3]["所有者权益(或股东权益)合计"][-1]) / self.info[3]["所有者权益(或股东权益)合计"][-1] 196 | dict4["净资产增长率(%)"] = nzb 197 | '''现金流量''' 198 | dict5 = {} 199 | 200 | dict5["现金流量比率(%)"] = np.array(info[2]["经营活动产生的现金流量净额"][:-1]) / np.array(info[0]["流动负债合计"][:-1]) 201 | # dict5["现金流量允当比率(%)"] = 202 | # dict5["现金再投资比率(%)"] = 203 | avg_na = ((np.array(info[0]["所有者权益(或股东权益)合计"][1:]) + np.array(info[0]["所有者权益(或股东权益)合计"][:-1])) / 2) 204 | avg_na[0] = (info[-1]["所有者权益(或股东权益)合计"][0] + info[-1]["所有者权益(或股东权益)合计"][-1]) / 2 205 | dict3["ROE=净资产收益率(%)"] = dict3["净利率(%)"]*dict2["总资产周转率(次/年)"]*(1/(1-dict0["资产负债率(%)"])) 206 | dict3["ROE=净资产收益率(%)2"] = np.array(info[1]["五、净利润"][:-1])/avg_na 207 | 208 | all_dict["财务结构"] = dict0 209 | all_dict["偿债能力"] = dict1 210 | all_dict["运营能力"] = dict2 211 | all_dict["盈利能力"] = dict3 212 | all_dict["成长能力"] = dict4 213 | all_dict["现金流量"] = dict5 214 | # all_dict.extend([dict0,dict1,dict2,dict3,dict4,dict5]) 215 | # for i in all_dict: 216 | # print(i) 217 | self.five_index=all_dict 218 | 219 | def scheduler(self): 220 | self.asset_liability_ratio() 221 | self.cash_flow_st() 222 | self.five_ratio() 223 | return self.five_index ,self.cash_flow_dict,self.alr_dict_list 224 | ''' 225 | 五类财务比率: 226 | data={ '财务结构': {...}, 227 | '偿债能力': {...}, 228 | '运营能力': {...}, 229 | '盈利能力': {...}, 230 | '成长能力': {...}, 231 | '现金流量': {...}, 232 | } 233 | 现金流量: 234 | Ri.scheduler()[1]={ '期初现金':array(...), 235 | '+ 营业活动现金流量 (from 损益表)':array(...), 236 | '+ 投资活动现金流量 (from 资产负债表左)':array(...), 237 | '+ 融资活动现金流量 (from 资产负债表右)':array(...),} 238 | 资产负债百分比: 239 | Ri.scheduler()[2]={ '资产部分':{...}, 240 | '负债部分': {...}, 241 | '权益部分': {...} } 242 | ''' 243 | 244 | 245 | if __name__ == '__main__': 246 | Rp=Report_index("600519") 247 | print(Rp.scheduler()) 248 | -------------------------------------------------------------------------------- /pyqt/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | import codecs 3 | import numpy as np 4 | __author__ = "Gallen_qiu" 5 | from PyQt5.Qt import * 6 | import sys 7 | from PyQt5.QtWidgets import * 8 | from PyQt5.QtWebEngineWidgets import * 9 | from regionRp import Report_dealer 10 | from indexData import Report_index 11 | from html_maker import HtmlMaker 12 | import sys 13 | import os 14 | currentUrl = os.path.dirname(__file__) 15 | parentUrl = os.path.abspath(os.path.join(currentUrl, os.pardir)) 16 | sys.path.append(parentUrl) 17 | 18 | '''导入所需要的包''' 19 | 20 | class Window(QTabWidget): 21 | 22 | def __init__(self,scode): 23 | super().__init__() 24 | self.scode=scode 25 | #生成html 26 | HtmlMaker(self.scode) 27 | 28 | 29 | # 获取数据 30 | self.data = {} 31 | self.data1 = {} 32 | self.getData1() 33 | self.getData2() 34 | self.score_ = {} # cbs评分 35 | self.score() 36 | 37 | 38 | self.setWindowTitle("主窗口") 39 | self.resize(500, 500) 40 | self.move(400, 200) # 在显示器上移动 41 | self.setTabPosition(QTabWidget.South) 42 | tabbar=QTabBar() 43 | tabbar.setShape(QTabBar.Shape(5)) 44 | # tabbar.setStyleSheet("color:cyan;") 45 | self.setTabBar(tabbar) 46 | 47 | #最大化 48 | self.showMaximized() 49 | 50 | # 创建3个选项卡小控件窗口 51 | self.tab1 = QWidget() 52 | # self.tab1.setStyleSheet("background-color:cyan;") 53 | self.tab2 = QWidget() 54 | self.tab3 = QWidget() 55 | 56 | # 将三个选项卡添加到顶层窗口中 57 | self.addTab(self.tab1, "Tab 1") 58 | self.addTab(self.tab2, "Tab 2") 59 | self.addTab(self.tab3, "Tab 3") 60 | self.setTabText(0, '主页面') 61 | self.setTabText(1, '杜邦分析') 62 | self.setTabText(2, '财报分析') 63 | 64 | #调用子控件 65 | self.setup_tab1() 66 | self.setup_tab3() 67 | 68 | 69 | '''获取原始报表数据集合''' 70 | def getData1(self): 71 | Ri=Report_dealer(self.scode) 72 | 73 | self.data=Ri.scheduler()[0] 74 | ''' 75 | return self.balanceS ,self.incomeS,self.cashFlowS,self.last12 76 | ''' 77 | 78 | '''获取重要指标数据集合''' 79 | def getData2(self): 80 | Ri=Report_index(self.scode) 81 | 82 | self.data1=Ri.scheduler() 83 | ''' 84 | 五类财务比率: 85 | data={ '财务结构': {...}, 86 | '偿债能力': {...}, 87 | '运营能力': {...}, 88 | '盈利能力': {...}, 89 | '成长能力': {...}, 90 | '现金流量': {...}, 91 | } 92 | 现金流量: 93 | Ri.scheduler()[1]={ '期初现金':array(...), 94 | '+ 营业活动现金流量 (from 损益表)':array(...), 95 | '+ 投资活动现金流量 (from 资产负债表左)':array(...), 96 | '+ 融资活动现金流量 (from 资产负债表右)':array(...),} 97 | 资产负债百分比: 98 | Ri.scheduler()[2]={ '资产部分':{...}, 99 | '负债部分': {...}, 100 | '权益部分': {...} } 101 | ''' 102 | 103 | '''各项能力的评分''' 104 | def score(self): 105 | ''' 106 | "现金占比权重(去年)30% 107 | "经营能力权重(去年)30% 108 | "获利能力权重(去年)20% 109 | "财务结构权重(去年)10% 110 | "偿债能力权重(去年)10% 111 | ''' 112 | # 求股票的气 113 | # 现金占比 114 | # 现金与约当现金占比->7分 115 | score={"现金占比":0,"运营能力":0,"盈利能力":0,"财务结构":0,"偿债能力":0,"Total":0} 116 | 117 | data = self.data1 118 | value = data[2]["资产部分"]["现金与约当现金(%)"][0]*100 119 | if value >= 10: 120 | score["现金占比"] += 7 121 | else: 122 | score["现金占比"] += value * 7 / 25 123 | # 求股票的应收款周转天数->2分 124 | value = data[0]["运营能力"]["应收款项周转天数(天)"][0] 125 | if value <= 15: 126 | score["现金占比"] += 2 127 | else: 128 | score["现金占比"] +=2 * 15 / value 129 | # 现金的三大比例->1分 130 | # i = 0 131 | value=data[0]["现金流量"]["现金流量比率(%)"][0]*100 132 | if value >= 100: # 现金流量比率 133 | i = 1 134 | else: 135 | i = value / 100 136 | # if data[35, j] >= 100: # 现金允当比例 137 | # i = i + 1 138 | # else: 139 | # i = (data[35, j] / 100) + i 140 | # if data[36, j] >= 10: # 现金在投资比例 141 | # i = i + 1 142 | # else: 143 | # i = i + (data[36, j] / 100) 144 | # score[0, j] = score[0, j] + i / 3 145 | score["现金占比"]=score["现金占比"]+i/1 146 | if score["现金占比"] == -np.inf: 147 | score["现金占比"] = 0 148 | 149 | # 经营能力 150 | # 资产周转率->5分 151 | value = data[0]["运营能力"]["总资产周转率(次/年)"][0] 152 | if value < 1: 153 | score["运营能力"] = score["现金占比"]#???? 154 | else: 155 | score["运营能力"] += 5 156 | 157 | value = data[0]["运营能力"]["存货周转天数(天)"][0] 158 | if value <= 30: # 存货周转天数->2.5 159 | score["运营能力"] += 2.5 160 | else: 161 | score["运营能力"] += 2.5 * 30 / value 162 | 163 | value = data[0]["运营能力"]["应收款项周转天数(天)"][0] 164 | if value <= 90: # 应收款项周转天数->2.5 165 | score["运营能力"] += 2.5 166 | else: 167 | score["运营能力"] += 2.5 * 60 / value 168 | 169 | # 获利能力 170 | # 毛利率->2 171 | value = data[0]["盈利能力"]["毛利率(%)"][0]*100 172 | if value >= 32: 173 | score["盈利能力"] += 2 174 | else: 175 | score["盈利能力"] += 2 * value / 30 176 | # 营业利益率->2 177 | value = data[0]["盈利能力"]["营业利润率(%)"][0] * 100 178 | if value >= 10: 179 | score["盈利能力"] += 2 180 | else: 181 | score["盈利能力"] += 2 * value / 10 182 | # 经营安全边界->2 183 | value = data[0]["盈利能力"]["经营安全边际率(%)"][0] * 100 184 | if value >= 60: 185 | score["盈利能力"] += 2 186 | else: 187 | score["盈利能力"] += 2 * value / 60 188 | # 净利率->1 189 | value = data[0]["盈利能力"]["净利率(%)"][0] * 100 190 | if value >= 2: 191 | score["盈利能力"] += 1 192 | else: 193 | score["盈利能力"] += value / 2 194 | # EPS->1 195 | value = data[0]["盈利能力"]["EPS=基本每股收益(元)"][0] 196 | if value >= 1: 197 | score["盈利能力"] += 1 198 | else: 199 | score["盈利能力"] +=value 200 | value = data[0]["盈利能力"]["ROE=净资产收益率(%)"][0] * 100 201 | if value >= 20: # ROE 202 | score["盈利能力"] += 1 203 | else: 204 | score["盈利能力"] += value / 20 205 | 206 | if score["盈利能力"] == -np.inf: 207 | score["盈利能力"] = 0 208 | 209 | # 财务结构 210 | # 负债占资产比例->5 211 | value = data[0]["财务结构"]["资产负债率(%)"][0] * 100 212 | if (value >= 25) and (value <= 70): 213 | score["财务结构"] += 5 214 | elif value < 25: 215 | score["财务结构"] += 5 * value / 25 216 | else: 217 | pass 218 | # 长期资金占不动产比率->5 219 | value = data[0]["财务结构"]["长期资金占重资产比率(%)"][0] * 100 220 | if value >= 100: 221 | score["财务结构"] += 5 222 | else: 223 | score["财务结构"] += 5 * value / 100 224 | 225 | # 偿债能力 226 | # 流动比率->5 227 | value = data[0]["偿债能力"]["流动比率(%)"][0] * 100 228 | if value >= 300: 229 | score["偿债能力"] += 5 230 | else: 231 | score["偿债能力"] += 5 * value / 300 232 | # 速动比率 233 | value = data[0]["偿债能力"]["速动比率(%)"][0] * 100 234 | if value >= 150: 235 | score["偿债能力"] += 5 236 | else: 237 | score["偿债能力"] += 5 * value / 100 238 | 239 | score["Total"] = score["现金占比"] * 3 + score["运营能力"] * 3 + score["盈利能力"] * 2 + score["偿债能力"] + score["财务结构"] 240 | self.score_=score 241 | 242 | '''第一个页面:主页面展示''' 243 | def setup_tab1(self): 244 | self.layout00 = QVBoxLayout() 245 | # self.label0_1 = QWidget() 246 | self.setup_label0() 247 | 248 | self.layout01=QHBoxLayout() 249 | self.setup_label1() 250 | '''第一个布局''' 251 | layout0=QHBoxLayout() 252 | layout0.addLayout(self.layout00, 1) 253 | layout0.addLayout(self.layout01, 3) 254 | # layout0.addWidget(label0_3, 1) 255 | # layout0.addWidget(label0_4, 1) 256 | # layout0.addWidget(label0_5, 1) 257 | # layout0.addWidget(label0_6, 1) 258 | # layout0.addWidget(label0_7, 1) 259 | 260 | 261 | # label1_1 = QLabel() 262 | # label1_1.setStyleSheet("border;") 263 | label1_1 = Comment() 264 | label1_1.comment() 265 | label1_1.setContentsMargins(0, 0, 0, 0) 266 | '''重要财务比率''' 267 | label1_2 = Rate_index() 268 | label1_2.rate_index() 269 | label1_2.setContentsMargins(0,0,0,0) 270 | 271 | label1_3_1 = Rate_index_zfb() 272 | label1_3_1.rate_index() 273 | label1_3_1.setContentsMargins(0, 0, 0, 0) 274 | 275 | 276 | '''第二个布局''' 277 | layout1 = QHBoxLayout() 278 | layout1.addWidget(label1_1, 4) 279 | layout1.addWidget(label1_2, 7) 280 | layout1.addWidget(label1_3_1,5) 281 | '''创建布局管理器''' 282 | layout_main = QVBoxLayout() # 垂直排列布局 283 | '''添加layout''' 284 | layout_main.addSpacing(50) 285 | layout_main.addLayout(layout0,10) 286 | layout_main.addLayout(layout1,35) 287 | '''插入空白''' 288 | # layout.insertSpacing(3,30) 289 | '''布局管理器设置''' 290 | # 外边框 291 | layout_main.setContentsMargins(2, 2, 2, 2) # 左,上,右,下 292 | # 内边框 293 | layout_main.setSpacing(2) 294 | 295 | self.tab1.setLayout(layout_main) 296 | 297 | # self.tab1.setLayoutDirection(Qt.LeftToRight) # Qt.RightToLeft Qt.LayoutDirectionAuto 298 | '''第一个页面:上半部分布局-左''' 299 | def setup_label0(self): 300 | 301 | info=self.data 302 | l_Qlabel00=QLabel() 303 | l_Qlabel00.setText(' ') # 股票名称 304 | l_Qlabel00.setStyleSheet("font-size : 50px;font-family : fantasy;font-variant : normal;font-weight : 600;font-style : normal;background-color:#5F9EA0;") 305 | l_Qlabel0 = QLabel() 306 | l_Qlabel0.setText(' '+info["SECNAME"])#股票名称 307 | l_Qlabel0.setStyleSheet("font-size : 50px;font-family : fantasy;font-variant : normal;font-weight : 600;font-style : normal;background-color:#B0E0E6;") 308 | l_Qlabel1 = QLabel() 309 | l_Qlabel1.setText(' '+info["SECCODE"]) # 股票代码 310 | l_Qlabel1.setStyleSheet("font-size : 38px;background-color:#B0E0E6;") 311 | 312 | l_Qlabel2 = QLabel() 313 | 314 | l_Qlabel2.setText(' 行业分类:{}-{}-{}'.format(info["f_kind"],info["s_kind"],info["t_kind"])) # 股票代码 315 | l_Qlabel2.setStyleSheet("font-size : 22px;background-color:#B0E0E6;") 316 | # self.layout00.addStretch(1) 317 | self.layout00.addWidget(l_Qlabel00, 1) 318 | self.layout00.addWidget(l_Qlabel0,1) 319 | self.layout00.addWidget(l_Qlabel1,1) 320 | self.layout00.addWidget(l_Qlabel2,1) 321 | self.layout00.setContentsMargins(0,0,0,0) 322 | self.layout00.setSpacing(0) 323 | color_label = QLabel() 324 | color_label.setStyleSheet("background-color:#B0E0E6;") 325 | 326 | '''第一个页面:上半部分布局-右''' 327 | def setup_label1(self): 328 | score=self.score_ 329 | 330 | label0 = QLabel(" 现金流量(30%)") 331 | label0.setStyleSheet("font-size : 22px;") 332 | # label0.setContentsMargins() 333 | label1 = QLabel(' {}/100.00'.format(round(score["现金占比"]*10,2))) 334 | label1.setStyleSheet("font-size : 30px;border:1px solid; border-bottom-color : #B0C4DE;border-top-color : #FFFFFF;border-left-color : #FFFFFF;border-right-color : #FFFFFF;") 335 | 336 | box0=QVBoxLayout() 337 | box0.addStretch(1) 338 | box0.addWidget(label0, 2) 339 | box0.addWidget(label1, 4) 340 | 341 | label0 = QLabel(" 运营能力(30%)") 342 | label0.setStyleSheet("font-size : 22px;") 343 | label1 = QLabel(' {}/100.00'.format(round(score["运营能力"] * 10, 2))) 344 | label1.setStyleSheet("font-size : 30px;border:1px solid; border-bottom-color : #B0C4DE;border-top-color : #FFFFFF;border-left-color : #FFFFFF;border-right-color : #FFFFFF;") 345 | 346 | box1 = QVBoxLayout() 347 | box1.addStretch(1) 348 | box1.addWidget(label0, 2) 349 | box1.addWidget(label1, 4) 350 | 351 | label0 = QLabel(" 盈利能力(20%)") 352 | label0.setStyleSheet("font-size : 22px;") 353 | label1 = QLabel(' {}/100.00'.format(round(score["盈利能力"] * 10, 2))) 354 | label1.setStyleSheet("font-size : 30px;border:1px solid; border-bottom-color : #B0C4DE;border-top-color : #FFFFFF;border-left-color : #FFFFFF;border-right-color : #FFFFFF;") 355 | 356 | box2 = QVBoxLayout() 357 | box2.addStretch(1) 358 | box2.addWidget(label0, 2) 359 | box2.addWidget(label1, 4) 360 | 361 | label0 = QLabel(" 财务结构(10%)") 362 | label0.setStyleSheet("font-size : 22px;") 363 | label1 = QLabel(' {}/100.00'.format(round(float('%.3f' % score["财务结构"]) * 10, 3))) 364 | label1.setStyleSheet("font-size :30px;border:1px solid; border-bottom-color : #B0C4DE;border-top-color : #FFFFFF;border-left-color : #FFFFFF;border-right-color : #FFFFFF;") 365 | 366 | box3 = QVBoxLayout() 367 | box3.addStretch(1) 368 | box3.addWidget(label0, 2) 369 | box3.addWidget(label1, 4) 370 | 371 | label0 = QLabel(" 偿债能力(10%)") 372 | label0.setStyleSheet("font-size : 22px;") 373 | label1 = QLabel(' {}/100.00'.format(round(score["偿债能力"] * 10, 2))) 374 | label1.setStyleSheet("font-size : 30px;border:1px solid; border-bottom-color : #B0C4DE;border-top-color : #FFFFFF;border-left-color : #FFFFFF;border-right-color : #FFFFFF;") 375 | 376 | box4 = QVBoxLayout() 377 | box4.addStretch(1) 378 | box4.addWidget(label0, 2) 379 | box4.addWidget(label1, 4) 380 | 381 | label0 = QLabel("\n 加权评分") 382 | label0.setStyleSheet("background-color:#5F9EA0;font-size : 22px;font-weight : bold;") 383 | 384 | label1 = QLabel(' {}/100.00'.format(round(score["Total"], 2))) 385 | label1.setStyleSheet("background-color:#B0E0E6;font-size : 40px;font-weight : 900;border:1px ; border-bottom-color : #B0C4DE;border-top-color : #FFFFFF;border-left-color : #FFFFFF;border-right-color : #FFFFFF;") 386 | # label1.setMargin(100) 387 | box5 = QVBoxLayout() 388 | box5.setSpacing(0) 389 | 390 | # box5.addStretch(1) 391 | box5.addWidget(label0,1) 392 | box5.addWidget(label1,3) 393 | self.layout01.addLayout(box0,2) 394 | self.layout01.addLayout(box1,2) 395 | self.layout01.addLayout(box2,2) 396 | self.layout01.addLayout(box3,2) 397 | self.layout01.addLayout(box4,2) 398 | self.layout01.addLayout(box5,3) 399 | 400 | 401 | 402 | 403 | '''第三个页面:财报分析展示''' 404 | def setup_tab3(self): 405 | layout=QVBoxLayout() 406 | 407 | self.view = QWebEngineView() 408 | 409 | layout.addWidget(self.view,10) 410 | with codecs.open("cb.html", "r", "utf-8") as f: 411 | html = f.read() 412 | self.view.setHtml(html) 413 | # self.time = QTimer() 414 | 415 | self.tab3.setLayout(layout) 416 | 417 | '''重要财务比率窗口''' 418 | class Rate_index(QWidget): 419 | 420 | def rate_index(self): 421 | layout = QVBoxLayout() 422 | 423 | view = QWebEngineView() 424 | # layout.addStretch(1) 425 | layout.addWidget(view,24) 426 | 427 | with codecs.open("HTML/rate_index.html", "r", "utf-8") as f: 428 | html = f.read() 429 | view.setHtml(html) 430 | self.setLayout(layout) 431 | 432 | self.loadCSS(view, "HTML/rate_index.css", "alkeyTabContent") 433 | 434 | 435 | def loadCSS(self,view, path, name): 436 | path = QFile(path) 437 | if not path.open(QFile.ReadOnly | QFile.Text): 438 | return 439 | css = path.readAll().data().decode("utf-8") 440 | SCRIPT = """ 441 | (function() { 442 | css = document.createElement('style'); 443 | css.type = 'text/css'; 444 | css.id = "%s"; 445 | document.head.appendChild(css); 446 | css.innerText = `%s`; 447 | })() 448 | """ % (name, css) 449 | 450 | script = QWebEngineScript() 451 | view.page().runJavaScript(SCRIPT,QWebEngineScript.ApplicationWorld) 452 | script.setName(name) 453 | script.setSourceCode(SCRIPT) 454 | script.setInjectionPoint(QWebEngineScript.DocumentReady) 455 | script.setRunsOnSubFrames(True) 456 | script.setWorldId(QWebEngineScript.ApplicationWorld) 457 | view.page().scripts().insert(script) 458 | 459 | '''资产负债表百分比比率窗口、现金流量比率窗口''' 460 | class Rate_index_zfb(QWidget): 461 | 462 | def rate_index(self): 463 | layout = QVBoxLayout() 464 | 465 | view = QWebEngineView() 466 | layout.addWidget(view) 467 | with codecs.open("HTML/zfb_index.html", "r", "utf-8") as f: 468 | html = f.read() 469 | view.setHtml(html) 470 | self.setLayout(layout) 471 | self.loadCSS(view, "HTML/zfb_index.css", "albsTabContent") 472 | 473 | def loadCSS(self,view, path, name): 474 | path = QFile(path) 475 | if not path.open(QFile.ReadOnly | QFile.Text): 476 | return 477 | css = path.readAll().data().decode("utf-8") 478 | SCRIPT = """ 479 | (function() { 480 | css = document.createElement('style'); 481 | css.type = 'text/css'; 482 | css.id = "%s"; 483 | document.head.appendChild(css); 484 | css.innerText = `%s`; 485 | })() 486 | """ % (name, css) 487 | 488 | script = QWebEngineScript() 489 | view.page().runJavaScript(SCRIPT,QWebEngineScript.ApplicationWorld) 490 | script.setName(name) 491 | script.setSourceCode(SCRIPT) 492 | script.setInjectionPoint(QWebEngineScript.DocumentReady) 493 | script.setRunsOnSubFrames(True) 494 | script.setWorldId(QWebEngineScript.ApplicationWorld) 495 | view.page().scripts().insert(script) 496 | 497 | '''评论窗口''' 498 | class Comment(QWidget): 499 | def comment(self): 500 | layout = QVBoxLayout() 501 | view = QWebEngineView() 502 | layout.addStretch(1) 503 | layout.addWidget(view, 24) 504 | with codecs.open("HTML/comment.html", "r", "utf-8") as f: 505 | html = f.read() 506 | view.setHtml(html) 507 | self.setLayout(layout) 508 | 509 | self.loadCSS(view, "HTML/comment.css", "alkeyTabContent") 510 | 511 | def loadCSS(self, view, path, name): 512 | path = QFile(path) 513 | if not path.open(QFile.ReadOnly | QFile.Text): 514 | return 515 | css = path.readAll().data().decode("utf-8") 516 | SCRIPT = """ 517 | (function() { 518 | css = document.createElement('style'); 519 | css.type = 'text/css'; 520 | css.id = "%s"; 521 | document.head.appendChild(css); 522 | css.innerText = `%s`; 523 | })() 524 | """ % (name, css) 525 | 526 | script = QWebEngineScript() 527 | view.page().runJavaScript(SCRIPT, QWebEngineScript.ApplicationWorld) 528 | script.setName(name) 529 | script.setSourceCode(SCRIPT) 530 | script.setInjectionPoint(QWebEngineScript.DocumentReady) 531 | script.setRunsOnSubFrames(True) 532 | script.setWorldId(QWebEngineScript.ApplicationWorld) 533 | view.page().scripts().insert(script) 534 | 535 | 536 | 537 | if __name__ == '__main__': 538 | 539 | app=QApplication(sys.argv)##############创建程序,接收外部参数 540 | window=Window()#window是第一个控件,也是顶层控件;会自动添加窗口上沿(缩小、关闭、title) 541 | window.show() 542 | sys.exit(app.exec_())####################结束程序,返回结束参数;app.exec_()进入消息循环 -------------------------------------------------------------------------------- /pyqt/null: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/pyqt/null -------------------------------------------------------------------------------- /pyqt/rate_index_副本.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

五大财务比率(+成长能力)

4 |
5 |
6 |
7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 21 | 24 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
  类别财务比率趋势 16 | 2015 17 | 19 | 2016 20 | 22 | 2017 23 | 25 | 2018 26 | 28 | 近12个月 29 |
37 | 38 | 财务结构 39 | 40 | 负债占资产比率(%)23.332.828.726.527.6
长期资金占重资产比率(%)406.2441.4556.4682.5683.1
50 | 51 | 偿债能力 52 | 53 | 流动比率(%)324.2243.6291.0324.9313.7
速动比率(%)227.0183.4231.6266.2256.7
利息保障倍数
66 | 运营能力 67 | 应收款项周转率(次/年)6.38.357.182.5113.9
应收款项周转天数(天)58.344.16.44.43.2
存货周转率(次/年)0.20.20.30.30.3
存货周转天数(天)2,372.32,067.71,311.21,274.81,254.0
固定资产周转率(次/年)3.03.03.94.85.3
应付款项周转天数(天)114.2102.862.460.767.9
总资产周转率(次/年)0.430.390.470.500.54
92 | 盈利能力 93 | ROA=资产收益率(%)21.618.023.425.728.5
ROE=净资产收益率(%)26.424.433.034.537.8
税前纯益占实收资本(%)1,834.91,907.23,083.94,046.14,489.6
毛利率(%)92.291.289.891.191.6
营业利润率(%)67.862.466.969.771.3
净利率(%)50.446.149.851.452.8
营业费用率(%)16.015.013.110.710.0
经营安全边际率(%)73.668.474.576.577.9
EPS=基本每股收益(元)12.3413.3121.5628.0231.35
123 | 成长能力 124 | 营收增长率(%)3.419.049.826.518.2
营业利润增长率(%)0.39.560.531.924.1
净资本增长率(%)19.714.626.522.323.9
136 | 现金流量 137 | 现金流量比率(%)87.0101.257.497.5105.1
148 | 149 | 150 |
151 | 152 | 153 | 154 |
155 |
156 |
-------------------------------------------------------------------------------- /pyqt/start.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'C:\Users\user\Desktop\A股数据预测\1.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.6 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | from PyQt5 import QtCore, QtGui, QtWidgets 10 | from PyQt5.QtCore import Qt 11 | from PyQt5.QtCore import QCoreApplication 12 | from PyQt5.QtGui import QIcon 13 | 14 | from main import Window 15 | # import startphoto 16 | import os 17 | 18 | 19 | class Pushbtn_diy(QtWidgets.QPushButton): 20 | 21 | def enterEvent(self, QEvent): 22 | # # #鼠标进入时触发 23 | self.setStyleSheet("background-color: rgb(31,200,253);border-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));border-radius: 4px;") 24 | 25 | def leaveEvent(self, QEvent): 26 | # #鼠标离开时触发 27 | self.setStyleSheet("background-color: rgb(7,188,252);border-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));border-radius: 4px;") 28 | 29 | 30 | class Ui_Form(object): 31 | 32 | def setupUi(self, Form): 33 | Form.setObjectName("Form") 34 | Form.setFixedSize(600, 350)#设置窗口长宽 35 | # Form.resize(500, 277) 36 | font = QtGui.QFont() 37 | font.setFamily("微软雅黑") 38 | Form.setFont(font) 39 | Form.setStyleSheet("") 40 | #输入框 41 | self.lineEdit = QtWidgets.QLineEdit(Form) 42 | self.lineEdit.setGeometry(QtCore.QRect(130, 210, 300, 40)) 43 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) 44 | sizePolicy.setHorizontalStretch(0) 45 | sizePolicy.setVerticalStretch(0) 46 | sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth()) 47 | self.lineEdit.setSizePolicy(sizePolicy) 48 | font = QtGui.QFont() 49 | font.setFamily("微软雅黑") 50 | self.lineEdit.setFont(font) 51 | self.lineEdit.setText("") 52 | self.lineEdit.setReadOnly(False) 53 | self.lineEdit.setObjectName("lineEdit") 54 | #查找界面按钮 55 | 56 | self.pushButton =Pushbtn_diy(Form) 57 | self.pushButton.setGeometry(QtCore.QRect(440, 210, 61, 40)) 58 | font = QtGui.QFont() 59 | font.setFamily("微软雅黑") 60 | self.pushButton.setFont(font) 61 | self.pushButton.setStyleSheet("background-color: rgb(7,188,252);border-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));border-radius: 4px;") 62 | self.pushButton.setObjectName("pushButton") 63 | #快速锁定财富洼地, 你的价值投资军火库 64 | self.label = QtWidgets.QLabel(Form) 65 | self.label.setGeometry(QtCore.QRect(90, 130, 500, 40)) 66 | 67 | font = QtGui.QFont() 68 | font.setFamily("微软雅黑") 69 | font.setPointSize(12) 70 | self.label.setFont(font) 71 | self.label.setObjectName("label") 72 | 73 | #一眼看懂公司财报 74 | self.label_2 = QtWidgets.QLabel(Form) 75 | self.label_2.setGeometry(QtCore.QRect(150, 80, 400, 43)) 76 | font = QtGui.QFont() 77 | font.setFamily("微软雅黑") 78 | font.setPointSize(18) 79 | font.setBold(True) 80 | font.setWeight(75) 81 | self.label_2.setFont(font) 82 | self.label_2.setObjectName("label_2") 83 | 84 | #查找界面背景 85 | self.graphicsView = QtWidgets.QGraphicsView(Form) 86 | self.graphicsView.setGeometry(QtCore.QRect(0, 0, 600, 350)) 87 | self.graphicsView.setStyleSheet("background-image: url(img/start.png);") 88 | self.graphicsView.setObjectName("graphicsView") 89 | #输入公司名/股票代码 90 | self.label_3 = QtWidgets.QLabel(Form) 91 | self.label_3.setGeometry(QtCore.QRect(133, 219, 200, 20)) 92 | self.label_3.setStyleSheet("color: rgb(202, 202, 202);") 93 | self.label_3.setObjectName("label_3") 94 | #退出按钮 95 | self.pushButton_2 = QtWidgets.QPushButton(Form) 96 | self.pushButton_2.setGeometry(QtCore.QRect(560, 0, 40, 40)) 97 | # self.pushButton_2.setStyleSheet("background-image: url(:/image/exit.png);") 98 | self.pushButton_2.setFlat(True) 99 | self.pushButton_2.setIcon(QIcon("img\close.png")) 100 | self.pushButton_2.setText("") 101 | self.pushButton_2.setObjectName("pushButton_2") 102 | self.pushButton_2.clicked.connect(QCoreApplication.instance().quit) 103 | 104 | 105 | self.pushButton.clicked.connect(self.searchButton) 106 | self.graphicsView.raise_() 107 | self.pushButton.raise_() 108 | self.lineEdit.raise_() 109 | self.lineEdit.textChanged.connect(self.masklabel3) 110 | self.label.raise_() 111 | self.label_2.raise_() 112 | self.label_3.raise_() 113 | self.pushButton_2.raise_() 114 | 115 | self.retranslateUi(Form) 116 | QtCore.QMetaObject.connectSlotsByName(Form) 117 | 118 | 119 | '''查找界面设置模块''' 120 | def retranslateUi(self, Form): 121 | _translate = QtCore.QCoreApplication.translate 122 | Form.setWindowFlags(Qt.FramelessWindowHint) 123 | Form.setWindowTitle(_translate("Form", "小财报")) 124 | self.pushButton.setText(_translate("Form", "搜索")) 125 | self.label.setText(_translate("Form", "快速锁定财富洼地, 你的价值投资军火库")) 126 | self.label_2.setText(_translate("Form", "一眼看懂公司财报")) 127 | self.label_3.setText(_translate("Form", "输入公司名/股票代码")) 128 | 129 | def masklabel3(self,Form): 130 | self.label_3.setText(None) 131 | 132 | def searchButton(self): 133 | global firmname 134 | if(self.lineEdit.text!=""): 135 | firmname=self.lineEdit.text() 136 | # for dir in dirs: 137 | # file_name = dir.split('.') 138 | # file_name=file_name[0].split('_') 139 | # name.append(file_name) 140 | # namebool=False 141 | # for i in range(len(name)): 142 | # if firmname in name[i]: 143 | # name1=name[i][1] 144 | # namebool=True 145 | # if namebool==False: 146 | # name1=name[0][1] 147 | name1=firmname 148 | print(name1) 149 | self.mainpage = QtWidgets.QMainWindow() 150 | self.ui = Window(name1) 151 | self.ui.show() 152 | # self.ui.setupUi(self.mainpage) 153 | 154 | # self.mainpage.show() 155 | 156 | if __name__ == "__main__": 157 | import sys 158 | app = QtWidgets.QApplication(sys.argv) 159 | 160 | Dialog = QtWidgets.QDialog() 161 | 162 | ui=Ui_Form() 163 | ui.setupUi(Dialog) 164 | Dialog.show() 165 | 166 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /数据处理入库.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | import pymongo 5 | from locale import * 6 | # locale.setlocale( locale.LC_ALL, 'en_US.UTF-8' ) 7 | from pymongo.collection import Collection 8 | 9 | def getData(): 10 | # 建立连接 11 | client = pymongo.MongoClient('localhost', 27017) 12 | # 建立数据库 13 | db = client["XinlangFinance"] 14 | 15 | # 从原有的txt文件导入share_id: 16 | 17 | # 表的对象化 18 | mgtable = Collection(db, 'FinanceReport_data') 19 | # print({"SECCODE":str(scode),"year":year}) 20 | data=mgtable.find({},{"_id": 0}) 21 | # print(data[0]) 22 | return data 23 | 24 | if __name__ == '__main__': 25 | gd=getData() 26 | ol=[] 27 | for d in gd: 28 | for n in d: 29 | try: 30 | if n == "SECCODE": 31 | pass 32 | else: 33 | d[n]=float(d[n].replace(",","")) 34 | except: 35 | 36 | pass 37 | # print(d) 38 | ol.append(d) 39 | 40 | try: 41 | # 建立连接 42 | client = pymongo.MongoClient('localhost', 27017) 43 | # 建立数据库 44 | db = client["XinlangFinance"] 45 | 46 | # 从原有的txt文件导入share_id: 47 | 48 | # 表的对象化 49 | mgtable = Collection(db, 'FinanceReport_data2') 50 | 51 | mgtable.insert_many(ol) 52 | 53 | except: 54 | print("写入出错!!") 55 | pass 56 | # print(gd) 57 | -------------------------------------------------------------------------------- /新浪财经数据.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | import requests,json,time 5 | from bs4 import BeautifulSoup 6 | from multiprocessing import Queue 7 | from concurrent.futures import ThreadPoolExecutor 8 | 9 | class Xinalang(): 10 | def __init__(self): 11 | self.queue=Queue() 12 | self.info=[] 13 | self.json=[] 14 | 15 | def req(self,ninfo): 16 | try: 17 | info=json.loads(ninfo) 18 | scode=info["SECCODE"] 19 | year=info["year"] 20 | # print(scode,year) 21 | data_=info 22 | url0='http://money.finance.sina.com.cn/corp/go.php/vFD_BalanceSheet/stockid/{}/ctrl/{}/displaytype/4.phtml'.format(scode,year) 23 | url1='http://money.finance.sina.com.cn/corp/go.php/vFD_ProfitStatement/stockid/{}/ctrl/{}/displaytype/4.phtml'.format(scode,year) 24 | url2='http://money.finance.sina.com.cn/corp/go.php/vFD_CashFlow/stockid/{}/ctrl/{}/displaytype/4.phtml'.format(scode,year) 25 | url_list=[] 26 | url_list.extend([url0,url1,url2]) 27 | data_year=[] 28 | for url in url_list: 29 | headers={} 30 | response=requests.get(url,headers=headers,timeout=5) 31 | soup=BeautifulSoup(response.content.decode("gb2312"),"lxml") 32 | 33 | '''报表日期''' 34 | trs = soup.select("tbody tr") 35 | data={} 36 | for tr in trs: 37 | tds=tr.select("td") 38 | if tds != []: 39 | # print(tds) 40 | try: 41 | value = tds[1].text 42 | if value == "--": 43 | value = "0.00" 44 | data[tds[0].text] = value 45 | except: 46 | pass 47 | 48 | 49 | 50 | data_year.append(data) 51 | 52 | data_["data"]=data_year 53 | print(info["SECNAME"],info["year"]) 54 | self.json.append(json.dumps(data_)) 55 | except TimeoutError: 56 | print("超时") 57 | self.info.append(ninfo) 58 | except: 59 | print("其他错误") 60 | print("其他错误") 61 | info = json.loads(ninfo) 62 | print(info["SECNAME"], info["year"]) 63 | 64 | def scheduler(self): 65 | year_list=[2014,2015,2016,2017,2018] 66 | 67 | with open("D:\python文件库\项目\Financal analysis\A股数据分析\stockCode.txt",encoding="utf8") as f: 68 | lines=f.readlines() 69 | 70 | for line in lines: 71 | info=json.loads(line) 72 | for year in year_list: 73 | info["year"]=year 74 | info_str=json.dumps(info) 75 | # print(json.loads(info_str)) 76 | 77 | self.queue.put(info_str) 78 | 79 | pool=ThreadPoolExecutor(max_workers=8) 80 | while self.queue.qsize()>0: 81 | pool.submit(self.req, self.queue.get()) 82 | pool.shutdown() 83 | 84 | print("剩下:"+str(len(self.info))) 85 | while len(self.info)>0: 86 | 87 | self.req(self.info.pop()) 88 | 89 | self.write_json() 90 | 91 | def write_json(self): 92 | try: 93 | for j in self.json: 94 | with open('data.json', 'a') as f: 95 | json.dump(j, f) 96 | except: 97 | print("写入出错!!") 98 | pass 99 | 100 | 101 | 102 | if __name__ == '__main__': 103 | 104 | 105 | start_time=time.time() 106 | 107 | X = Xinalang() 108 | X.scheduler() 109 | 110 | print("总耗时:{}秒".format(time.time()-start_time)) 111 | 112 | 113 | -------------------------------------------------------------------------------- /新浪财经数据_mg_n12.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | '''最近12个月的财报''' 5 | import requests,json,time,pymongo,time 6 | from bs4 import BeautifulSoup 7 | from fake_useragent import UserAgent 8 | from multiprocessing import Queue 9 | from concurrent.futures import ThreadPoolExecutor 10 | from pymongo.collection import Collection 11 | class Xinalang(): 12 | def __init__(self): 13 | self.queue=Queue() 14 | self.info=[] 15 | self.dict_list=[] 16 | self.usa=UserAgent() 17 | 18 | def req(self,ninfo): 19 | # try: 20 | info=json.loads(ninfo) 21 | scode=info["SECCODE"] 22 | # year=info["year"] 23 | # print(scode,year) 24 | data_=info 25 | url0='http://vip.stock.finance.sina.com.cn/corp/go.php/vFD_BalanceSheet/stockid/{}/ctrl/part/displaytype/4.phtml'.format(scode) 26 | url1='http://vip.stock.finance.sina.com.cn/corp/go.php/vFD_ProfitStatement/stockid/{}/ctrl/part/displaytype/4.phtml'.format(scode) 27 | url2='http://vip.stock.finance.sina.com.cn/corp/go.php/vFD_CashFlow/stockid/{}/ctrl/part/displaytype/4.phtml'.format(scode) 28 | url_list=[] 29 | url_list.extend([url0,url1,url2]) 30 | # data_year=[] 31 | data = {} 32 | for url in url_list: 33 | headers={ 34 | "accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", 35 | "accept-encoding":"gzip,deflate,br", 36 | "accept-language":"zh-CN,zh;q=0.9,en;q=0.8", 37 | "cache-control":"max-age=0", 38 | "upgrade-insecure-requests":"1", 39 | "user-agent":self.usa.random,} 40 | response=requests.get(url,headers=headers)#,headers=headers 41 | # print(response.text) 42 | soup=BeautifulSoup(response.content.decode("GBK"),"lxml") 43 | 44 | '''报表日期''' 45 | trs = soup.select("tbody tr") 46 | 47 | for tr in trs: 48 | tds=tr.select("td") 49 | if tds[1:] != []: 50 | # print(tds) 51 | # try: 52 | value_list=[] 53 | # value = [td.text for td in tds[1:]] 54 | for td in tds[1:]: 55 | td=td.text 56 | # print(td) 57 | 58 | if td == "--": 59 | td = 0.00 60 | 61 | try: 62 | value_list.append(float(td.replace(',',''))) 63 | # data[tds[0].text] = 64 | except: 65 | value_list.append(td) 66 | # data[tds[0].text] = td 67 | data[tds[0].text]=value_list 68 | # except: 69 | # pass 70 | 71 | 72 | # print(data) 73 | # data_year.append(data) 74 | data_.update(data) 75 | # print(data_) 76 | # data_["data"]=data_year 77 | print(info["SECNAME"]) 78 | self.dict_list.append(data_) 79 | # except TimeoutError: 80 | # print("超时") 81 | # self.info.append(ninfo) 82 | # except: 83 | # print("其他错误") 84 | # print("其他错误") 85 | # info = json.loads(ninfo) 86 | # print(info["SECNAME"], info["year"]) 87 | 88 | def scheduler(self): 89 | 90 | with open("D:\python文件库\项目\Financal analysis\A股数据分析\stockCode.txt",encoding="utf8") as f: 91 | lines=f.readlines() 92 | c=-1 93 | for line in lines[2234:]: 94 | 95 | # info=json.loads(line) 96 | # 97 | # info["year"]=year 98 | # info_str=json.dumps(info) 99 | # print(json.loads(info_str)) 100 | self.req(line) 101 | self.write_json() 102 | time.sleep(2) 103 | # self.queue.put(line) 104 | 105 | # pool=ThreadPoolExecutor(max_workers=6) 106 | # while self.queue.qsize()>0: 107 | # pool.submit(self.req, self.queue.get()) 108 | # pool.shutdown() 109 | # 110 | # print("剩下:"+str(len(self.info))) 111 | # while len(self.info)>0: 112 | # 113 | # self.req(self.info.pop()) 114 | 115 | self.write_json() 116 | 117 | def write_json(self): 118 | try: 119 | # 建立连接 120 | client = pymongo.MongoClient('localhost', 27017) 121 | # 建立数据库 122 | db = client["XinlangFinance"] 123 | 124 | # 从原有的txt文件导入share_id: 125 | 126 | # 表的对象化 127 | mgtable = Collection(db, 'FinanceReport_data_n12_06') 128 | 129 | mgtable.insert_many(self.dict_list) 130 | self.dict_list.pop() 131 | 132 | except: 133 | print("写入出错!!") 134 | pass 135 | 136 | 137 | 138 | if __name__ == '__main__': 139 | 140 | 141 | start_time=time.time() 142 | 143 | X = Xinalang() 144 | X.scheduler() 145 | 146 | print("总耗时:{}秒".format(time.time()-start_time)) 147 | 148 | 149 | -------------------------------------------------------------------------------- /新浪财经数据_mg_year.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | '''最近5年的财报''' 5 | import requests,json,time,pymongo 6 | from bs4 import BeautifulSoup 7 | from multiprocessing import Queue 8 | from concurrent.futures import ThreadPoolExecutor 9 | from pymongo.collection import Collection 10 | class Xinalang(): 11 | def __init__(self): 12 | self.queue=Queue() 13 | self.info=[] 14 | self.dict_list=[] 15 | 16 | def req(self,ninfo): 17 | try: 18 | info=json.loads(ninfo) 19 | scode=info["SECCODE"] 20 | year=info["year"] 21 | # print(scode,year) 22 | data_=info 23 | url0='http://money.finance.sina.com.cn/corp/go.php/vFD_BalanceSheet/stockid/{}/ctrl/{}/displaytype/4.phtml'.format(scode,year) 24 | url1='http://money.finance.sina.com.cn/corp/go.php/vFD_ProfitStatement/stockid/{}/ctrl/{}/displaytype/4.phtml'.format(scode,year) 25 | url2='http://money.finance.sina.com.cn/corp/go.php/vFD_CashFlow/stockid/{}/ctrl/{}/displaytype/4.phtml'.format(scode,year) 26 | url_list=[] 27 | url_list.extend([url0,url1,url2]) 28 | # data_year=[] 29 | data = {} 30 | for url in url_list: 31 | headers={} 32 | response=requests.get(url,headers=headers,timeout=5) 33 | soup=BeautifulSoup(response.content.decode("gb2312"),"lxml") 34 | 35 | '''报表日期''' 36 | trs = soup.select("tbody tr") 37 | 38 | for tr in trs: 39 | tds=tr.select("td") 40 | if tds != []: 41 | # print(tds) 42 | try: 43 | value = tds[1].text 44 | if value == "--": 45 | value = 0.00 46 | try: 47 | data[tds[0].text] = float(value) 48 | except: 49 | data[tds[0].text] = value 50 | except: 51 | pass 52 | 53 | 54 | 55 | # data_year.append(data) 56 | data_.update(data) 57 | 58 | # data_["data"]=data_year 59 | print(info["SECNAME"],info["year"]) 60 | self.dict_list.append(data_) 61 | except TimeoutError: 62 | print("超时") 63 | self.info.append(ninfo) 64 | except: 65 | print("其他错误") 66 | print("其他错误") 67 | info = json.loads(ninfo) 68 | print(info["SECNAME"], info["year"]) 69 | 70 | def scheduler(self): 71 | year_list=[2014,2015,2016,2017,2018] 72 | 73 | with open("D:\python文件库\项目\Financal analysis\A股数据分析\stockCode.txt",encoding="utf8") as f: 74 | lines=f.readlines() 75 | 76 | for line in lines: 77 | info=json.loads(line) 78 | for year in year_list: 79 | info["year"]=year 80 | info_str=json.dumps(info) 81 | # print(json.loads(info_str)) 82 | 83 | self.queue.put(info_str) 84 | 85 | pool=ThreadPoolExecutor(max_workers=8) 86 | while self.queue.qsize()>0: 87 | pool.submit(self.req, self.queue.get()) 88 | pool.shutdown() 89 | 90 | print("剩下:"+str(len(self.info))) 91 | while len(self.info)>0: 92 | 93 | self.req(self.info.pop()) 94 | 95 | self.write_json() 96 | 97 | def write_json(self): 98 | try: 99 | # 建立连接 100 | client = pymongo.MongoClient('localhost', 27017) 101 | # 建立数据库 102 | db = client["XinlangFinance"] 103 | 104 | # 从原有的txt文件导入share_id: 105 | 106 | # 表的对象化 107 | mgtable = Collection(db, 'FinanceReport_data') 108 | 109 | mgtable.insert_many(self.dict_list) 110 | 111 | except: 112 | print("写入出错!!") 113 | pass 114 | 115 | 116 | 117 | if __name__ == '__main__': 118 | 119 | 120 | start_time=time.time() 121 | 122 | X = Xinalang() 123 | X.scheduler() 124 | 125 | print("总耗时:{}秒".format(time.time()-start_time)) 126 | 127 | 128 | -------------------------------------------------------------------------------- /新浪财经数据_mg_财务摘要.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | '''最近5年的财报财务摘要''' 5 | import requests,json,time,pymongo,time,re 6 | from bs4 import BeautifulSoup 7 | from fake_useragent import UserAgent 8 | from multiprocessing import Queue 9 | from concurrent.futures import ThreadPoolExecutor 10 | from pymongo.collection import Collection 11 | class Xinalang(): 12 | def __init__(self): 13 | self.queue=Queue() 14 | self.info=[] 15 | self.dict_list=[] 16 | self.usa=UserAgent() 17 | 18 | def req(self,ninfo): 19 | # try: 20 | info=json.loads(ninfo) 21 | scode=info["SECCODE"] 22 | 23 | data_=info 24 | url0='http://vip.stock.finance.sina.com.cn/corp/go.php/vFD_FinanceSummary/stockid/{}.phtml'.format(scode) 25 | url_list=[] 26 | url_list.extend([url0]) 27 | # data = {} 28 | for url in url_list: 29 | headers={ 30 | "accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", 31 | "accept-encoding":"gzip,deflate,br", 32 | "accept-language":"zh-CN,zh;q=0.9,en;q=0.8", 33 | "cache-control":"max-age=0", 34 | "upgrade-insecure-requests":"1", 35 | "user-agent":self.usa.random,} 36 | response=requests.get(url,headers=headers,timeout=5)#,headers=headers 37 | # print(response.text) 38 | html_text=response.content.decode("GBK") 39 | html1=html_text.split("FundHoldSharesTable")[1].split("")[0] 40 | html2=html1.split("") 41 | for h in html2: 42 | li={} 43 | soup=BeautifulSoup(h,"lxml") 44 | 45 | for tr in soup.select("tr"): 46 | try: 47 | key=tr.select("td")[0].text 48 | value=tr.select("td")[1].text 49 | if value =="\xa0": 50 | value=None 51 | elif key =='截止日期': 52 | value=value 53 | else: 54 | value = float(value.replace("元","").replace(",","")) 55 | 56 | li[key]=value 57 | except: 58 | pass 59 | if li != {}: 60 | data_[li["截止日期"]]=li 61 | # print(li) 62 | '''报表日期''' 63 | 64 | # data_.update(data) 65 | 66 | print(info["SECNAME"]) 67 | # print(data_) 68 | self.dict_list.append(data_) 69 | 70 | 71 | def scheduler(self): 72 | 73 | with open("D:\python文件库\项目\Financal analysis\A股数据分析\stockCode.txt",encoding="utf8") as f: 74 | lines=f.readlines() 75 | c=-1 76 | for line in lines[3216:]: 77 | 78 | # info=json.loads(line) 79 | # 80 | # info["year"]=year 81 | # info_str=json.dumps(info) 82 | # print(json.loads(info_str)) 83 | try: 84 | self.req(line) 85 | except: 86 | print("Retry!") 87 | self.req(line) 88 | self.write_json() 89 | time.sleep(1.5) 90 | # self.queue.put(line) 91 | 92 | # pool=ThreadPoolExecutor(max_workers=6) 93 | # while self.queue.qsize()>0: 94 | # pool.submit(self.req, self.queue.get()) 95 | # pool.shutdown() 96 | # 97 | # print("剩下:"+str(len(self.info))) 98 | # while len(self.info)>0: 99 | # 100 | # self.req(self.info.pop()) 101 | 102 | self.write_json() 103 | 104 | def write_json(self): 105 | try: 106 | # 建立连接 107 | client = pymongo.MongoClient('localhost', 27017) 108 | # 建立数据库 109 | db = client["XinlangFinance"] 110 | 111 | # 从原有的txt文件导入share_id: 112 | 113 | # 表的对象化 114 | mgtable = Collection(db, 'FinanceReport_data_cwzy') 115 | 116 | mgtable.insert_many(self.dict_list) 117 | self.dict_list.pop() 118 | 119 | except: 120 | print("写入出错!!") 121 | pass 122 | 123 | 124 | 125 | if __name__ == '__main__': 126 | 127 | 128 | start_time=time.time() 129 | 130 | X = Xinalang() 131 | X.scheduler() 132 | 133 | print("总耗时:{}秒".format(time.time()-start_time)) 134 | 135 | 136 | -------------------------------------------------------------------------------- /说明.md: -------------------------------------------------------------------------------- 1 | #说明: 2 | 1、本程序财务报表数据源来自新浪财经,利用爬虫程序从获取之后入库(我用的数据库是MongoDB) 3 | 2、报表分析模型和算法参考了“财报说”网站,为的是对比效果和纠错。 4 | 3、本程序远计划有三个界面:主分析界面(已完成)、杜邦分析界面(未完成)、财务报告界面(未完成),由于时间关系以及秋招事情多,所以会等有时间再完成后续。 5 | 4、因为是非完全体,所以文件稍微有些混乱。目前没有Mongodb数据的话也无法正常运行。 6 | -------------------------------------------------------------------------------- /财务摘要数据库处理.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | import pymongo 5 | from locale import * 6 | # locale.setlocale( locale.LC_ALL, 'en_US.UTF-8' ) 7 | from pymongo.collection import Collection 8 | 9 | def getData(): 10 | # 建立连接 11 | client = pymongo.MongoClient('localhost', 27017) 12 | # 建立数据库 13 | db = client["XinlangFinance"] 14 | 15 | # 从原有的txt文件导入share_id: 16 | 17 | # 表的对象化 18 | mgtable = Collection(db, 'FinanceReport_data_cwzy') 19 | # print({"SECCODE":str(scode),"year":year}) 20 | data=mgtable.find({},{"_id": 0,"SECNAME" : 1, 21 | "SECCODE" : 1, 22 | "f_kind" : 1, 23 | "s_kind" : 1, 24 | "t_kind" : 1, 25 | "2019-06-30":1, 26 | "2019-03-31": 1, 27 | "2018-12-31": 1, 28 | "2018-09-30": 1, 29 | "2018-06-30":1, 30 | 31 | "2018-03-31":1, 32 | "2017-12-31": 33 | 34 | }) 35 | # print(data[0]) 36 | return data 37 | 38 | if __name__ == '__main__': 39 | gd=getData() 40 | for g in gd: 41 | print(g) -------------------------------------------------------------------------------- /财报分析/原始报表/__pycache__/原始报表.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/财报分析/原始报表/__pycache__/原始报表.cpython-36.pyc -------------------------------------------------------------------------------- /财报分析/原始报表/重要财务指标.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | from 原始报表 import Report_dealer 5 | import numpy as np 6 | 7 | class Report_index: 8 | def __init__(self): 9 | self.scode = input("输入股票代码:") 10 | # self.year = input("输入年份:") 11 | # if self.year=="last": 12 | # self.info=self.getData(self.scode ,self.year ) 13 | # else: 14 | # self.info=self.getData(self.scode ,self.year ) 15 | # self.info0 =self.getData(self.scode, int(self.year) - 1) 16 | self.getData() 17 | '''指数数据如下''' 18 | self.five_index ={} 19 | self.cash_flow_dict={} 20 | self.alr_dict_list={} 21 | 22 | def getData(self): 23 | Rd = Report_dealer(self.scode) 24 | self.info = Rd.scheduler() 25 | 26 | def getData_cwzy(self): 27 | import pymongo 28 | from pymongo.collection import Collection 29 | # 建立连接 30 | client = pymongo.MongoClient('localhost', 27017) 31 | # 建立数据库 32 | db = client["XinlangFinance"] 33 | 34 | # 表的对象化 35 | mgtable = Collection(db, 'FinanceReport_data_cwzy') 36 | # print({"SECCODE":str(scode),"year":year}) 37 | data = mgtable.find({"SECCODE":self.scode}, {"_id": 0}) 38 | # print(data[0]) 39 | return data 40 | 41 | 42 | # 资产负债比率(重要科目) 43 | def asset_liability_ratio(self): 44 | alr_dict_list=[] 45 | info=self.info[0] 46 | 47 | '''资产部分''' 48 | alr_dict={} 49 | # 比率(占总资产%) 50 | cap = np.array(info["资产总计"])#资产总计 51 | # 现金与约当现金(%) 52 | alr_dict["现金与约当现金(%)"]= np.array(info["货币资金"])/cap 53 | # 应收款项( %) 54 | alr_dict["应收款项( %)"] = np.array(info["应收票据及应收账款"])/cap 55 | # 存货( %) 56 | alr_dict["存货( %)"] = np.array(info["存货"])/cap 57 | # 其他流动资产(%) 58 | alr_dict["其他流动资产(%)"] = np.array(info["其他流动资产"])/cap 59 | # 流动资产( %) 60 | alr_dict["流动资产( %)"] = np.array(info["流动资产合计"])/cap 61 | #商誉(%) 62 | alr_dict["商誉(%)"] = np.array(info["商誉"])/ cap 63 | #非流动资产 64 | alr_dict["非流动资产%)"] = np.array(info["非流动资产合计"])/ cap 65 | 66 | '''负债部分''' 67 | alr_dict_1 = {} 68 | #应付账款(%) 69 | alr_dict_1["应付账款(%)"]=np.array(info["应付票据及应付账款"])/cap 70 | # 流动负债(%) 71 | alr_dict_1["流动负债(%)"] = np.array(info["流动负债合计"]) / cap 72 | # 非流动资产(%) 73 | alr_dict_1["非流动资产(%)"] = np.array(info["非流动负债合计"]) / cap 74 | 75 | '''权益部分''' 76 | alr_dict_2 = {} 77 | #股东权益(%) 78 | alr_dict_2["股东权益(%)"]=np.array(info["所有者权益(或股东权益)合计"]) / cap 79 | 80 | # alr_dict_list.append(alr_dict) 81 | # alr_dict_list.append(alr_dict_1) 82 | # alr_dict_list.append(alr_dict_2) 83 | # for o in alr_dict_list: 84 | # print(o) 85 | alr_dict={} 86 | alr_dict["资产部分"]=alr_dict 87 | alr_dict["负债部分"] =alr_dict_1 88 | alr_dict["权益部分"] =alr_dict_2 89 | self.alr_dict_list=alr_dict 90 | 91 | #现金流量表 92 | def cash_flow_st(self): 93 | info=self.info[2] 94 | cash_flow_dict={} 95 | #期初现金 96 | cash_flow_dict["期初现金"]=np.array(info["现金的期初余额"]) 97 | #+ 营业活动现金流量 (from 损益表) 98 | cash_flow_dict["+ 营业活动现金流量 (from 损益表)"] =np.array(info["经营活动产生的现金流量净额"]) 99 | #+ 投资活动现金流量 (from 资产负债表左) 100 | cash_flow_dict["+ 投资活动现金流量 (from 资产负债表左)"] =np.array(info["投资活动产生的现金流量净额"])#投资活动产生的现金流量净额 101 | #+ 融资活动现金流量 (from 资产负债表右) 102 | cash_flow_dict["+ 融资活动现金流量 (from 资产负债表右)"] =np.array(info["筹资活动产生的现金流量净额"])#筹资活动产生的现金流量净额 103 | #期末现金 104 | cash_flow_dict["期末现金"] = np.array(info["六、期末现金及现金等价物余额"]) 105 | #自由现金流(FCF)=经营活动产生的现金流量净额-购建固定资产、无形资产和其他长期资产支付的现金 106 | cash_flow_dict["自由现金流(FCF)"] = np.array(info["经营活动产生的现金流量净额"])-np.array(info["购建固定资产、无形资产和其他长期资产所支付的现金"]) 107 | # print(np.array(info["经营活动产生的现金流量净额"])) 108 | # print(np.array(["购建固定资产、无形资产和其他长期资产所支付的现金"])) 109 | # print(cash_flow_dict) 110 | self.cash_flow_dict=cash_flow_dict 111 | 112 | 113 | # #五大财务比率(+成长能力) 114 | def five_ratio(self): 115 | all_dict = {} 116 | info=self.info 117 | 118 | '''财务结构''' 119 | dict0 = {} 120 | 121 | dict0["资产负债率(%)"] = np.array(info[0]["负债合计"][:-1]) / np.array(info[0]["资产总计"][:-1]) 122 | dict0["权益乘数"] = np.array(info[0]["资产总计"][:-1]) / np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) 123 | dict0["长期资金占重资产比率(%)"] = (np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) + np.array(info[0]["非流动负债合计"][:-1])) / (np.array(info[0]["在建工程"][:-1]) + np.array(info[0]["固定资产净额"][:-1]) + np.array(info[0]["工程物资"][:-1])) # 长期资金占重资产比率(Longterm Ratio) = (股东权益+长期负债)(Total Equity + Non Current Liability) / (固定资产 + 工程物资 + 在建工程)(Fixed Assets + Construction Materials +Construction In Progress) 124 | 125 | '''偿债能力''' 126 | dict1 = {} 127 | dict1["流动比率(%)"] = np.array(info[0]["流动资产合计"][:-1]) / np.array(info[0]["流动负债合计"][:-1]) # 流动比率(Current Ratio) = 流动资产总额(Total Assets) / 流动负债总额(Current Liabilities) 128 | dict1["速动比率(%)"] =( np.array(info[0]["货币资金"][:-1])+np.array(info[0]["应收票据及应收账款"][:-1])+np.array(info[0]["其他应收款"][:-1])+np.array(info[0]["交易性金融资产"][:-1]) )/ np.array(info[0]["流动负债合计"][:-1]) 129 | 130 | '''缺利息费用,暂时用财务费用''' 131 | dict1["利息保障倍数"] = (np.array(info[1]["四、利润总额"][:-1]) - np.array(info[1]["财务费用"][:-1])) / np.array(info[1]["财务费用"][:-1]) # 利息保障倍数(Interest Coverage) = 息税前利润(EBITDA) / 利息费用(Interest Expense) 132 | 133 | '''运营能力''' 134 | dict2 = {} 135 | #平均应收账款 136 | avg_rvb=(( np.array(info[0]["应收账款"][1:])+np.array(info[0]["应收票据"][1:]) + np.array(info[0]["应收账款"][:-1])+ np.array(info[0]["应收票据"][:-1]) ) / 2) 137 | avg_rvb[0]=(info[-1]["应收账款"][0]+info[-1]["应收账款"][-1]+info[-1]["应收票据"][0]+info[-1]["应收票据"][-1])/2 138 | dict2["应收款项周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) /avg_rvb# 应收款项周转率(次/年) = 营业收入/平均应收账款 139 | # print(np.array(info[0]["应收票据及应收账款"][1:]) + np.array(info[0]["应收票据及应收账款"][:-1])) 140 | dict2["应收款项周转天数(天)"] = 365 / dict2["应收款项周转率(次/年)"] 141 | 142 | avg_inv = ((np.array(info[0]["存货"][1:])+ np.array(info[0]["存货"][:-1])) / 2) 143 | avg_inv[0] = (info[-1]["存货"][0] + info[-1]["存货"][-1] ) / 2 144 | dict2["存货周转率(次/年)"] = np.array(info[1]["营业成本"][:-1]) / avg_inv # 营业成本/平均存货 145 | dict2["存货周转天数(天)"] = 365 / dict2["存货周转率(次/年)"] 146 | 147 | avg_fa = ((np.array(info[0]["固定资产净额"][1:]) + np.array(info[0]["固定资产净额"][:-1])) / 2) 148 | avg_fa[0] = (info[-1]["固定资产净额"][0] + info[-1]["固定资产净额"][-1]) / 2 149 | dict2["固定资产周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) / avg_fa 150 | # dict2["完整生意周期(天)"] = 151 | # 销售成本÷平均应付账款 152 | 153 | avg_pbl = ((np.array(info[0]["应付账款"][1:]) + np.array(info[0]["应付票据"][1:]) + np.array(info[0]["应付账款"][:-1]) + np.array(info[0]["应付票据"][:-1])) / 2) 154 | avg_pbl[0] = (info[-1]["应付账款"][0] + info[-1]["应付账款"][-1] + info[-1]["应付票据"][0] + info[-1]["应付票据"][-1]) / 2 155 | dict2["应付款项周转天数(天)"] = avg_pbl*365/np.array(info[1]["营业成本"][:-1]) 156 | 157 | avg_ta = ((np.array(info[0]["资产总计"][1:]) + np.array(info[0]["资产总计"][:-1])) / 2) 158 | avg_ta[0] = (info[-1]["资产总计"][0] + info[-1]["资产总计"][-1]) / 2 159 | dict2["总资产周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) / avg_ta 160 | 161 | '''盈利能力''' 162 | dict3 = {} 163 | 164 | dict3["ROA=资产收益率(%)"] = np.array(info[1]["五、净利润"][:-1]) / avg_ta 165 | # dict3["ROE=净资产收益率(%)"] = np.array(info[1]["五、净利润"][:-1]) / ( 166 | # (np.array(info[0]["所有者权益(或股东权益)合计"][1:]) + np.array(info[0]["所有者权益(或股东权益)合计"][:-1])) / 2) 167 | 168 | dict3["毛利率(%)"] = (np.array(info[1]["营业收入"][:-1]) - np.array(info[1]["营业成本"][:-1])) / np.array(info[1]["营业收入"][:-1]) 169 | dict3["营业利润率(%)"] = np.array(info[1]["三、营业利润"][:-1]) / np.array(info[1]["营业收入"][:-1]) 170 | dict3["净利率(%)"] = np.array(info[1]["五、净利润"][:-1]) / np.array(info[1]["营业收入"][:-1]) 171 | dict3["营业费用率(%)"] = (np.array(info[1]["销售费用"][:1]) + np.array(info[1]["财务费用"][:-1]) + np.array(info[1]["管理费用"][:-1]) )/ np.array(info[1]["营业收入"][:-1]) 172 | dict3["经营安全边际率(%)"] = dict3["营业利润率(%)"]/ dict3["毛利率(%)"] 173 | dict3["EPS=基本每股收益(元)"] =np.array(info[1]["基本每股收益(元/股)"]) 174 | 175 | '''成长能力''' 176 | dict4 = {} 177 | cwzy_info=self.getData_cwzy()[0] 178 | main_income=(cwzy_info[info[0]["报表日期"][0]]["主营业务收入"]-cwzy_info[info[0]["报表日期"][0].replace("2019","2018")]["主营业务收入"])/cwzy_info[info[0]["报表日期"][0].replace("2019","2018")]["主营业务收入"] 179 | main_2018=(cwzy_info["2018-12-31"]["主营业务收入"]-cwzy_info["2017-12-31"]["主营业务收入"])/cwzy_info["2017-12-31"]["主营业务收入"] 180 | main_2017=(cwzy_info["2017-12-31"]["主营业务收入"]-cwzy_info["2016-12-31"]["主营业务收入"])/cwzy_info["2016-12-31"]["主营业务收入"] 181 | main_2016=(cwzy_info["2016-12-31"]["主营业务收入"]-cwzy_info["2015-12-31"]["主营业务收入"])/cwzy_info["2015-12-31"]["主营业务收入"] 182 | main_2015=(cwzy_info["2015-12-31"]["主营业务收入"]-cwzy_info["2014-12-31"]["主营业务收入"])/cwzy_info["2014-12-31"]["主营业务收入"] 183 | main_r=np.array([main_income,main_2018,main_2017,main_2016,main_2015]) 184 | # print(cwzy_info[info[0]["报表日期"][-1]]["主营业务收入"],info[0]["报表日期"]) 185 | dict4["营收增长率(%)"] = main_r 186 | dict4["营业利润增长率(%)"] = (np.array(info[1]["三、营业利润"][:-1]) - np.array(info[1]["三、营业利润"][1:])) / np.array(info[1]["三、营业利润"][1:]) 187 | dict4["净资产增长率(%)"] = (np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) - np.array(info[0]["所有者权益(或股东权益)合计"][1:])) / np.array(info[0]["所有者权益(或股东权益)合计"][1:]) 188 | 189 | '''现金流量''' 190 | dict5 = {} 191 | 192 | dict5["现金流量比率(%)"] = np.array(info[2]["经营活动产生的现金流量净额"][:-1]) / np.array(info[0]["流动负债合计"][:-1]) 193 | # dict5["现金流量允当比率(%)"] = 194 | # dict5["现金再投资比率(%)"] = 195 | avg_na = ((np.array(info[0]["所有者权益(或股东权益)合计"][1:]) + np.array(info[0]["所有者权益(或股东权益)合计"][:-1])) / 2) 196 | avg_na[0] = (info[-1]["所有者权益(或股东权益)合计"][0] + info[-1]["所有者权益(或股东权益)合计"][-1]) / 2 197 | dict3["ROE=净资产收益率(%)"] = dict3["净利率(%)"]*dict2["总资产周转率(次/年)"]*(1/(1-dict0["资产负债率(%)"])) 198 | dict3["ROE=净资产收益率(%)2"] = np.array(info[1]["五、净利润"][:-1])/avg_na 199 | 200 | all_dict["财务结构"] = dict0 201 | all_dict["偿债能力"] = dict1 202 | all_dict["运营能力"] = dict2 203 | all_dict["盈利能力"] = dict3 204 | all_dict["成长能力"] = dict4 205 | all_dict["现金流量"] = dict5 206 | # all_dict.extend([dict0,dict1,dict2,dict3,dict4,dict5]) 207 | # for i in all_dict: 208 | # print(i) 209 | self.five_index=all_dict 210 | 211 | def scheduler(self): 212 | self.asset_liability_ratio() 213 | self.cash_flow_st() 214 | self.five_ratio() 215 | return self.five_index ,self.cash_flow_dict,self.alr_dict_list 216 | 217 | 218 | 219 | if __name__ == '__main__': 220 | Rp=Report_index() 221 | print(Rp.scheduler()[0]) 222 | -------------------------------------------------------------------------------- /财报分析/原始财报处理.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | import pymongo 5 | 6 | from pymongo.collection import Collection 7 | 8 | class Report_dealer: 9 | def __init__(self): 10 | self.scode = input("输入股票代码:") 11 | self.year = input("输入年份:") 12 | if self.year=="last": 13 | self.info=self.getData(self.scode ,self.year ) 14 | else: 15 | self.info=self.getData(self.scode ,self.year ) 16 | self.info0 =self.getData(self.scode, int(self.year) - 1) 17 | 18 | def getData(self,scode,year): 19 | # 建立连接 20 | client = pymongo.MongoClient('localhost', 27017) 21 | # 建立数据库 22 | db = client["XinlangFinance"] 23 | 24 | # 从原有的txt文件导入share_id: 25 | 26 | # 表的对象化 27 | mgtable = Collection(db, 'FinanceReport_data2') 28 | print({"SECCODE":str(scode),"year":year}) 29 | data=mgtable.find({"SECCODE":str(scode),"year":int(year)}) 30 | # print(data[0]) 31 | return data[0] 32 | 33 | #资产负债比率(重要科目) 34 | def asset_liability_ratio(self): 35 | alr_dict_list=[] 36 | 37 | cash=self.info["货币资金"]#货币资金 38 | if self.info['应收票据及应收账款'] == 0: 39 | receivable=(self.info["应收账款"])+(self.info["应收票据"])#应收账款+应收票据 40 | else: 41 | receivable = self.info["应收票据及应收账款"] 42 | # print(receivable) 43 | inventory=self.info["存货"]#存货 44 | # print(inventory) 45 | 46 | otherFA=(self.info["其他流动资产"])#其他流动资产 47 | FA=self.info["流动资产合计"]#流动资产合计 48 | goodwill=self.info["商誉"]#商誉 49 | NFA=self.info["非流动资产合计"]#非流动资产合计 50 | 51 | if self.info['应付票据及应付账款'] == 0: 52 | payable = float(self.info["应付账款"]) + float(self.info["应付票据"]) # 应收账款+应收票据 53 | else: 54 | payable = float(self.info["应付票据及应付账款"]) 55 | 56 | FD=float(self.info["流动负债合计"])#流动负债合计 57 | NFD=self.info["非流动负债合计"]#非流动负债合计 58 | equity=self.info["所有者权益(或股东权益)合计"]#所有者权益(或股东权益)合计 59 | 60 | '''资产''' 61 | alr_dict={"kind":"资产"} 62 | #比率(占总资产%) 63 | Cap=self.info["资产总计"]#资产总计 64 | #现金与约当现金(%) 65 | cashCap=round(cash/Cap*100,1) 66 | alr_dict["现金与约当现金(%)"]=cashCap 67 | 68 | #应收款项( %) 69 | receivableCap=round(receivable/Cap*100,1) 70 | alr_dict["应收款项( %)"] = receivableCap 71 | #存货( %) 72 | inventoryCap=round(inventory/Cap*100,1) 73 | alr_dict["存货( %)"] = inventoryCap 74 | #其他流动资产(%) 75 | otherFACap=round(otherFA/Cap*100,1) 76 | alr_dict["其他流动资产(%)"] = otherFACap 77 | #流动资产( %) 78 | FACap=round(FA/Cap*100,1) 79 | alr_dict["流动资产( %)"] = FACap 80 | #商誉(%) 81 | goodwillCap = round(goodwill/ Cap * 100, 1) 82 | alr_dict["商誉(%)"] = goodwillCap 83 | #非流动资产 84 | NFACap=round(NFA/ Cap * 100, 1) 85 | alr_dict["非流动资产%)"] = NFACap 86 | '''负债''' 87 | alr_dict_1 = {"kind": "负债"} 88 | #应付账款(%) 89 | payableCap=round(payable/Cap * 100, 1) 90 | alr_dict_1["应付账款(%)"]=payableCap 91 | # 流动负债(%) 92 | FDCap = round(FD / Cap * 100, 1) 93 | alr_dict_1["流动负债(%)"] = FDCap 94 | # 非流动资产(%) 95 | NFDCap = round(NFD / Cap * 100, 1) 96 | alr_dict_1["非流动资产(%)"] = NFDCap 97 | '''权益''' 98 | alr_dict_2 = {"kind": "权益"} 99 | #股东权益(%) 100 | equityCap = round(equity / Cap * 100, 1) 101 | alr_dict_2["股东权益(%)"]=equityCap 102 | alr_dict_list.append(alr_dict) 103 | alr_dict_list.append(alr_dict_1) 104 | alr_dict_list.append(alr_dict_2) 105 | for o in alr_dict_list: 106 | print(o) 107 | 108 | #现金流量表 109 | def cash_flow_st(self): 110 | # scode = input("输入股票代码:") 111 | # year = input("输入年份:") 112 | # # 113 | # if year=="n12": 114 | # info=getData(scode,year) 115 | # else: 116 | # info=getData(scode,year) 117 | 118 | cash_flow_dict={} 119 | #期初现金 120 | cash_flow_dict["期初现金"]=float(self.info["加:期初现金及现金等价物余额"]) 121 | #+ 营业活动现金流量 (from 损益表) 122 | cash_flow_dict["+ 营业活动现金流量 (from 损益表)"] =float(self.info["经营活动产生现金流量净额"]) 123 | #+ 投资活动现金流量 (from 资产负债表左) 124 | cash_flow_dict["+ 投资活动现金流量 (from 资产负债表左)"] =float(self.info["投资活动产生的现金流量净额"])#投资活动产生的现金流量净额 125 | #+ 融资活动现金流量 (from 资产负债表右) 126 | cash_flow_dict["+ 融资活动现金流量 (from 资产负债表右)"] =float(self.info["筹资活动产生的现金流量净额"])#筹资活动产生的现金流量净额 127 | #期末现金 128 | cash_flow_dict["期末现金"] =float(self.info["六、期末现金及现金等价物余额"]) 129 | #自由现金流(FCF)=经营活动产生的现金流量净额-购建固定资产、无形资产和其他长期资产支付的现金 130 | cash_flow_dict["自由现金流(FCF)"] =self.info["经营活动产生现金流量净额"]-self.info["购建固定资产、无形资产和其他长期资产所支付的现金"] 131 | print(self.info["经营活动产生现金流量净额"],self.info["购建固定资产、无形资产和其他长期资产所支付的现金"]) 132 | print(cash_flow_dict) 133 | 134 | # #五大财务比率(+成长能力) 135 | def five_ratio(self): 136 | 137 | info=self.info 138 | info0=self.info0 139 | '''财务结构''' 140 | dict0 = {"kind":"财务结构"} 141 | 142 | dict0["资产负债率(%)"]=float(info["负债合计"])/float(info["资产总计"]) 143 | dict0["长期资金占重资产比率(%)"] =(float(info["所有者权益(或股东权益)合计"])+float(info["非流动负债合计"]))/(float(info["在建工程"])+float(info["固定资产净额"])+float(info["工程物资"]))#长期资金占重资产比率(Longterm Ratio) = (股东权益+长期负债)(Total Equity + Non Current Liability) / (固定资产 + 工程物资 + 在建工程)(Fixed Assets + Construction Materials +Construction In Progress) 144 | 145 | '''偿债能力''' 146 | dict1 = {"kind": "财务结构"} 147 | dict1["流动比率(%)"] =float(info["流动资产合计"])/float(info["流动负债合计"])#流动比率(Current Ratio) = 流动资产总额(Total Assets) / 流动负债总额(Current Liabilities) 148 | if info['应收票据及应收账款'] == 0: 149 | receivable=(info["应收账款"])+(info["应收票据"])#应收账款+应收票据 150 | else: 151 | receivable = info["应收票据及应收账款"] 152 | dict1["速动比率(%)"] =(float(info["货币资金"])+float(info["交易性金融资产"])+receivable+float(info["应收利息"])+float(info["应收股利"])+float(info["其他应收款"]))/float(info["流动负债合计"])#速动比率(%) = (货币资金 + 交易性金融资产 + 应收票据及应收账款 + 合同资产 + 应收股利 + 应收利息 + 其他应收款) / 流动负债(Total Liabilities) 153 | 154 | '''缺利息费用,暂时用财务费用''' 155 | dict1["利息保障倍数"] =(float(info["四、利润总额"])-float(info["财务费用"]))/float(info["财务费用"])#利息保障倍数(Interest Coverage) = 息税前利润(EBITDA) / 利息费用(Interest Expense) 156 | 157 | '''运营能力''' 158 | dict2 = {"kind": "财务结构"} 159 | 160 | dict2["应收款项周转率(次/年)"] =float(info["营业收入"])/float((info0["应收账款"]+info["应收账款"])/2)#应收款项周转率(次/年) = 营业收入/平均应收账款 161 | dict2["应收款项周转天数(天)"] =365/(float(info["营业收入"])/float((info0["应收账款"]+info["应收账款"])/2)) 162 | dict2["存货周转率(次/年)"] =float(info["营业收入"])/float((info0["存货"]+info["存货"])/2)#营业成本/平均存货 163 | dict2["存货周转天数(天)"] =365/(float(info["营业收入"])/float((info0["存货"]+info["存货"])/2)) 164 | dict2["固定资产周转率(次/年)"] =float(info["营业收入"])/float((info0["固定资产净额"]+info["固定资产净额"])/2) 165 | # dict2["完整生意周期(天)"] = 166 | #销售成本÷平均应付账款 167 | dict2["应付款项周转天数(天)"] =float(float(info["营业成本"]/(info0["应付账款"]+info["应付账款"])/2)) 168 | # dict2["缺钱天数(天)"] = 169 | dict2["总资产周转率(次/年)"] =float(info["营业收入"])/float((info0["资产总计"]+info["资产总计"])/2) 170 | 171 | '''盈利能力''' 172 | dict3 = {"kind": "财务结构"} 173 | 174 | dict3["ROA=资产收益率(%)"] =float(info["五、净利润"])/float((info0["资产总计"]+info["资产总计"])/2) 175 | dict3["ROE=净资产收益率(%)"] =float(info["五、净利润"])/float((info0["所有者权益(或股东权益)合计"]+info["所有者权益(或股东权益)合计"])/2) 176 | 177 | dict3["毛利率(%)"] =(float(info["营业收入"])-float(info["营业成本"]))/float(info["营业收入"]) 178 | dict3["营业利润率(%)"] =float(info["四、利润总额"])/float(info["营业收入"]) 179 | dict3["净利率(%)"] =float(info["五、净利润"])/float(info["营业收入"]) 180 | dict3["营业费用率(%)"] =float((info["销售费用"])+info["财务费用"]+info["管理费用"])/float(info["营业收入"]) 181 | dict3["经营安全边际率(%)"] =float(info["四、利润总额"])/float(info["营业收入"])/(float(info["营业收入"])-float(info["营业成本"]))/float(info["营业收入"]) 182 | # dict3["EPS=基本每股收益(元)"] = 183 | 184 | '''成长能力''' 185 | dict4 = {"kind": "财务结构"} 186 | 187 | dict4["营收增长率(%)"] =(float(info["营业收入"])-float(info0["营业收入"]))/float(info0["营业收入"]) 188 | dict4["营业利润增长率(%)"] =(float(info["四、利润总额"])-float(info0["四、利润总额"]))/float(info0["四、利润总额"]) 189 | dict4["净资产增长率(%)"] =(float(info["所有者权益(或股东权益)合计"])-float(info0["所有者权益(或股东权益)合计"]))/float(info0["所有者权益(或股东权益)合计"]) 190 | 191 | '''现金流量''' 192 | dict5 = {"kind": "财务结构"} 193 | 194 | dict5["现金流量比率(%)"] =float(info["经营活动产生的现金流量净额"])/float(info["流动负债合计"]) 195 | # dict5["现金流量允当比率(%)"] = 196 | # dict5["现金再投资比率(%)"] = 197 | 198 | 199 | all_dict=[] 200 | all_dict.extend([dict0,dict1,dict2,dict3,dict4,dict5]) 201 | for i in all_dict: 202 | print(i) 203 | 204 | def scheduler(self): 205 | self.asset_liability_ratio() 206 | self.cash_flow_st() 207 | self.five_ratio() 208 | 209 | 210 | if __name__ == '__main__': 211 | Rp=Report_dealer() 212 | Rp.scheduler() 213 | 214 | -------------------------------------------------------------------------------- /财报分析/杜邦分析/__pycache__/impt_index.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/财报分析/杜邦分析/__pycache__/impt_index.cpython-36.pyc -------------------------------------------------------------------------------- /财报分析/杜邦分析/__pycache__/原始报表.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/财报分析/杜邦分析/__pycache__/原始报表.cpython-36.pyc -------------------------------------------------------------------------------- /财报分析/杜邦分析/__pycache__/重要财务指标.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GallenQiu/FinanceReportAnalysis/a4fd1ba364c34829e64d1702fa84f60b9ac3272b/财报分析/杜邦分析/__pycache__/重要财务指标.cpython-36.pyc -------------------------------------------------------------------------------- /财报分析/杜邦分析/impt_index.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | from 原始报表 import Report_dealer 5 | import numpy as np 6 | 7 | class Report_index: 8 | def __init__(self): 9 | self.scode = input("输入股票代码:") 10 | # self.year = input("输入年份:") 11 | # if self.year=="last": 12 | # self.info=self.getData(self.scode ,self.year ) 13 | # else: 14 | # self.info=self.getData(self.scode ,self.year ) 15 | # self.info0 =self.getData(self.scode, int(self.year) - 1) 16 | self.getData() 17 | '''指数数据如下''' 18 | self.five_index ={} 19 | self.cash_flow_dict={} 20 | self.alr_dict_list={} 21 | 22 | def getData(self): 23 | Rd = Report_dealer(self.scode) 24 | self.info = Rd.scheduler() 25 | 26 | 27 | # 资产负债比率(重要科目) 28 | def asset_liability_ratio(self): 29 | alr_dict_list=[] 30 | info=self.info[0] 31 | 32 | '''资产部分''' 33 | alr_dict={} 34 | # 比率(占总资产%) 35 | cap = np.array(info["资产总计"])#资产总计 36 | # 现金与约当现金(%) 37 | alr_dict["现金与约当现金(%)"]= np.array(info["货币资金"])/cap 38 | # 应收款项( %) 39 | alr_dict["应收款项( %)"] = np.array(info["应收票据及应收账款"])/cap 40 | # 存货( %) 41 | alr_dict["存货( %)"] = np.array(info["存货"])/cap 42 | # 其他流动资产(%) 43 | alr_dict["其他流动资产(%)"] = np.array(info["其他流动资产"])/cap 44 | # 流动资产( %) 45 | alr_dict["流动资产( %)"] = np.array(info["流动资产合计"])/cap 46 | #商誉(%) 47 | alr_dict["商誉(%)"] = np.array(info["商誉"])/ cap 48 | #非流动资产 49 | alr_dict["非流动资产%)"] = np.array(info["非流动资产合计"])/ cap 50 | 51 | '''负债部分''' 52 | alr_dict_1 = {} 53 | #应付账款(%) 54 | alr_dict_1["应付账款(%)"]=np.array(info["应付票据及应付账款"])/cap 55 | # 流动负债(%) 56 | alr_dict_1["流动负债(%)"] = np.array(info["流动负债合计"]) / cap 57 | # 非流动资产(%) 58 | alr_dict_1["非流动资产(%)"] = np.array(info["非流动负债合计"]) / cap 59 | 60 | '''权益部分''' 61 | alr_dict_2 = {} 62 | #股东权益(%) 63 | alr_dict_2["股东权益(%)"]=np.array(info["所有者权益(或股东权益)合计"]) / cap 64 | 65 | # alr_dict_list.append(alr_dict) 66 | # alr_dict_list.append(alr_dict_1) 67 | # alr_dict_list.append(alr_dict_2) 68 | # for o in alr_dict_list: 69 | # print(o) 70 | alr_dict={} 71 | alr_dict["资产部分"]=alr_dict 72 | alr_dict["负债部分"] =alr_dict_1 73 | alr_dict["权益部分"] =alr_dict_2 74 | self.alr_dict_list=alr_dict 75 | 76 | #现金流量表 77 | def cash_flow_st(self): 78 | info=self.info[2] 79 | cash_flow_dict={} 80 | #期初现金 81 | cash_flow_dict["期初现金"]=np.array(info["现金的期初余额"]) 82 | #+ 营业活动现金流量 (from 损益表) 83 | cash_flow_dict["+ 营业活动现金流量 (from 损益表)"] =np.array(info["经营活动产生的现金流量净额"]) 84 | #+ 投资活动现金流量 (from 资产负债表左) 85 | cash_flow_dict["+ 投资活动现金流量 (from 资产负债表左)"] =np.array(info["投资活动产生的现金流量净额"])#投资活动产生的现金流量净额 86 | #+ 融资活动现金流量 (from 资产负债表右) 87 | cash_flow_dict["+ 融资活动现金流量 (from 资产负债表右)"] =np.array(info["筹资活动产生的现金流量净额"])#筹资活动产生的现金流量净额 88 | #期末现金 89 | cash_flow_dict["期末现金"] = np.array(info["六、期末现金及现金等价物余额"]) 90 | #自由现金流(FCF)=经营活动产生的现金流量净额-购建固定资产、无形资产和其他长期资产支付的现金 91 | cash_flow_dict["自由现金流(FCF)"] = np.array(info["经营活动产生的现金流量净额"])-np.array(info["购建固定资产、无形资产和其他长期资产所支付的现金"]) 92 | # print(np.array(info["经营活动产生的现金流量净额"])) 93 | # print(np.array(["购建固定资产、无形资产和其他长期资产所支付的现金"])) 94 | # print(cash_flow_dict) 95 | self.cash_flow_dict=cash_flow_dict 96 | 97 | 98 | # #五大财务比率(+成长能力) 99 | def five_ratio(self): 100 | all_dict = {} 101 | info=self.info 102 | # info0=self.info0 103 | 104 | '''财务结构''' 105 | dict0 = {} 106 | 107 | dict0["资产负债率(%)"] = np.array(info[0]["负债合计"][:-1]) / np.array(info[0]["资产总计"][:-1]) 108 | dict0["长期资金占重资产比率(%)"] = (np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) + np.array(info[0]["非流动负债合计"][:-1])) / ( 109 | np.array(info[0]["在建工程"][:-1]) + np.array(info[0]["固定资产净额"][:-1]) + np.array(info[0]["工程物资"][:-1])) # 长期资金占重资产比率(Longterm Ratio) = (股东权益+长期负债)(Total Equity + Non Current Liability) / (固定资产 + 工程物资 + 在建工程)(Fixed Assets + Construction Materials +Construction In Progress) 110 | 111 | '''偿债能力''' 112 | dict1 = {} 113 | dict1["流动比率(%)"] = np.array(info[0]["流动资产合计"][:-1]) / np.array(info[0]["流动负债合计"][:-1]) # 流动比率(Current Ratio) = 流动资产总额(Total Assets) / 流动负债总额(Current Liabilities) 114 | dict1["速动比率(%)"] =( np.array(info[0]["货币资金"][:-1])+np.array(info[0]["应收票据及应收账款"][:-1])+np.array(info[0]["其他应收款"][:-1])+np.array(info[0]["交易性金融资产"][:-1]) )/ np.array(info[0]["流动负债合计"][:-1]) 115 | 116 | '''缺利息费用,暂时用财务费用''' 117 | dict1["利息保障倍数"] = (np.array(info[1]["四、利润总额"][:-1]) - np.array(info[1]["财务费用"][:-1])) / np.array(info[1]["财务费用"][:-1]) # 利息保障倍数(Interest Coverage) = 息税前利润(EBITDA) / 利息费用(Interest Expense) 118 | 119 | '''运营能力''' 120 | dict2 = {} 121 | 122 | dict2["应收款项周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) / ( 123 | np.array(info[0]["应收账款"][1:]) + np.array(info[0]["应收账款"][:-1]) / 2) # 应收款项周转率(次/年) = 营业收入/平均应收账款 124 | 125 | dict2["应收款项周转天数(天)"] = 365 / (np.array(info[1]["营业收入"][:-1]) / (np.array(info[0]["应收账款"][1:]) + np.array(info[0]["应收账款"][:-1]) / 2)) 126 | dict2["存货周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) / (np.array(info[0]["存货"][1:]) + np.array(info[0]["存货"][:-1]) / 2) # 营业成本/平均存货 127 | dict2["存货周转天数(天)"] = 365 / dict2["存货周转率(次/年)"] 128 | dict2["固定资产周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) / (np.array(info[0]["固定资产净额"][1:]) + np.array(info[0]["固定资产净额"][:-1]) / 2) 129 | # dict2["完整生意周期(天)"] = 130 | # 销售成本÷平均应付账款 131 | dict2["应付款项周转天数(天)"] = np.array(info[1]["营业成本"][:-1] / (np.array(info[0]["应付账款"][1:]) + np.array(info[0]["应付账款"][:-1]) / 2)) 132 | # dict2["缺钱天数(天)"] = 133 | dict2["总资产周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) / (np.array(info[0]["资产总计"][1:]) + np.array(info[0]["资产总计"][:-1]) / 2) 134 | 135 | '''盈利能力''' 136 | dict3 = {} 137 | 138 | dict3["ROA=资产收益率(%)"] = np.array(info[1]["五、净利润"][:-1]) / (np.array(info[0]["资产总计"][1:]) + np.array(info[0]["资产总计"][:-1]) / 2) 139 | dict3["ROE=净资产收益率(%)"] = np.array(info[1]["五、净利润"][:-1]) / (np.array(info[0]["所有者权益(或股东权益)合计"][1:]) + np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) / 2) 140 | 141 | dict3["毛利率(%)"] = (np.array(info[1]["营业收入"][:-1]) - np.array(info[1]["营业成本"][:-1])) / np.array(info[1]["营业收入"][:-1]) 142 | dict3["营业利润率(%)"] = np.array(info[1]["四、利润总额"][:-1]) / np.array(info[1]["营业收入"][:-1]) 143 | dict3["净利率(%)"] = np.array(info[1]["五、净利润"][:-1]) / np.array(info[1]["营业收入"][:-1]) 144 | dict3["营业费用率(%)"] = (np.array(info[1]["销售费用"][:1]) + np.array(info[1]["财务费用"][:-1]) + np.array(info[1]["管理费用"][:-1]) )/ np.array(info[1]["营业收入"][:-1]) 145 | dict3["经营安全边际率(%)"] = dict3["营业利润率(%)"]/ dict3["毛利率(%)"] 146 | # dict3["EPS=基本每股收益(元)"] = 147 | 148 | '''成长能力''' 149 | dict4 = {} 150 | 151 | dict4["营收增长率(%)"] = (np.array(info[1]["营业收入"][:-1]) - np.array(info[1]["营业收入"][1:])) / np.array(info[1]["营业收入"][1:]) 152 | dict4["营业利润增长率(%)"] = (np.array(info[1]["四、利润总额"][:-1]) - np.array(info[1]["四、利润总额"][1:])) / np.array(info[1]["四、利润总额"][1:]) 153 | dict4["净资产增长率(%)"] = (np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) - np.array(info[0]["所有者权益(或股东权益)合计"][1:])) / np.array(info[0]["所有者权益(或股东权益)合计"][1:]) 154 | 155 | '''现金流量''' 156 | dict5 = {} 157 | 158 | dict5["现金流量比率(%)"] = np.array(info[2]["经营活动产生的现金流量净额"][:-1]) / np.array(info[0]["流动负债合计"][:-1]) 159 | # dict5["现金流量允当比率(%)"] = 160 | # dict5["现金再投资比率(%)"] = 161 | 162 | all_dict["财务结构"] = dict0 163 | all_dict["偿债能力"] = dict1 164 | all_dict["运营能力"] = dict2 165 | all_dict["盈利能力"] = dict3 166 | all_dict["成长能力"] = dict4 167 | all_dict["现金流量"] = dict5 168 | # all_dict.extend([dict0,dict1,dict2,dict3,dict4,dict5]) 169 | # for i in all_dict: 170 | # print(i) 171 | self.five_index=all_dict 172 | 173 | def scheduler(self): 174 | self.asset_liability_ratio() 175 | self.cash_flow_st() 176 | self.five_ratio() 177 | return self.five_index ,self.cash_flow_dict,self.alr_dict_list 178 | 179 | 180 | 181 | if __name__ == '__main__': 182 | Rp=Report_index() 183 | Rp.scheduler() 184 | -------------------------------------------------------------------------------- /财报分析/杜邦分析/杜邦分析.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | 5 | from 重要财务指标 import Report_index 6 | 7 | 8 | class Dupont: 9 | def __init__(self): 10 | self.info={} 11 | self.get_data() 12 | 13 | self.index={} 14 | 15 | 16 | def get_data(self): 17 | Ri=Report_index() 18 | self.info=Ri.scheduler()[0] 19 | 20 | 21 | def index_(self): 22 | index={} 23 | index["ROE"]=self.info["盈利能力"]["ROE=净资产收益率(%)"] 24 | 25 | index["权益乘数"]=1/(1-self.info["财务结构"]["资产负债率(%)"]) 26 | index["资产周转率"] =self.info["运营能力"]["总资产周转率(次/年)"] 27 | index["净利率"] =self.info["盈利能力"]["净利率(%)"] 28 | 29 | '''财务能力''' 30 | index["负债比率"] =self.info["财务结构"]["资产负债率(%)"] 31 | index["流动比"] =self.info["偿债能力"]["流动比率(%)"] 32 | index["速动比"] =self.info["偿债能力"]["速动比率(%)"] 33 | index["利息保障倍数"] =self.info["偿债能力"]["利息保障倍数"] 34 | 35 | '''运营能力''' 36 | # index["流动资产比率"] = 37 | # index["非流动资产比率"] = 38 | index["存货周转率"] =self.info["运营能力"]["存货周转率(次/年)"] 39 | index["存货在库天数"] =self.info["运营能力"]["存货周转天数(天)"] 40 | index["应收帐款周转率"] =self.info["运营能力"]["应收款项周转率(次/年)"] 41 | index["应收款项周转天数"] =self.info["运营能力"]["应收款项周转天数(天)"] 42 | 43 | '''盈利能力''' 44 | index["毛利率"] =self.info["盈利能力"]["毛利率(%)"] 45 | index["营业利润率"] =self.info["盈利能力"]["营业利润率(%)"] 46 | # print(index) 47 | self.index=index 48 | 49 | def analysis(self): 50 | '''净利率 x 总资产周转率 x 杠杆倍数 = ROE ''' 51 | netIncomeE=(self.index["净利率"][0]*self.index["资产周转率"][-1]*self.index["权益乘数"][-1])-(self.index["净利率"][-1]*self.index["资产周转率"][-1]*self.index["权益乘数"][-1]) 52 | tofTotalE=(self.index["净利率"][0]*self.index["资产周转率"][0]*self.index["权益乘数"][-1])-(self.index["净利率"][0]*self.index["资产周转率"][-1]*self.index["权益乘数"][-1]) 53 | leverageE=(self.index["净利率"][0]*self.index["资产周转率"][0]*self.index["权益乘数"][0])-(self.index["净利率"][0]*self.index["资产周转率"][0]*self.index["权益乘数"][-1]) 54 | region=(self.index["净利率"][-1] * self.index["资产周转率"][-1] * self.index["权益乘数"][-1]) 55 | now=(self.index["净利率"][0]*self.index["资产周转率"][0]*self.index["权益乘数"][0]) 56 | if now-region >=0: 57 | print("正增长:2015 ~ 2019 年的 ROE 从 {}% 改变至 {}%".format(round(region*100,2),round(now*100,2))) 58 | if netIncomeE == max(netIncomeE, tofTotalE, leverageE): 59 | print("净利率") 60 | gpr = (self.index["毛利率"][0] - self.index["毛利率"][-1]) / self.index["毛利率"][-1] 61 | oppr = (self.index["营业利润率"][0] - self.index["营业利润率"][-1]) / self.index["营业利润率"][-1] 62 | if gpr == max(gpr, oppr): 63 | print("主要原因为【毛利率】的改变。 毛利率变化 {}%".format(round(gpr * 100, 2))) 64 | else: 65 | print("主要原因为【营业利润率】的改变。 营业利润率变化 {}%".format(round(oppr * 100, 2))) 66 | elif tofTotalE == max(netIncomeE, tofTotalE, leverageE): 67 | print("总资产周转率") 68 | # self.index["存货周转率"] 69 | 70 | invDay = (self.index["存货在库天数"][0] - self.index["存货在库天数"][-1]) / self.index["存货在库天数"][-1] 71 | 72 | # self.index["应收帐款周转率"] 73 | rbleDay = (self.index["应收款项周转天数"][0] - self.index["应收款项周转天数"][-1]) / self.index["应收款项周转天数"][-1] 74 | # self.index["应收款项周转天数"] 75 | if invDay == max(invDay, rbleDay): 76 | print("主要原因为【存货周转率】的改变。 存货在库天数从 {} 天 变为 {} 天".format(self.index["存货在库天数"][-1], 77 | self.index["存货在库天数"][0])) 78 | else: 79 | print("主要原因为【应收账款周转率】的改变。 应收款项周转天数从 {} 天 变为 {} 天".format(self.index["应收款项周转天数"][-1], 80 | self.index["应收款项周转天数"][0])) 81 | 82 | else: 83 | print("杠杆倍数") 84 | else: 85 | print("负增长:2015 ~ 2019 年的 ROE 从 {}% 改变至 {}%".format(round(region*100,2),round(now*100,2))) 86 | if netIncomeE == min(netIncomeE, tofTotalE, leverageE): 87 | print("净利率") 88 | gpr = (self.index["毛利率"][0] - self.index["毛利率"][-1]) / self.index["毛利率"][-1] 89 | oppr = (self.index["营业利润率"][0] - self.index["营业利润率"][-1]) / self.index["营业利润率"][-1] 90 | if gpr == min(gpr, oppr): 91 | print("主要原因为【毛利率】的改变。 毛利率变化 {%}".format(round(gpr * 100, 2))) 92 | else: 93 | print("主要原因为【营业利润率】的改变。 营业利润率变化 {}%".format(round(oppr * 100, 2))) 94 | elif tofTotalE == min(netIncomeE, tofTotalE, leverageE): 95 | print("总资产周转率") 96 | # self.index["存货周转率"] 97 | 98 | invDay = (self.index["存货在库天数"][0] - self.index["存货在库天数"][-1]) / self.index["存货在库天数"][-1] 99 | 100 | # self.index["应收帐款周转率"] 101 | rbleDay = (self.index["应收款项周转天数"][0] - self.index["应收款项周转天数"][-1]) / self.index["应收款项周转天数"][-1] 102 | # self.index["应收款项周转天数"] 103 | if invDay == min(invDay, rbleDay): 104 | print("主要原因为【存货周转率】的改变。 存货在库天数从 {} 天 变为 {} 天".format(self.index["存货在库天数"][-1], 105 | self.index["存货在库天数"][0])) 106 | else: 107 | print("主要原因为【应收账款周转率】的改变。 应收款项周转天数从 {} 天 变为 {} 天".format(self.index["应收款项周转天数"][-1], 108 | self.index["应收款项周转天数"][0])) 109 | 110 | else: 111 | print("杠杆倍数") 112 | 113 | 114 | 115 | 116 | if __name__ == '__main__': 117 | Dp=Dupont() 118 | Dp.index_() 119 | Dp.analysis() 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /财报分析/杜邦分析/重要财务指标.py: -------------------------------------------------------------------------------- 1 | # -*- coding : utf-8 -*- # 2 | 3 | __author__ = "Gallen_qiu" 4 | from 原始报表 import Report_dealer 5 | import numpy as np 6 | 7 | class Report_index: 8 | def __init__(self): 9 | self.scode = input("输入股票代码:") 10 | # self.year = input("输入年份:") 11 | # if self.year=="last": 12 | # self.info=self.getData(self.scode ,self.year ) 13 | # else: 14 | # self.info=self.getData(self.scode ,self.year ) 15 | # self.info0 =self.getData(self.scode, int(self.year) - 1) 16 | self.getData() 17 | '''指数数据如下''' 18 | self.five_index ={} 19 | self.cash_flow_dict={} 20 | self.alr_dict_list={} 21 | 22 | def getData(self): 23 | Rd = Report_dealer(self.scode) 24 | self.info = Rd.scheduler() 25 | 26 | 27 | # 资产负债比率(重要科目) 28 | def asset_liability_ratio(self): 29 | alr_dict_list=[] 30 | info=self.info[0] 31 | 32 | '''资产部分''' 33 | alr_dict={} 34 | # 比率(占总资产%) 35 | cap = np.array(info["资产总计"])#资产总计 36 | # 现金与约当现金(%) 37 | alr_dict["现金与约当现金(%)"]= np.array(info["货币资金"])/cap 38 | # 应收款项( %) 39 | alr_dict["应收款项( %)"] = np.array(info["应收票据及应收账款"])/cap 40 | # 存货( %) 41 | alr_dict["存货( %)"] = np.array(info["存货"])/cap 42 | # 其他流动资产(%) 43 | alr_dict["其他流动资产(%)"] = np.array(info["其他流动资产"])/cap 44 | # 流动资产( %) 45 | alr_dict["流动资产( %)"] = np.array(info["流动资产合计"])/cap 46 | #商誉(%) 47 | alr_dict["商誉(%)"] = np.array(info["商誉"])/ cap 48 | #非流动资产 49 | alr_dict["非流动资产%)"] = np.array(info["非流动资产合计"])/ cap 50 | 51 | '''负债部分''' 52 | alr_dict_1 = {} 53 | #应付账款(%) 54 | alr_dict_1["应付账款(%)"]=np.array(info["应付票据及应付账款"])/cap 55 | # 流动负债(%) 56 | alr_dict_1["流动负债(%)"] = np.array(info["流动负债合计"]) / cap 57 | # 非流动资产(%) 58 | alr_dict_1["非流动资产(%)"] = np.array(info["非流动负债合计"]) / cap 59 | 60 | '''权益部分''' 61 | alr_dict_2 = {} 62 | #股东权益(%) 63 | alr_dict_2["股东权益(%)"]=np.array(info["所有者权益(或股东权益)合计"]) / cap 64 | 65 | # alr_dict_list.append(alr_dict) 66 | # alr_dict_list.append(alr_dict_1) 67 | # alr_dict_list.append(alr_dict_2) 68 | # for o in alr_dict_list: 69 | # print(o) 70 | alr_dict={} 71 | alr_dict["资产部分"]=alr_dict 72 | alr_dict["负债部分"] =alr_dict_1 73 | alr_dict["权益部分"] =alr_dict_2 74 | self.alr_dict_list=alr_dict 75 | 76 | #现金流量表 77 | def cash_flow_st(self): 78 | info=self.info[2] 79 | cash_flow_dict={} 80 | #期初现金 81 | cash_flow_dict["期初现金"]=np.array(info["现金的期初余额"]) 82 | #+ 营业活动现金流量 (from 损益表) 83 | cash_flow_dict["+ 营业活动现金流量 (from 损益表)"] =np.array(info["经营活动产生的现金流量净额"]) 84 | #+ 投资活动现金流量 (from 资产负债表左) 85 | cash_flow_dict["+ 投资活动现金流量 (from 资产负债表左)"] =np.array(info["投资活动产生的现金流量净额"])#投资活动产生的现金流量净额 86 | #+ 融资活动现金流量 (from 资产负债表右) 87 | cash_flow_dict["+ 融资活动现金流量 (from 资产负债表右)"] =np.array(info["筹资活动产生的现金流量净额"])#筹资活动产生的现金流量净额 88 | #期末现金 89 | cash_flow_dict["期末现金"] = np.array(info["六、期末现金及现金等价物余额"]) 90 | #自由现金流(FCF)=经营活动产生的现金流量净额-购建固定资产、无形资产和其他长期资产支付的现金 91 | cash_flow_dict["自由现金流(FCF)"] = np.array(info["经营活动产生的现金流量净额"])-np.array(info["购建固定资产、无形资产和其他长期资产所支付的现金"]) 92 | # print(np.array(info["经营活动产生的现金流量净额"])) 93 | # print(np.array(["购建固定资产、无形资产和其他长期资产所支付的现金"])) 94 | # print(cash_flow_dict) 95 | self.cash_flow_dict=cash_flow_dict 96 | 97 | 98 | # #五大财务比率(+成长能力) 99 | def five_ratio(self): 100 | all_dict = {} 101 | info=self.info 102 | 103 | '''财务结构''' 104 | dict0 = {} 105 | 106 | dict0["资产负债率(%)"] = np.array(info[0]["负债合计"][:-1]) / np.array(info[0]["资产总计"][:-1]) 107 | dict0["权益乘数"] = np.array(info[0]["资产总计"][:-1]) / np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) 108 | dict0["长期资金占重资产比率(%)"] = (np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) + np.array(info[0]["非流动负债合计"][:-1])) / (np.array(info[0]["在建工程"][:-1]) + np.array(info[0]["固定资产净额"][:-1]) + np.array(info[0]["工程物资"][:-1])) # 长期资金占重资产比率(Longterm Ratio) = (股东权益+长期负债)(Total Equity + Non Current Liability) / (固定资产 + 工程物资 + 在建工程)(Fixed Assets + Construction Materials +Construction In Progress) 109 | 110 | '''偿债能力''' 111 | dict1 = {} 112 | dict1["流动比率(%)"] = np.array(info[0]["流动资产合计"][:-1]) / np.array(info[0]["流动负债合计"][:-1]) # 流动比率(Current Ratio) = 流动资产总额(Total Assets) / 流动负债总额(Current Liabilities) 113 | dict1["速动比率(%)"] =( np.array(info[0]["货币资金"][:-1])+np.array(info[0]["应收票据及应收账款"][:-1])+np.array(info[0]["其他应收款"][:-1])+np.array(info[0]["交易性金融资产"][:-1]) )/ np.array(info[0]["流动负债合计"][:-1]) 114 | 115 | '''缺利息费用,暂时用财务费用''' 116 | dict1["利息保障倍数"] = (np.array(info[1]["四、利润总额"][:-1]) - np.array(info[1]["财务费用"][:-1])) / np.array(info[1]["财务费用"][:-1]) # 利息保障倍数(Interest Coverage) = 息税前利润(EBITDA) / 利息费用(Interest Expense) 117 | 118 | '''运营能力''' 119 | dict2 = {} 120 | #平均应收账款 121 | avg_rvb=(( np.array(info[0]["应收账款"][1:])+np.array(info[0]["应收票据"][1:]) + np.array(info[0]["应收账款"][:-1])+ np.array(info[0]["应收票据"][:-1]) ) / 2) 122 | avg_rvb[0]=(info[-1]["应收账款"][0]+info[-1]["应收账款"][-1]+info[-1]["应收票据"][0]+info[-1]["应收票据"][-1])/2 123 | dict2["应收款项周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) /avg_rvb# 应收款项周转率(次/年) = 营业收入/平均应收账款 124 | # print(np.array(info[0]["应收票据及应收账款"][1:]) + np.array(info[0]["应收票据及应收账款"][:-1])) 125 | dict2["应收款项周转天数(天)"] = 365 / dict2["应收款项周转率(次/年)"] 126 | 127 | avg_inv = ((np.array(info[0]["存货"][1:])+ np.array(info[0]["存货"][:-1])) / 2) 128 | avg_inv[0] = (info[-1]["存货"][0] + info[-1]["存货"][-1] ) / 2 129 | dict2["存货周转率(次/年)"] = np.array(info[1]["营业成本"][:-1]) / avg_inv # 营业成本/平均存货 130 | dict2["存货周转天数(天)"] = 365 / dict2["存货周转率(次/年)"] 131 | 132 | avg_fa = ((np.array(info[0]["固定资产净额"][1:]) + np.array(info[0]["固定资产净额"][:-1])) / 2) 133 | avg_fa[0] = (info[-1]["固定资产净额"][0] + info[-1]["固定资产净额"][-1]) / 2 134 | dict2["固定资产周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) / avg_fa 135 | # dict2["完整生意周期(天)"] = 136 | # 销售成本÷平均应付账款 137 | 138 | avg_pbl = ((np.array(info[0]["应付账款"][1:]) + np.array(info[0]["应付票据"][1:]) + np.array(info[0]["应付账款"][:-1]) + np.array(info[0]["应付票据"][:-1])) / 2) 139 | avg_pbl[0] = (info[-1]["应付账款"][0] + info[-1]["应付账款"][-1] + info[-1]["应付票据"][0] + info[-1]["应付票据"][-1]) / 2 140 | dict2["应付款项周转天数(天)"] = avg_pbl*365/np.array(info[1]["营业成本"][:-1]) 141 | 142 | avg_ta = ((np.array(info[0]["资产总计"][1:]) + np.array(info[0]["资产总计"][:-1])) / 2) 143 | avg_ta[0] = (info[-1]["资产总计"][0] + info[-1]["资产总计"][-1]) / 2 144 | dict2["总资产周转率(次/年)"] = np.array(info[1]["营业收入"][:-1]) / avg_ta 145 | 146 | '''盈利能力''' 147 | dict3 = {} 148 | 149 | dict3["ROA=资产收益率(%)"] = np.array(info[1]["五、净利润"][:-1]) / avg_ta 150 | # dict3["ROE=净资产收益率(%)"] = np.array(info[1]["五、净利润"][:-1]) / ( 151 | # (np.array(info[0]["所有者权益(或股东权益)合计"][1:]) + np.array(info[0]["所有者权益(或股东权益)合计"][:-1])) / 2) 152 | 153 | dict3["毛利率(%)"] = (np.array(info[1]["营业收入"][:-1]) - np.array(info[1]["营业成本"][:-1])) / np.array(info[1]["营业收入"][:-1]) 154 | dict3["营业利润率(%)"] = np.array(info[1]["四、利润总额"][:-1]) / np.array(info[1]["营业收入"][:-1]) 155 | dict3["净利率(%)"] = np.array(info[1]["五、净利润"][:-1]) / np.array(info[1]["营业收入"][:-1]) 156 | dict3["营业费用率(%)"] = (np.array(info[1]["销售费用"][:1]) + np.array(info[1]["财务费用"][:-1]) + np.array(info[1]["管理费用"][:-1]) )/ np.array(info[1]["营业收入"][:-1]) 157 | dict3["经营安全边际率(%)"] = dict3["营业利润率(%)"]/ dict3["毛利率(%)"] 158 | dict3["EPS=基本每股收益(元)"] =np.array(info[1]["基本每股收益(元/股)"]) 159 | 160 | '''成长能力''' 161 | dict4 = {} 162 | 163 | dict4["营收增长率(%)"] = (np.array(info[1]["营业收入"][:-1]) - np.array(info[1]["营业收入"][1:])) / np.array(info[1]["营业收入"][1:]) 164 | dict4["营业利润增长率(%)"] = (np.array(info[1]["四、利润总额"][:-1]) - np.array(info[1]["四、利润总额"][1:])) / np.array(info[1]["四、利润总额"][1:]) 165 | dict4["净资产增长率(%)"] = (np.array(info[0]["所有者权益(或股东权益)合计"][:-1]) - np.array(info[0]["所有者权益(或股东权益)合计"][1:])) / np.array(info[0]["所有者权益(或股东权益)合计"][1:]) 166 | 167 | '''现金流量''' 168 | dict5 = {} 169 | 170 | dict5["现金流量比率(%)"] = np.array(info[2]["经营活动产生的现金流量净额"][:-1]) / np.array(info[0]["流动负债合计"][:-1]) 171 | # dict5["现金流量允当比率(%)"] = 172 | # dict5["现金再投资比率(%)"] = 173 | avg_na = ((np.array(info[0]["所有者权益(或股东权益)合计"][1:]) + np.array(info[0]["所有者权益(或股东权益)合计"][:-1])) / 2) 174 | avg_na[0] = (info[-1]["所有者权益(或股东权益)合计"][0] + info[-1]["所有者权益(或股东权益)合计"][-1]) / 2 175 | dict3["ROE=净资产收益率(%)"] = dict3["净利率(%)"]*dict2["总资产周转率(次/年)"]*(1/(1-dict0["资产负债率(%)"])) 176 | dict3["ROE=净资产收益率(%)2"] = np.array(info[1]["五、净利润"][:-1])/avg_na 177 | 178 | all_dict["财务结构"] = dict0 179 | all_dict["偿债能力"] = dict1 180 | all_dict["运营能力"] = dict2 181 | all_dict["盈利能力"] = dict3 182 | all_dict["成长能力"] = dict4 183 | all_dict["现金流量"] = dict5 184 | # all_dict.extend([dict0,dict1,dict2,dict3,dict4,dict5]) 185 | # for i in all_dict: 186 | # print(i) 187 | self.five_index=all_dict 188 | 189 | def scheduler(self): 190 | self.asset_liability_ratio() 191 | self.cash_flow_st() 192 | self.five_ratio() 193 | return self.five_index ,self.cash_flow_dict,self.alr_dict_list 194 | 195 | 196 | 197 | if __name__ == '__main__': 198 | Rp=Report_index() 199 | print(Rp.scheduler()[0]) 200 | --------------------------------------------------------------------------------