SET50 MACD Quandrant

Apr 11, 2023

2 min read


programmer-with-chrome

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 CloseVolume
ADVANC.BKAOT.BKAWC.BKBANPU.BKBBL.BKBDMS.BKBEM.BKBGRIM.BKBH.BKBTS.BKSCB.BKSCC.BKSCGP.BKSTGT.BKTIDLOR.BKTISCO.BKTOP.BKTRUE.BKTTB.BKTU.BK
Date
2022-04-11215.69134567.004.8692409.830594131.57086225.2217858.43967732.693142158.8641828.777742NaN333460096339007125300411643041673006204300158715000.08076200015357100
2022-04-12214.72843968.004.8891969.740406131.08535825.2217858.29161332.693142159.3560038.777742NaN18000004736800535210093269073891000748760063423400.013558610036730000
2022-04-18212.80261267.254.98897610.101161130.59986925.2217858.24225832.693142157.3886578.777742NaN23705004061200107356001580664544729005897900119334300.020341240028960200
2022-04-19207.02517767.254.98897610.461917132.05636625.7115298.19290432.443573157.8804938.777742NaN289790048748008187500626887653144002935400053312700.033909920022326000
2022-04-20207.98808367.004.96901910.642295133.02737425.9564008.24225832.942707161.8152168.7295142840200.0252120067467004755600345713852507002511570035610600.059318780018619400
2023-04-03213.00000071.505.80000010.336239154.00000029.7500008.90000039.500000226.0000007.1000005468900.014322007188400324900091926001747300202528000.09364830023346800
2023-04-04213.00000071.755.80000010.243119154.50000030.5000008.95000038.500000227.0000007.2000005276900.01496500775830016194002822900245620055614000.023083020029583900
2023-04-05209.00000071.755.70000010.056881153.00000030.2500009.00000039.500000229.0000007.1500007396900.09428004718700506830013217100649840067460000.017895100040425800
2023-04-07210.00000072.005.60000010.150000153.00000030.0000008.95000039.250000230.0000007.4000008880400.0832800757460013312002765700463360032558000.026754080016634400
2023-04-10212.00000072.255.75000010.150000154.50000030.5000008.95000040.000000235.0000007.6500005404495.055407647182042070053177442252743154351727414147134.03473731313789732

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 CloseCloseHighLowOpenVolume
DateStock
2022-04-11ADVANC.BK215.691345224.0226.0223.0225.03504800.0
2022-04-12ADVANC.BK214.728439223.0225.0221.0222.02646900.0
2022-04-18ADVANC.BK212.802612221.0223.0219.0223.05392900.0
2022-04-19ADVANC.BK207.025177215.0223.0214.0222.09313500.0
2022-04-20ADVANC.BK207.988083216.0220.0215.0215.07284200.0
2023-04-03TU.BK13.80000013.814.213.814.123346800.0
2023-04-04TU.BK13.60000013.613.913.513.829583900.0
2023-04-05TU.BK13.20000013.213.713.213.640425800.0
2023-04-07TU.BK13.20000013.213.413.213.316634400.0
2023-04-10TU.BK13.30000013.313.513.213.213789732.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_9MACDh_12_26_9MACDs_12_26_9
Stock
ADVANC.BKNaNNaNNaN
ADVANC.BKNaNNaNNaN
ADVANC.BKNaNNaNNaN
ADVANC.BKNaNNaNNaN
ADVANC.BKNaNNaNNaN
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

StockAdj CloseCloseHighLowOpenVolumeMACD_12_26_9MACDh_12_26_9MACDs_12_26_9
Date
2022-04-11ADVANC.BK215.691345224.0226.0223.0225.03504800.0NaNNaNNaN
2022-04-12ADVANC.BK214.728439223.0225.0221.0222.02646900.0NaNNaNNaN
2022-04-18ADVANC.BK212.802612221.0223.0219.0223.05392900.0NaNNaNNaN
2022-04-19ADVANC.BK207.025177215.0223.0214.0222.09313500.0NaNNaNNaN
2022-04-20ADVANC.BK207.988083216.0220.0215.0215.07284200.0NaNNaNNaN
2023-04-03TU.BK13.80000013.814.213.814.123346800.0-0.380704-0.023116-0.357587
2023-04-04TU.BK13.60000013.613.913.513.829583900.0-0.417789-0.048162-0.369628
2023-04-05TU.BK13.20000013.213.713.213.640425800.0-0.473993-0.083492-0.390501
2023-04-07TU.BK13.20000013.213.413.213.316634400.0-0.512626-0.097700-0.414926
2023-04-10TU.BK13.30000013.313.513.213.213789732.0-0.529074-0.091319-0.437756

12096 rows × 10 columns


Rename the columns for better readability:


df4=df3.loc['2022-08-05']
df4


