The PE Band Chart Analysis - Visualize Historical Stock Valuation

Apr 9, 2023

4 min read


programmer-with-chrome

What Idea about PE ROE CHART ?


In this article, we will explore the idea of using a Price-to-Earnings (PE) and Return on Equity (ROE) band chart to analyze financial data. We will use Python and some popular libraries to read and process the data, and then create a band chart to visualize it.

The code provided imports the necessary libraries, reads data from an Excel file, and stores it in a pandas DataFrame. It then sorts the DataFrame by market capitalization (MCap) and selects the top 50 companies.


Importing Libraries:

First, let’s import the necessary libraries:


import pandas as pd
import numpy as np
import plotly.express as px

Loading the Data:


Next, we will read the data from an Excel file hosted on Google Drive and store it in a pandas DataFrame:


path = 'https://drive.google.com/uc?expoert=download&id=1EqhMOcAPX7WfW1gObCPPsFq99D5RfA42'
df=pd.read_excel(path)
df

NameNo.LinksSignLastChg%VolumeValue (k)MCap (M)P/EROA%ROE%NPM%Yield%FFloat%MG%Magic1Magic2PEGCG
0AverageNaNNaNNaN19.491.613.363165e+07105048.2624834.0562.505.612.36-12.970.7740.89NaN559.69558.51-1.10NaN
12S1.0i | 1 | 2 | 3NaN6.852.241.073600e+067281.003425.004.7240.3138.9815.653.2858.11NaN31.0017.000.02NaN
23K-BAT2.0iNaN68.25-0.731.000000e+0368.005351.0049.35-3.085.283.290.372.10NaN914.00NaNNaNNaN
37UP3.0i | 1 | 2 | 3NaN1.612.552.758150e+08440191.008280.0039.607.7010.2037.44NaN66.55NaN741.00713.00-0.29NaN
4A4.0i | 1 | 2 | 3NaN4.96-0.401.500000e+037.004861.0051.303.992.77-4.930.6025.86NaN989.00927.00-0.18NaN
752XPG752.0i | 1 | 2 | 3NaN3.98-4.333.193370e+07128129.0011405.00830.921.491.56129.78NaN61.26NaN1082.001106.00-1.65NaN
753YGG753.0i | 1 | 3NaN20.70-1.906.996000e+0514600.003726.0043.2022.0824.2132.100.8526.32NaN534.00489.002.63NaN
754YUASA754.0i | 1 | 3NaN16.800.006.400000e+03108.001808.0010.5916.7020.395.822.6315.27NaN215.00178.000.23NaN
755ZEN755.0i | 1 | 3NaN11.80-0.841.912000e+052278.003540.00158.122.181.83-3.452.1226.68NaN1060.001060.00-6.52NaN
756ZIGA756.0i | 1 | 2 | 3NaN5.05-1.945.696200e+0629052.002511.0016.1814.3620.2913.693.1937.17NaN322.00306.000.32NaN

757 rows × 24 columns


Sorting by Market Capitalization:


We will now sort the DataFrame by the market capitalization (MCap) column in descending order and select the top 50 rows:


set50df = df.sort_values(['MCap (M)'],ascending=False)[:50]
set50df

