Python for Stock Market Charts with yfinance & Matplotlib | Part-2 | #mlwithakansha #stockmarket #yt

Akansha Yadav shows how to fetch TCS stock data with yfinance and build charts in matplotlib: line charts, candlestick charts, volume bars, and histograms. She explains the code for each chart type and how to combine them into subplots for a complete dashboard view.
Chapters
Ladies and gentlemen, in the last video we have seen the basic graphs of stock market, which is candlestick chart, bar chart, colored chart, line chart, work text chart, and then step, and then mounting. So if you have not watched that video, you can go back to the pen icon and you will get the link of that video, which is part 1 of the stock market graphs video. So let's see the another thing in this video. This is the part 2 of that video. So in this we are going to see baseline, hollow, volume, colored, scatter, and histogram, that how we can create these graphs and how the stock market analysis looks with this graph. So the company is the same, we are analyzing the TCS company. I have already imported the data using yfinance library. I have imported the basic statistics of the company and I know the data now. Now I have the data in my file. Now what I have to do is I have to plot the graph. So for plotting the graphs, we are using the matplotlib library. To create a baseline chart, what I have done is I have plt.figure where I am defining the height and the width of the graph. Then plt.plot works with the closing value, and which I am defining the color as a black and line width is 1. Then I have defined title, x label, y label, grids I want, and then I'm printing it to show. So here I have the price-date baseline chart, and this is the graph which is in the black color, and I do have the grids in this. So another type of a graph that we have is the holo candle. Holo candle is something which looks like this, which is, uh, like earlier we were using the colored one, this is holo one. So I have defined— I'm defining the figure size, then I'm defining the title, then on this plot I want index onto the x-axis and then onto the y-axis, and then I want the closing value onto this, and then I have the color which is in the black, and I'm filling it up with the two values because I want index and then open value, close value. Where close value is greater than the stock data open value, I am considering it in the white color. And I have done the opposite of it, where the stock price closing price is less than the open, I am keeping it in the white color so that I can analyze it in the better way. Then I have defined the x-label and then the y-label. Over here you can see we do have a black color line which shows that the value, the closing price and the opening price. Another type of a graph is the volume candle. Volume candle is— for this I have defined the figure size, title, bar. I am using the bar 1 over here to define the volume. And here I am using the volume as a parameter because volume is one of the parameters in the stock market data which tells that what is the volume of the trading, that what, how many, uh, investors were there on that particular day to trade on that particular company. So on the basis of that, I have date and then volume, and then I'm looking forward for the grids as well. So I have made the grid as true. This is how our volume chart looks like, volume candles look like. Another one is the colored HCL bar. Colored HCL bar is something which will, which is also the colored bar similarly that we done in the part 1, but this is a bit different where we are filling it up with the index and then the closing price. And I have defined the color over here. Earlier it was 0.4, now it's 0.5. I'm plotting the closing price of the width of this stock data. Another is the scatter plot. Scatter plot is very simple that we used to do in the machine learning part or the data visualization. Same stock market, we are using the data is stock market, just that. And the plot is the plt.scatter, which will help you to plot the scatter plot. Another is the histogram, which is done using plt.hist. We are defining the bins, we are defining the colors. And here we go with the output. Now, as we have done earlier, we have created multiple separate graphs for analyzing it better. Or in the one go, what we are doing is we are creating the subplot of this, where which we are defining the figures and the axis. I do have the figures, and this is the size of the figure. And now I have the baselines. And now using the axis, I am defining the subplots. Earlier we were doing something else with— when we were plotting it, we were not defining any axis, we were just directly plotting it. We have taken the same code from above and we have plotted the graph. But this time I have made it bit different to make you learn something new, which is using the axis, how you can plot it. So I have used 1, uh, 0, 0. I will show you. So I have used 0, 0, 0, 1, 0, 2, 1, 0, up to 0, 2 only because I want 3 in line. So 1, 0, 1, 1, 1, 2, like this. So there will be 6 graphs like this. And that's how you can plot the subplots using the multiple graphs that you have. So this way you can analyze the stock market better using the yfinance library. Earlier, before 3.7 version of Python, there was one library called data reader library Pandas. So that library is not acceptable after 3.7 version. So we have new library which is yfinance library, which is extracting the data from the Yahoo Finance, like Yahoo Finance website. So I hope you like the video. Make sure to subscribe to the channel and comment down your views of what you want next into this series.