StockAdj CloseCloseHighLowOpenVolumeMACD_12_26_9MACDh_12_26_9MACDs_12_26_9
Date
2022-08-05ADVANC.BK194.507385202.000000203.000000201.000000203.0002602200.0-0.8565130.294622-1.151134
2022-08-05AOT.BK71.75000071.75000071.75000071.00000071.75021971500.0-0.0818350.340664-0.422499
2022-08-05AWC.BK5.0000005.0000005.1000005.0000005.10045309700.0-0.1658790.107002-0.272881
2022-08-05BANPU.BK11.54418412.80000012.90000012.40000012.700178069500.00.144754-0.0186620.163416
2022-08-05BBL.BK132.532852134.000000134.000000132.000000132.5006410800.00.7217690.2102680.511500
2022-08-05BDMS.BK26.44614227.00000027.25000026.75000027.25052557700.00.0000310.198562-0.198531
2022-08-05BEM.BK8.7851618.9000008.9500008.8000008.90038909200.0-0.0361020.067209-0.103311
2022-08-05BGRIM.BK38.68272038.75000040.00000038.25000040.00023528900.01.0281560.0352080.992948
2022-08-05BH.BK179.029587182.000000184.000000181.000000184.0001962100.01.456043-0.4266711.882714
2022-08-05BTS.BK8.4508688.6000008.6500008.5500008.60022088700.0-0.6497170.305738-0.955455
2022-08-05CBG.BK111.864189113.500000114.500000113.000000113.5001640200.01.525211-0.0929681.618179
2022-08-05COM7.BK32.70238133.50000034.00000032.25000032.75026999300.00.2879470.786764-0.498816
2022-08-05CPALL.BK60.00000060.00000060.25000059.75000059.75012652600.0-0.410506-0.134523-0.275983
2022-08-05CPF.BK24.41475724.79999925.25000024.79999925.00019225300.0-0.404668-0.018700-0.385968
2022-08-05CPN.BK63.87170065.00000065.25000064.00000065.2506587100.01.2914910.3548650.936626
2022-08-05CRC.BK38.00000038.00000038.25000037.50000037.50013405600.00.4954920.3385420.156950
2022-08-05DTAC.BK45.61497546.75000047.25000046.00000046.00013830500.00.3085920.0529200.255672
2022-08-05EA.BK81.68155782.00000083.25000082.00000083.0004059700.00.0946770.483959-0.389282
2022-08-05EGCO.BK177.501480184.500000186.500000183.000000186.5001333400.02.561365-0.3640212.925386
2022-08-05GLOBAL.BK17.52208517.75999817.95200017.66400017.9523141354.0-0.4467440.377365-0.824108
2022-08-05GPSC.BK69.98613770.50000071.00000069.50000071.00010314500.01.2852590.3030100.982249
2022-08-05GULF.BK48.19285648.75000049.50000048.50000049.25023724500.00.2295280.2135500.015977
2022-08-05HMPRO.BK13.33951113.50000013.60000013.40000013.50033188400.0-0.0737480.142847-0.216595
2022-08-05INTUCH.BK67.86466272.25000072.75000071.75000072.7501046400.00.7130900.1168700.596220
2022-08-05IRPC.BK3.2460463.3200003.3200003.2800003.30028322400.0-0.1966260.123611-0.320237
2022-08-05IVL.BK42.20521243.00000044.00000042.75000044.00027382300.0-0.667181-0.085784-0.581397
2022-08-05KBANK.BK146.513245147.000000147.500000144.500000145.00016607200.00.0277850.429325-0.401540
2022-08-05KCE.BK63.23059565.25000065.75000065.00000065.7506052000.01.2857981.320024-0.034226
2022-08-05KTB.BK16.00000016.00000016.00000015.80000015.80030308400.00.0904900.128446-0.037956
2022-08-05KTC.BK58.50000058.50000059.00000058.25000058.7502876100.00.4171290.464354-0.047226
2022-08-05LH.BK8.4083808.6500008.7000008.6000008.65018001300.0-0.0757860.127073-0.202859
2022-08-05MINT.BK33.50000033.50000034.00000033.00000034.00011301400.00.0936140.0688020.024812
2022-08-05MTC.BK50.50000050.50000051.25000050.25000051.0007803200.01.6550340.6413601.013674
2022-08-05OR.BK26.46911827.00000027.00000026.50000026.75023073500.00.1576250.205681-0.048055
2022-08-05OSP.BK31.30000131.75000031.75000031.25000031.5006439800.0-0.625802-0.092757-0.533046
2022-08-05PTT.BK33.49512535.50000035.50000034.50000034.75053854700.00.1030580.188528-0.085470
2022-08-05PTTEP.BK142.485611151.000000152.500000149.500000152.00027671000.0-0.662412-0.7395820.077170
2022-08-05PTTGC.BK44.28584345.25000045.50000044.00000044.75010155500.0-0.4382500.347540-0.785790
2022-08-05RATCH.BK37.01569738.50000039.00000038.25000038.5005418500.0-0.0022680.054583-0.056850
2022-08-05SAWAD.BK53.50000053.50000053.50000052.75000053.2506020300.00.8516550.6413730.210281
2022-08-05SCB.BK102.000000103.500000103.500000101.000000101.00014923300.0-0.0991840.913495-1.012679
2022-08-05SCC.BK358.740265367.000000368.000000366.000000367.0001896800.0-0.544546-1.4273130.882767
2022-08-05SCGP.BK54.83189055.50000056.00000055.00000055.75013283300.0-1.1197980.631380-1.751178
2022-08-05STGT.BK15.68407716.20000116.70000116.20000116.50010841100.0-0.2909350.133474-0.424409
2022-08-05TIDLOR.BK30.00000030.00000030.50000030.00000030.50012373100.00.0503440.423401-0.373056
2022-08-05TISCO.BK89.50000089.50000089.75000089.25000089.2503243000.00.3918250.2262630.165562
2022-08-05TOP.BK47.70791651.00000051.50000050.25000051.50013279300.0-0.4528420.349862-0.802703
2022-08-05TRUE.BK5.0000005.0000005.0500004.9000004.900366377200.0-0.0836470.097325-0.180973
2022-08-05TTB.BK1.1514291.1700001.1900001.1700001.180249877600.0-0.0299880.013520-0.043507
2022-08-05TU.BK15.77994416.60000016.60000016.40000016.5005566800.00.0117970.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.