NameNo.LinksSignLastChg%VolumeValue (k)MCap (M)P/EROA%ROE%NPM%Yield%FFloat%MG%Magic1Magic2PEGCG
467PTT467.0i | 1 | 2 | 3NaN38.00-0.6528381900.01074237.01085394.012.867.459.227.862.6348.88NaN488.0445.00.13NaN
170DELTA170.0i | 1 | 2 | 3NaN764.004.663045800.02312848.0953000.0123.8314.1721.418.520.4322.35NaN619.0615.0-7.49NaN
42AOT42.0i | 1 | 2 | 3NaN63.00-0.7914060600.0884765.0899999.0NaN-8.68-11.27-184.600.3030.00NaNNaNNaNNaNNaN
15ADVANC15.0i | 1 | 2 | 3NaN191.500.797256600.01383672.0569507.021.4110.4136.4515.303.6136.22NaN319.0474.0-4.20NaN
147CPALL147.0i | 1 | 2 | 3NaN62.50-0.7946574000.02904196.0561444.046.165.5013.701.841.4457.50NaN674.0851.03.42NaN
513SCC513.0i | 1 | 2 | 3NaN424.00-0.93906700.0385150.0508800.010.219.8915.3714.883.3066.21NaN274.0300.0-1.60NaN
236GULF236.0i | 1 | 2 | 3NaN41.75-1.7669909800.02960616.0489859.084.695.6112.4617.210.9126.23NaN746.0887.03.41NaN
468PTTEP468.0i | 1 | 2 | 3NaN108.50-1.364623500.0503196.0430743.015.248.217.6117.033.9234.69NaN575.0457.02.02NaN
82BDMS82.0i | 1 | 2 | 3NaN23.20-0.8514042900.0326426.0368694.052.838.548.558.912.3765.98NaN823.0722.02.44NaN
512SCB512.0i | 1 | 2 | 3XD104.00-1.893662300.0381120.0353146.012.401.706.9125.342.2176.61NaN549.0705.0-3.38NaN
409OR409.0iNaN29.250.0015964200.0469812.0351000.026.037.8611.903.020.3323.72NaN590.0605.0NaNNaN
293KBANK293.0i | 1 | 3NaN122.00-0.418435400.01028314.0289058.07.301.909.1819.272.0579.60NaN367.0583.0-488.67NaN
516SCGP516.0i | 1 | 3NaN67.00-2.1927537900.01850632.0287626.039.256.8310.419.140.6726.21NaN736.0752.0NaNNaN
266INTUCH266.0i | 1 | 2 | 3NaN86.750.8710442200.0899883.0278172.026.7320.7928.51273.842.8863.21NaN388.0372.0-3.58NaN
469PTTGC469.0i | 1 | 2 | 3XD60.00-2.4414956500.0905059.0270531.06.3710.4714.3614.681.6754.32NaN221.0209.02.70NaN
337MAKRO337.0i | 1 | 3NaN52.500.0018354500.0963709.0252000.037.1212.9331.352.711.906.92NaN469.0548.09.34NaN
183EA183.0i | 1 | 2 | 3NaN66.00-0.7512536300.0834329.0246180.048.368.3719.0325.940.4540.37NaN592.0722.02.08NaN
152CPN152.0i | 1 | 2 | 3NaN53.501.4211157100.0594783.0240108.025.146.1914.2130.881.3162.75NaN523.0670.01.94NaN
75BAY75.0i | 1 | 3NaN32.250.781782800.057438.0237223.07.652.4010.4431.961.0923.12NaN341.0570.00.50NaN
274IVL274.0i | 1 | 2 | 3NaN42.25-0.5915631400.0669683.0237215.014.885.6011.737.141.6635.11NaN452.0574.00.49NaN
229GPSC229.0i | 1 | 2 | 3NaN82.75-0.607248700.0603553.0233333.028.015.598.1312.381.8124.75NaN718.0744.01.31NaN
148CPF148.0i | 1 | 2 | 3NaN26.50-1.8528640900.0762444.0228198.08.728.7012.975.633.7945.49NaN290.0305.00.61NaN
76BBL76.0i | 1 | 2 | 3NaN114.000.006231000.0708242.0217608.011.051.454.3520.922.1998.53NaN596.0688.08.44NaN
157CRC157.0i | 1 | 3NaN34.25-0.723287000.0112461.0206562.0112.431.803.260.031.1753.11NaN1019.01064.0NaNNaN
243HMPRO243.0i | 1 | 2 | 3NaN14.00-0.7113010600.0182351.0184117.032.3013.2527.548.522.1440.83NaN456.0515.02.09NaN
310KTC310.0i | 1 | 2 | 3NaN66.75-1.1110156500.0680479.0172104.029.1710.7826.3531.041.3240.45NaN444.0558.01.01NaN
360MINT360.0i | 1 | 2 | 3NaN32.00-1.547722300.0246868.0166369.0NaN-4.94-35.79-42.07NaN61.42NaNNaNNaNNaNNaN
309KTB309.0i | 1 | 2 | 3NaN11.10-0.8910181300.0113044.0155134.08.571.465.3123.072.4844.93NaN506.0628.02.73NaN
93BJC93.0i | 1 | 2 | 3NaN35.000.722810500.097958.0140273.033.243.223.742.972.2325.57NaN896.0890.01.19NaN
67AWC67.0i | 1 | 3NaN4.240.4723363400.098952.0135680.0NaN-0.79-2.55-37.92NaN24.97NaNNaNNaNNaNNaN
116CBG116.0i | 1 | 2 | 3NaN133.00-1.126198500.0829850.0133000.037.1925.3037.1218.121.8028.85NaN456.0444.01.36NaN
371MTC371.0i | 1 | 2 | 3NaN61.50-0.813287600.0203283.0130380.024.1511.0326.4334.100.6032.12NaN381.0486.00.46NaN
85BEM85.0i | 1 | 2 | 3NaN8.50-0.5837106500.0315875.0129923.068.893.875.098.551.1854.02NaN953.0960.03.02NaN
110BTS110.0i | 1 | 2 | 3NaN9.35-0.5330140700.0282400.0123076.022.315.479.8715.063.3259.67NaN610.0691.02.39NaN
88BGRIM88.0i | 1 | 2 | 3NaN45.000.009387300.0422143.0117311.043.536.219.7610.541.0036.01NaN772.0803.06.80NaN
686TRUE686.0i | 1 | 2 | 3NaN3.36-1.1873249300.0247376.0112117.0NaN2.93-1.12-1.342.0831.78NaNNaNNaNNaNNaN
411OSP411.0i | 1 | 3NaN35.000.0012505100.0433992.0105131.029.4315.7618.6412.683.1446.56NaN505.0457.03.46NaN
90BH90.0i | 1 | 2 | 3NaN132.00-1.861120300.0148576.0104885.0150.183.773.865.372.4249.02NaN1014.0991.060.82NaN
589STGT589.0iNaN36.250.006267600.0227332.0103793.03.4883.42102.2860.747.2334.33NaN5.05.0NaNNaN
695TTB695.0i | 1 | 2 | 3NaN1.06-0.93111503500.0118292.0102194.012.511.354.0116.244.2534.20NaN640.0725.0-4.79NaN
665TOP665.0i | 1 | 2 | 3NaN49.500.0011298500.0562364.0100981.07.586.8712.083.641.4151.96NaN293.0350.0-5.03NaN
324LH324.0i | 1 | 2 | 3NaN8.150.0019943300.0162013.097390.011.998.4616.3521.556.1369.40NaN308.0393.01.86NaN
226GLOBAL226.0i | 1 | 2 | 3NaN21.10-1.4014780900.0311305.097095.034.7110.3616.1710.870.8432.11NaN578.0602.01.32NaN
700TU700.0i | 1 | 2 | 3NaN20.20-0.9824200700.0488060.096391.012.287.1614.386.343.5660.55NaN341.0442.0-3.26NaN
190EGCO190.0i | 1 | 2 | 3NaN181.000.841185100.0214379.095290.015.495.315.9712.443.5950.00NaN629.0606.00.35NaN
509SAWAD509.0i | 1 | 2 | 3NaN69.25-1.776545600.0455449.095091.019.3114.7722.5649.652.6045.03NaN356.0355.00.63NaN
297KCE297.0i | 1 | 2 | 3NaN77.00-1.6011156900.0867800.090943.052.0810.9514.3015.841.0358.02NaN674.0649.0-3.77NaN
179DTAC179.0i | 1 | 2 | 3NaN38.00-1.308252800.0316006.089977.023.134.6617.575.797.8729.26NaN443.0727.0-0.15NaN
639TIDLOR639.0i | 1 | 3NaN38.25-1.9210047200.0387333.088701.029.817.3513.3426.91NaN44.53NaN597.0668.0NaNNaN
144COM7144.0i | 1 | 2 | 3NaN71.502.5113313100.0941356.085800.040.8025.0561.834.901.4045.71NaN459.0470.00.90NaN

