|
8 | 8 | "\n",
|
9 | 9 | "In this notebook, we load and analyze key financial metrics for several major German companies.\n",
|
10 | 10 | "We perform data transformations, compute statistical measures, group by business sector, and create various plots to visualize trends in\n",
|
11 |
| - "revenue, net income, return on assets (ROA), and return on equity (ROE)" |
| 11 | + "revenue, net income, return on assets (roa), and return on equity (roe)" |
12 | 12 | ]
|
13 | 13 | },
|
14 | 14 | {
|
|
49 | 49 | "source": [
|
50 | 50 | "// Read data from a CSV file into a DataFrame\n",
|
51 | 51 | "val dataFrame = DataFrame.read(\"top_12_german_companies.csv\")\n",
|
52 |
| - " .renameToCamelCase().rename(\"rOA(%)\", \"rOE(%)\").into(\"ROA\", \"ROE\")" |
| 52 | + " .renameToCamelCase()" |
53 | 53 | ],
|
54 | 54 | "outputs": [
|
55 | 55 | {
|
|
198 | 198 | "val companiesDf = dataFrame\n",
|
199 | 199 | " .convert { period }.with { LocalDate.parse(it, format) }\n",
|
200 | 200 | " .convert { percentageDebtToEquity }.with { it.removeSuffix(\"%\").replace(',', '.').toDouble() }\n",
|
201 |
| - " .convert { ROA and ROE }.with { it.replace(\".\", \"\").toDouble() }\n", |
| 201 | + " .convert { roa and roe }.with { it.replace(\".\", \"\").toDouble() }\n", |
202 | 202 | " .sortBy { company and period }\n",
|
203 | 203 | " .add(\"sector\") {\n",
|
204 | 204 | " when (company) {\n",
|
|
230 | 230 | "cell_type": "code",
|
231 | 231 | "source": [
|
232 | 232 | "companiesDf.groupBy { company }.aggregate {\n",
|
233 |
| - " val financeColumns = it.select { revenue and netIncome and liabilities and assets and equity and ROA and ROE and debtToEquity and percentageDebtToEquity }\n", |
| 233 | + " val financeColumns = it.select { revenue and netIncome and liabilities and assets and equity and roa and roe and debtToEquity and percentageDebtToEquity }\n", |
234 | 234 | " financeColumns.mean() into \"mean\"\n",
|
235 | 235 | " financeColumns.median() into \"median\"\n",
|
236 | 236 | " financeColumns.std() into \"std\"\n",
|
|
247 | 247 | "source": [
|
248 | 248 | "// Group by \"company\" and aggregate key financial columns\n",
|
249 | 249 | "companiesDf.groupBy { sector }.aggregate {\n",
|
250 |
| - " val financeColumns = it.select { revenue and netIncome and liabilities and assets and equity and ROA and ROE and debtToEquity and percentageDebtToEquity }\n", |
| 250 | + " val financeColumns = it.select { revenue and netIncome and liabilities and assets and equity and roa and roe and debtToEquity and percentageDebtToEquity }\n", |
251 | 251 | " financeColumns.mean() into \"mean\"\n",
|
252 | 252 | " financeColumns.median() into \"median\"\n",
|
253 | 253 | " financeColumns.std() into \"std\"\n",
|
|
267 | 267 | " revenue.sum() into \"Total revenue\"\n",
|
268 | 268 | " netIncome.mean() into \"Avg Net Income\"\n",
|
269 | 269 | " netIncome.sum() into \"Sum Net Income\"\n",
|
270 |
| - " ROA.mean() into \"Avg ROA\"\n", |
271 |
| - " ROE.mean() into \"Avg ROE\"\n", |
| 270 | + " roa.mean() into \"Avg roa\"\n", |
| 271 | + " roe.mean() into \"Avg roe\"\n", |
272 | 272 | "}.sortBy { sector }"
|
273 | 273 | ],
|
274 | 274 | "outputs": [],
|
|
428 | 428 | "metadata": {},
|
429 | 429 | "cell_type": "markdown",
|
430 | 430 | "source": [
|
431 |
| - "## ROA and ROE Analysis by Sector\n", |
| 431 | + "## roa and roe Analysis by Sector\n", |
432 | 432 | "\n",
|
433 | 433 | "1. Computing Averages and Standard Deviations:\n",
|
434 |
| - " - Group the data by sector and calculate the mean and standard deviation for Return on Assets (ROA) and Return on Equity (ROE).\n", |
| 434 | + " - Group the data by sector and calculate the mean and standard deviation for Return on Assets (roa) and Return on Equity (roe).\n", |
435 | 435 | " - This creates a summarized dataset for sector-level performance comparison.\n",
|
436 |
| - "2. Visualizing ROA by Sector:\n", |
437 |
| - " - A bar chart displays the average ROA for each sector.\n", |
| 436 | + "2. Visualizing roa by Sector:\n", |
| 437 | + " - A bar chart displays the average roa for each sector.\n", |
438 | 438 | " - Error bars represent one standard deviation, showing the variability within each sector.\n",
|
439 |
| - "3. Visualizing ROE by Sector:\n", |
440 |
| - " - A similar bar chart illustrates the average ROE across sectors.\n", |
441 |
| - " - Error bars provide insight into the standard deviation of ROE within each sector.\n", |
| 439 | + "3. Visualizing roe by Sector:\n", |
| 440 | + " - A similar bar chart illustrates the average roe across sectors.\n", |
| 441 | + " - Error bars provide insight into the standard deviation of roe within each sector.\n", |
442 | 442 | "\n",
|
443 | 443 | "These charts help compare sector-level profitability metrics and assess consistency within sectors."
|
444 | 444 | ]
|
|
447 | 447 | "metadata": {},
|
448 | 448 | "cell_type": "code",
|
449 | 449 | "source": [
|
450 |
| - "// Group data by sector to compute average and standard deviations of ROA and ROE\n", |
| 450 | + "// Group data by sector to compute average and standard deviations of roa and roe\n", |
451 | 451 | "val roeAndRoaDf = companiesDf.groupBy { sector }.aggregate {\n",
|
452 |
| - " ROA.mean() into \"Avg ROA\"\n", |
453 |
| - " ROA.std() into \"Std ROA\"\n", |
454 |
| - " ROE.mean() into \"Avg ROE\"\n", |
455 |
| - " ROE.std() into \"Std ROE\"\n", |
| 452 | + " roa.mean() into \"Avg roa\"\n", |
| 453 | + " roa.std() into \"Std roa\"\n", |
| 454 | + " roe.mean() into \"Avg roe\"\n", |
| 455 | + " roe.std() into \"Std roe\"\n", |
456 | 456 | "}\n",
|
457 | 457 | "\n",
|
458 | 458 | "roeAndRoaDf"
|
|
464 | 464 | "metadata": {},
|
465 | 465 | "cell_type": "code",
|
466 | 466 | "source": [
|
467 |
| - "// Plot average ROA by sector with error bars representing one standard deviation\n", |
| 467 | + "// Plot average roa by sector with error bars representing one standard deviation\n", |
468 | 468 | "roeAndRoaDf.plot {\n",
|
469 | 469 | " // Set the x-axis to the sector names\n",
|
470 | 470 | " x(sector.map { it.simpleName }) { axis.name = \"Sector of Business\" }\n",
|
471 | 471 | "\n",
|
472 | 472 | " bars {\n",
|
473 |
| - " // Use the \"Avg ROA\" column for the bar heights\n", |
474 |
| - " y(`Avg ROA`) { scale = continuous(min = .0, max = 4.5e+9) }\n", |
| 473 | + " // Use the \"Avg roa\" column for the bar heights\n", |
| 474 | + " y(`Avg roa`) { scale = continuous(min = .0, max = 4.5e+9) }\n", |
475 | 475 | " // Fill bars with a chosen color\n",
|
476 | 476 | " fillColor = Color.hex(\"#ffaf00\")\n",
|
477 | 477 | " }\n",
|
478 | 478 | " lineRanges {\n",
|
479 |
| - " // Calculate the min and max for the error bars (Std ROA)\n", |
480 |
| - " yMin(`Avg ROA`.toList().zip(`Std ROA`.toList()).map { it.first - it.second })\n", |
481 |
| - " yMax(`Avg ROA`.toList().zip(`Std ROA`.toList()).map { it.first + it.second })\n", |
| 479 | + " // Calculate the min and max for the error bars (Std roa)\n", |
| 480 | + " yMin(`Avg roa`.toList().zip(`Std roa`.toList()).map { it.first - it.second })\n", |
| 481 | + " yMax(`Avg roa`.toList().zip(`Std roa`.toList()).map { it.first + it.second })\n", |
482 | 482 | " // Color the line of the ranges\n",
|
483 | 483 | " borderLine.color = Color.GREY\n",
|
484 | 484 | " }\n",
|
485 | 485 | "\n",
|
486 | 486 | " // Adjust layout options such as title and overall size\n",
|
487 | 487 | " layout {\n",
|
488 |
| - " title = \"Average ROA By Sector With Standard Deviation\"\n", |
| 488 | + " title = \"Average roa By Sector With Standard Deviation\"\n", |
489 | 489 | " size = 875 to 500\n",
|
490 | 490 | " }\n",
|
491 | 491 | "}"
|
|
497 | 497 | "metadata": {},
|
498 | 498 | "cell_type": "code",
|
499 | 499 | "source": [
|
500 |
| - "// Plot average ROE by sector with error bars representing one standard deviation\n", |
| 500 | + "// Plot average roe by sector with error bars representing one standard deviation\n", |
501 | 501 | "roeAndRoaDf.plot {\n",
|
502 | 502 | " // Set the x-axis to the sector names\n",
|
503 | 503 | " x(sector.map { it.simpleName }) { axis.name = \"Sector of Business\" }\n",
|
504 | 504 | "\n",
|
505 | 505 | " bars {\n",
|
506 |
| - " // Use the \"Avg ROE\" column for the bar heights\n", |
507 |
| - " y(`Avg ROE`)\n", |
| 506 | + " // Use the \"Avg roe\" column for the bar heights\n", |
| 507 | + " y(`Avg roe`)\n", |
508 | 508 | " // Fill bars with a chosen color\n",
|
509 | 509 | " fillColor = Color.hex(\"#ffaf00\")\n",
|
510 | 510 | " }\n",
|
511 | 511 | " lineRanges {\n",
|
512 |
| - " // Calculate the min and max for the error bars (Std ROE)\n", |
513 |
| - " yMin(`Avg ROE`.toList().zip(`Std ROE`.toList()).map { it.first - it.second })\n", |
514 |
| - " yMax(`Avg ROE`.toList().zip(`Std ROE`.toList()).map { it.first + it.second })\n", |
| 512 | + " // Calculate the min and max for the error bars (Std roe)\n", |
| 513 | + " yMin(`Avg roe`.toList().zip(`Std roe`.toList()).map { it.first - it.second })\n", |
| 514 | + " yMax(`Avg roe`.toList().zip(`Std roe`.toList()).map { it.first + it.second })\n", |
515 | 515 | " // Color the line of the ranges\n",
|
516 | 516 | " borderLine.color = Color.GREY\n",
|
517 | 517 | " }\n",
|
518 | 518 | "\n",
|
519 | 519 | " // Adjust layout options such as title and overall size\n",
|
520 | 520 | " layout {\n",
|
521 |
| - " title = \"Average ROE By Sector With Standard Deviation\"\n", |
| 521 | + " title = \"Average roe By Sector With Standard Deviation\"\n", |
522 | 522 | " size = 875 to 500\n",
|
523 | 523 | " }\n",
|
524 | 524 | "}"
|
|
0 commit comments