What Idea about Stock MACD Quadrant ?
The Stock MACD Quadrant Chart represents an overhead analysis of MACD, including multiple Stock in a single chart.
First, import the necessary libraries and dataset:
import pandas as pd
import yfinance as yf
import pandas_ta as ta
Create a ticker list and download data with a 2-day period and 1-day interval from Yahoo Finance:
ticker_list = ['PTT.BK','KBANK.BK','PTTGC.BK','SCC.BK','GPSC.BK',
'GULF.BK','PTTEP.BK','BDMS.BK','SCB.BK','CPALL.BK','AOT.BK','ADVANC.BK',
'AWC.BK','BANPU.BK','BBL.BK','BEM.BK','BGRIM.BK','BH.BK','BTS.BK','CBG.BK',
'COM7.BK','CPF.BK','CPN.BK','CRC.BK','DTAC.BK','EA.BK','EGCO.BK','GLOBAL.BK',
'HMPRO.BK','INTUCH.BK','IRPC.BK','IVL.BK','KCE.BK','KTB.BK','KTC.BK','LH.BK',
'MINT.BK','MTC.BK','OR.BK','OSP.BK','RATCH.BK','SAWAD.BK','SCGP.BK','STGT.BK',
'TIDLOR.BK','TISCO.BK','TOP.BK','TRUE.BK','TTB.BK','TU.BK'
]
data=yf.download(ticker_list,period='1y',interval='1d',group_by='column')
data.fillna(method='ffill',inplace=True)
data
[*********************100%***********************] 50 of 50 completed
Adj Close | … | Volume | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ADVANC.BK | AOT.BK | AWC.BK | BANPU.BK | BBL.BK | BDMS.BK | BEM.BK | BGRIM.BK | BH.BK | BTS.BK | … | SCB.BK | SCC.BK | SCGP.BK | STGT.BK | TIDLOR.BK | TISCO.BK | TOP.BK | TRUE.BK | TTB.BK | TU.BK | |
Date | |||||||||||||||||||||
2022-04-11 | 215.691345 | 67.00 | 4.869240 | 9.830594 | 131.570862 | 25.221785 | 8.439677 | 32.693142 | 158.864182 | 8.777742 | … | NaN | 3334600 | 9633900 | 7125300 | 4116430 | 4167300 | 6204300 | 158715000.0 | 80762000 | 15357100 |
2022-04-12 | 214.728439 | 68.00 | 4.889196 | 9.740406 | 131.085358 | 25.221785 | 8.291613 | 32.693142 | 159.356003 | 8.777742 | … | NaN | 1800000 | 4736800 | 5352100 | 9326907 | 3891000 | 7487600 | 63423400.0 | 135586100 | 36730000 |
2022-04-18 | 212.802612 | 67.25 | 4.988976 | 10.101161 | 130.599869 | 25.221785 | 8.242258 | 32.693142 | 157.388657 | 8.777742 | … | NaN | 2370500 | 4061200 | 10735600 | 15806645 | 4472900 | 5897900 | 119334300.0 | 203412400 | 28960200 |
2022-04-19 | 207.025177 | 67.25 | 4.988976 | 10.461917 | 132.056366 | 25.711529 | 8.192904 | 32.443573 | 157.880493 | 8.777742 | … | NaN | 2897900 | 4874800 | 8187500 | 6268876 | 5314400 | 29354000 | 53312700.0 | 339099200 | 22326000 |
2022-04-20 | 207.988083 | 67.00 | 4.969019 | 10.642295 | 133.027374 | 25.956400 | 8.242258 | 32.942707 | 161.815216 | 8.729514 | … | 2840200.0 | 2521200 | 6746700 | 4755600 | 3457138 | 5250700 | 25115700 | 35610600.0 | 593187800 | 18619400 |
… | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … |
2023-04-03 | 213.000000 | 71.50 | 5.800000 | 10.336239 | 154.000000 | 29.750000 | 8.900000 | 39.500000 | 226.000000 | 7.100000 | … | 5468900.0 | 1432200 | 7188400 | 3249000 | 9192600 | 1747300 | 20252800 | 0.0 | 93648300 | 23346800 |
2023-04-04 | 213.000000 | 71.75 | 5.800000 | 10.243119 | 154.500000 | 30.500000 | 8.950000 | 38.500000 | 227.000000 | 7.200000 | … | 5276900.0 | 1496500 | 7758300 | 1619400 | 2822900 | 2456200 | 5561400 | 0.0 | 230830200 | 29583900 |
2023-04-05 | 209.000000 | 71.75 | 5.700000 | 10.056881 | 153.000000 | 30.250000 | 9.000000 | 39.500000 | 229.000000 | 7.150000 | … | 7396900.0 | 942800 | 4718700 | 5068300 | 13217100 | 6498400 | 6746000 | 0.0 | 178951000 | 40425800 |
2023-04-07 | 210.000000 | 72.00 | 5.600000 | 10.150000 | 153.000000 | 30.000000 | 8.950000 | 39.250000 | 230.000000 | 7.400000 | … | 8880400.0 | 832800 | 7574600 | 1331200 | 2765700 | 4633600 | 3255800 | 0.0 | 267540800 | 16634400 |
2023-04-10 | 212.000000 | 72.25 | 5.750000 | 10.150000 | 154.500000 | 30.500000 | 8.950000 | 40.000000 | 235.000000 | 7.650000 | … | 5404495.0 | 554076 | 4718204 | 2070053 | 17744225 | 2743154 | 3517274 | 14147134.0 | 34737313 | 13789732 |
242 rows × 300 columns
Stack and sort the data:
df=data.stack()
# sort by stock name
df=df.sort_index(level=1)
df.index.names=['Date','Stock']
df
Adj Close | Close | High | Low | Open | Volume | ||
---|---|---|---|---|---|---|---|
Date | Stock | ||||||
2022-04-11 | ADVANC.BK | 215.691345 | 224.0 | 226.0 | 223.0 | 225.0 | 3504800.0 |
2022-04-12 | ADVANC.BK | 214.728439 | 223.0 | 225.0 | 221.0 | 222.0 | 2646900.0 |
2022-04-18 | ADVANC.BK | 212.802612 | 221.0 | 223.0 | 219.0 | 223.0 | 5392900.0 |
2022-04-19 | ADVANC.BK | 207.025177 | 215.0 | 223.0 | 214.0 | 222.0 | 9313500.0 |
2022-04-20 | ADVANC.BK | 207.988083 | 216.0 | 220.0 | 215.0 | 215.0 | 7284200.0 |
… | … | … | … | … | … | … | … |
2023-04-03 | TU.BK | 13.800000 | 13.8 | 14.2 | 13.8 | 14.1 | 23346800.0 |
2023-04-04 | TU.BK | 13.600000 | 13.6 | 13.9 | 13.5 | 13.8 | 29583900.0 |
2023-04-05 | TU.BK | 13.200000 | 13.2 | 13.7 | 13.2 | 13.6 | 40425800.0 |
2023-04-07 | TU.BK | 13.200000 | 13.2 | 13.4 | 13.2 | 13.3 | 16634400.0 |
2023-04-10 | TU.BK | 13.300000 | 13.3 | 13.5 | 13.2 | 13.2 | 13789732.0 |
12096 rows × 6 columns
Reset the index and apply the MACD indicator:
df2=df.reset_index().set_index('Stock')
df2.ta.macd(append=True)
df2
MACD_12_26_9 | MACDh_12_26_9 | MACDs_12_26_9 | |
---|---|---|---|
Stock | |||
ADVANC.BK | NaN | NaN | NaN |
ADVANC.BK | NaN | NaN | NaN |
ADVANC.BK | NaN | NaN | NaN |
ADVANC.BK | NaN | NaN | NaN |
ADVANC.BK | NaN | NaN | NaN |
… | … | … | … |
TU.BK | -0.380704 | -0.023116 | -0.357587 |
TU.BK | -0.417789 | -0.048162 | -0.369628 |
TU.BK | -0.473993 | -0.083492 | -0.390501 |
TU.BK | -0.512626 | -0.097700 | -0.414926 |
TU.BK | -0.529074 | -0.091319 | -0.437756 |
12096 rows × 3 columns
set date index
df3=df2.reset_index().set_index('Date')
df3
Stock | Adj Close | Close | High | Low | Open | Volume | MACD_12_26_9 | MACDh_12_26_9 | MACDs_12_26_9 | |
---|---|---|---|---|---|---|---|---|---|---|
Date | ||||||||||
2022-04-11 | ADVANC.BK | 215.691345 | 224.0 | 226.0 | 223.0 | 225.0 | 3504800.0 | NaN | NaN | NaN |
2022-04-12 | ADVANC.BK | 214.728439 | 223.0 | 225.0 | 221.0 | 222.0 | 2646900.0 | NaN | NaN | NaN |
2022-04-18 | ADVANC.BK | 212.802612 | 221.0 | 223.0 | 219.0 | 223.0 | 5392900.0 | NaN | NaN | NaN |
2022-04-19 | ADVANC.BK | 207.025177 | 215.0 | 223.0 | 214.0 | 222.0 | 9313500.0 | NaN | NaN | NaN |
2022-04-20 | ADVANC.BK | 207.988083 | 216.0 | 220.0 | 215.0 | 215.0 | 7284200.0 | NaN | NaN | NaN |
… | … | … | … | … | … | … | … | … | … | … |
2023-04-03 | TU.BK | 13.800000 | 13.8 | 14.2 | 13.8 | 14.1 | 23346800.0 | -0.380704 | -0.023116 | -0.357587 |
2023-04-04 | TU.BK | 13.600000 | 13.6 | 13.9 | 13.5 | 13.8 | 29583900.0 | -0.417789 | -0.048162 | -0.369628 |
2023-04-05 | TU.BK | 13.200000 | 13.2 | 13.7 | 13.2 | 13.6 | 40425800.0 | -0.473993 | -0.083492 | -0.390501 |
2023-04-07 | TU.BK | 13.200000 | 13.2 | 13.4 | 13.2 | 13.3 | 16634400.0 | -0.512626 | -0.097700 | -0.414926 |
2023-04-10 | TU.BK | 13.300000 | 13.3 | 13.5 | 13.2 | 13.2 | 13789732.0 | -0.529074 | -0.091319 | -0.437756 |
12096 rows × 10 columns
Rename the columns for better readability:
df4=df3.loc['2022-08-05']
df4
Stock | Adj Close | Close | High | Low | Open | Volume | MACD_12_26_9 | MACDh_12_26_9 | MACDs_12_26_9 | |
---|---|---|---|---|---|---|---|---|---|---|
Date | ||||||||||
2022-08-05 | ADVANC.BK | 194.507385 | 202.000000 | 203.000000 | 201.000000 | 203.000 | 2602200.0 | -0.856513 | 0.294622 | -1.151134 |
2022-08-05 | AOT.BK | 71.750000 | 71.750000 | 71.750000 | 71.000000 | 71.750 | 21971500.0 | -0.081835 | 0.340664 | -0.422499 |
2022-08-05 | AWC.BK | 5.000000 | 5.000000 | 5.100000 | 5.000000 | 5.100 | 45309700.0 | -0.165879 | 0.107002 | -0.272881 |
2022-08-05 | BANPU.BK | 11.544184 | 12.800000 | 12.900000 | 12.400000 | 12.700 | 178069500.0 | 0.144754 | -0.018662 | 0.163416 |
2022-08-05 | BBL.BK | 132.532852 | 134.000000 | 134.000000 | 132.000000 | 132.500 | 6410800.0 | 0.721769 | 0.210268 | 0.511500 |
2022-08-05 | BDMS.BK | 26.446142 | 27.000000 | 27.250000 | 26.750000 | 27.250 | 52557700.0 | 0.000031 | 0.198562 | -0.198531 |
2022-08-05 | BEM.BK | 8.785161 | 8.900000 | 8.950000 | 8.800000 | 8.900 | 38909200.0 | -0.036102 | 0.067209 | -0.103311 |
2022-08-05 | BGRIM.BK | 38.682720 | 38.750000 | 40.000000 | 38.250000 | 40.000 | 23528900.0 | 1.028156 | 0.035208 | 0.992948 |
2022-08-05 | BH.BK | 179.029587 | 182.000000 | 184.000000 | 181.000000 | 184.000 | 1962100.0 | 1.456043 | -0.426671 | 1.882714 |
2022-08-05 | BTS.BK | 8.450868 | 8.600000 | 8.650000 | 8.550000 | 8.600 | 22088700.0 | -0.649717 | 0.305738 | -0.955455 |
2022-08-05 | CBG.BK | 111.864189 | 113.500000 | 114.500000 | 113.000000 | 113.500 | 1640200.0 | 1.525211 | -0.092968 | 1.618179 |
2022-08-05 | COM7.BK | 32.702381 | 33.500000 | 34.000000 | 32.250000 | 32.750 | 26999300.0 | 0.287947 | 0.786764 | -0.498816 |
2022-08-05 | CPALL.BK | 60.000000 | 60.000000 | 60.250000 | 59.750000 | 59.750 | 12652600.0 | -0.410506 | -0.134523 | -0.275983 |
2022-08-05 | CPF.BK | 24.414757 | 24.799999 | 25.250000 | 24.799999 | 25.000 | 19225300.0 | -0.404668 | -0.018700 | -0.385968 |
2022-08-05 | CPN.BK | 63.871700 | 65.000000 | 65.250000 | 64.000000 | 65.250 | 6587100.0 | 1.291491 | 0.354865 | 0.936626 |
2022-08-05 | CRC.BK | 38.000000 | 38.000000 | 38.250000 | 37.500000 | 37.500 | 13405600.0 | 0.495492 | 0.338542 | 0.156950 |
2022-08-05 | DTAC.BK | 45.614975 | 46.750000 | 47.250000 | 46.000000 | 46.000 | 13830500.0 | 0.308592 | 0.052920 | 0.255672 |
2022-08-05 | EA.BK | 81.681557 | 82.000000 | 83.250000 | 82.000000 | 83.000 | 4059700.0 | 0.094677 | 0.483959 | -0.389282 |
2022-08-05 | EGCO.BK | 177.501480 | 184.500000 | 186.500000 | 183.000000 | 186.500 | 1333400.0 | 2.561365 | -0.364021 | 2.925386 |
2022-08-05 | GLOBAL.BK | 17.522085 | 17.759998 | 17.952000 | 17.664000 | 17.952 | 3141354.0 | -0.446744 | 0.377365 | -0.824108 |
2022-08-05 | GPSC.BK | 69.986137 | 70.500000 | 71.000000 | 69.500000 | 71.000 | 10314500.0 | 1.285259 | 0.303010 | 0.982249 |
2022-08-05 | GULF.BK | 48.192856 | 48.750000 | 49.500000 | 48.500000 | 49.250 | 23724500.0 | 0.229528 | 0.213550 | 0.015977 |
2022-08-05 | HMPRO.BK | 13.339511 | 13.500000 | 13.600000 | 13.400000 | 13.500 | 33188400.0 | -0.073748 | 0.142847 | -0.216595 |
2022-08-05 | INTUCH.BK | 67.864662 | 72.250000 | 72.750000 | 71.750000 | 72.750 | 1046400.0 | 0.713090 | 0.116870 | 0.596220 |
2022-08-05 | IRPC.BK | 3.246046 | 3.320000 | 3.320000 | 3.280000 | 3.300 | 28322400.0 | -0.196626 | 0.123611 | -0.320237 |
2022-08-05 | IVL.BK | 42.205212 | 43.000000 | 44.000000 | 42.750000 | 44.000 | 27382300.0 | -0.667181 | -0.085784 | -0.581397 |
2022-08-05 | KBANK.BK | 146.513245 | 147.000000 | 147.500000 | 144.500000 | 145.000 | 16607200.0 | 0.027785 | 0.429325 | -0.401540 |
2022-08-05 | KCE.BK | 63.230595 | 65.250000 | 65.750000 | 65.000000 | 65.750 | 6052000.0 | 1.285798 | 1.320024 | -0.034226 |
2022-08-05 | KTB.BK | 16.000000 | 16.000000 | 16.000000 | 15.800000 | 15.800 | 30308400.0 | 0.090490 | 0.128446 | -0.037956 |
2022-08-05 | KTC.BK | 58.500000 | 58.500000 | 59.000000 | 58.250000 | 58.750 | 2876100.0 | 0.417129 | 0.464354 | -0.047226 |
2022-08-05 | LH.BK | 8.408380 | 8.650000 | 8.700000 | 8.600000 | 8.650 | 18001300.0 | -0.075786 | 0.127073 | -0.202859 |
2022-08-05 | MINT.BK | 33.500000 | 33.500000 | 34.000000 | 33.000000 | 34.000 | 11301400.0 | 0.093614 | 0.068802 | 0.024812 |
2022-08-05 | MTC.BK | 50.500000 | 50.500000 | 51.250000 | 50.250000 | 51.000 | 7803200.0 | 1.655034 | 0.641360 | 1.013674 |
2022-08-05 | OR.BK | 26.469118 | 27.000000 | 27.000000 | 26.500000 | 26.750 | 23073500.0 | 0.157625 | 0.205681 | -0.048055 |
2022-08-05 | OSP.BK | 31.300001 | 31.750000 | 31.750000 | 31.250000 | 31.500 | 6439800.0 | -0.625802 | -0.092757 | -0.533046 |
2022-08-05 | PTT.BK | 33.495125 | 35.500000 | 35.500000 | 34.500000 | 34.750 | 53854700.0 | 0.103058 | 0.188528 | -0.085470 |
2022-08-05 | PTTEP.BK | 142.485611 | 151.000000 | 152.500000 | 149.500000 | 152.000 | 27671000.0 | -0.662412 | -0.739582 | 0.077170 |
2022-08-05 | PTTGC.BK | 44.285843 | 45.250000 | 45.500000 | 44.000000 | 44.750 | 10155500.0 | -0.438250 | 0.347540 | -0.785790 |
2022-08-05 | RATCH.BK | 37.015697 | 38.500000 | 39.000000 | 38.250000 | 38.500 | 5418500.0 | -0.002268 | 0.054583 | -0.056850 |
2022-08-05 | SAWAD.BK | 53.500000 | 53.500000 | 53.500000 | 52.750000 | 53.250 | 6020300.0 | 0.851655 | 0.641373 | 0.210281 |
2022-08-05 | SCB.BK | 102.000000 | 103.500000 | 103.500000 | 101.000000 | 101.000 | 14923300.0 | -0.099184 | 0.913495 | -1.012679 |
2022-08-05 | SCC.BK | 358.740265 | 367.000000 | 368.000000 | 366.000000 | 367.000 | 1896800.0 | -0.544546 | -1.427313 | 0.882767 |
2022-08-05 | SCGP.BK | 54.831890 | 55.500000 | 56.000000 | 55.000000 | 55.750 | 13283300.0 | -1.119798 | 0.631380 | -1.751178 |
2022-08-05 | STGT.BK | 15.684077 | 16.200001 | 16.700001 | 16.200001 | 16.500 | 10841100.0 | -0.290935 | 0.133474 | -0.424409 |
2022-08-05 | TIDLOR.BK | 30.000000 | 30.000000 | 30.500000 | 30.000000 | 30.500 | 12373100.0 | 0.050344 | 0.423401 | -0.373056 |
2022-08-05 | TISCO.BK | 89.500000 | 89.500000 | 89.750000 | 89.250000 | 89.250 | 3243000.0 | 0.391825 | 0.226263 | 0.165562 |
2022-08-05 | TOP.BK | 47.707916 | 51.000000 | 51.500000 | 50.250000 | 51.500 | 13279300.0 | -0.452842 | 0.349862 | -0.802703 |
2022-08-05 | TRUE.BK | 5.000000 | 5.000000 | 5.050000 | 4.900000 | 4.900 | 366377200.0 | -0.083647 | 0.097325 | -0.180973 |
2022-08-05 | TTB.BK | 1.151429 | 1.170000 | 1.190000 | 1.170000 | 1.180 | 249877600.0 | -0.029988 | 0.013520 | -0.043507 |
2022-08-05 | TU.BK | 15.779944 | 16.600000 | 16.600000 | 16.400000 | 16.500 | 5566800.0 | 0.011797 | 0.096138 | -0.084341 |
visulization section
import plotly.express as px
fig = px.scatter(df4,x='MACD_12_26_9',y='MACDh_12_26_9',color='Stock',text='Stock',hover_data=['Stock','Close'],title='MACD Quadrant : SET50')
fig.update_traces(marker={'size':14})
fig.update_traces(textposition='top center')
fig.add_vline(x=0,line_color="red")
fig.add_hline(y=0,line_color="red")
fig.show()
This code provides a comprehensive overview of the MACD values for various Stock in a single chart, allowing for easier analysis and comparison.
Conclusion
In conclusion, the Stock MACD Quadrant Chart provides a comprehensive and efficient way to analyze the performance of multiple Stock in a single visual representation. By incorporating MACD indicators, the chart offers valuable insights into the market momentum and potential trend reversals, enabling investors to make informed decisions when trading or investing in Stock.
The benefits of using the Stock MACD Quadrant Chart include:
Time-saving: Instead of analyzing individual charts for each Stock, the quadrant chart consolidates the information, allowing for a quick and efficient overview of market trends.
Enhanced decision-making: By utilizing the MACD indicator, the chart provides valuable information on market momentum, enabling investors to identify potential buy or sell signals.
Comparative analysis: The quadrant chart allows for easy comparison of the performance of various Stock,
Improved risk management: By gaining a better understanding of market trends and momentum, investors can develop more effective risk management strategies and protect their investments from potential losses.