50 rows × 24 columns


set50df.columns
Index(['Name', 'No.', 'Links', 'Sign', 'Last', 'Chg%', 'Volume', 'Value (k)','MCap (M)', 'P/E', 'P/BV', 'D/E', 'DPS', 'EPS', 'ROA%', 'ROE%', 'NPM%','Yield%', 'FFloat%', 'MG%', 'Magic1', 'Magic2', 'PEG', 'CG'],dtype='object')

set50df['Yield%']=set50df['Yield%'].astype(float)
# must be type float for plotly display

set50df.dtypes
    Name          object
    No.          float64
    Links         object
    Sign          object
    Last         float64
    Chg%         float64
    Volume       float64
    Value (k)    float64
    MCap (M)     float64
    P/E          float64
    P/BV          object
    D/E          float64
    DPS           object
    EPS          float64
    ROA%         float64
    ROE%         float64
    NPM%         float64
    Yield%       float64
    FFloat%      float64
    MG%          float64
    Magic1       float64
    Magic2       float64
    PEG          float64
    CG           float64
    dtype: object

Creating the PE Band Chart:


With our data now sorted, we can create a PE band chart to visualize the relationship between the Price-to-Earnings ratio (P/E) and the Return on Equity (ROE). We will use the Plotly Express library to achieve this:


fig = px.scatter(set50df,x='ROE%',y='P/E',color='Yield%',text='Name',hover_data=['Name','PEG'],title='FUNDAMENTAL PE : ROE SET50')



Conclusion


In this article, we have shown how to use Python and popular libraries to load financial data, process it, and create a PE band chart to visualize the relationship between the Price-to-Earnings ratio and the Return on Equity. This can be a helpful tool for analyzing trends, identifying potential opportunities, or spotting potential issues in a company’s financial performance.