Skip to main content

Posts

Showing posts with the label Python for Data Science

NSE Stock Fundamental Analysis in Python

 NSE Stock Fundamental Analysis in Python with yfinance library. Here is the full code: import random import time from tqdm import tqdm import yfinance as yf import pandas as pd from datetime import datetime, timedelta def get_nifty50_symbols():     nifty50_symbols = ["ACC", "PRSMJOHNSN", "AETHER"]     return [symbol + ".NS" for symbol in nifty50_symbols] def get_all_indian_stocks():     # Fetch list of Indian Stocks     url = f".\\Nifty_Stocks_Anaysis.csv"     df = pd.read_csv(url)     symbols = df['SYMBOL'].tolist()     return [symbol + ".NS" for symbol in symbols] def get_stock_data(symbol):     stock = yf.Ticker(symbol)     # Get price data     end_date = datetime.now()     start_date = end_date - timedelta(days=365)     price_data = stock.history(start=start_date, end=end_date)     if price_data.empty:         return None   ...

Compare Stock data in Python and Compare using charts

 Here is a program which compare the multiple stock/equity data using python and plot a graph for there performances for more than one year date range. I have used NSE stocks data such as Reliance, ITC and TCS companies stock data to do the comparison. First you need to install the Yahoo finance using following command: pip install yahoo-finance Please find the below code for the stock comparsion: # Import yfinance package import yfinance as yf import matplotlib.pyplot as plt # Get the data for the SPY (an ETF on the S&P 500 index) and the stock Apple by specifying the stock ticker, start date, and end date data = yf.download(['RELIANCE.NS', 'ITC.NS', 'TCS.NS'],'2022-01-01','2023-03-18') # Plot the adjusted close prices data["Adj Close"].plot() plt.show() Output for code is:

Get Stock data using python and plot a graph for stock analysis using python

 Below is the program to guide you how to get then Stock data using python and plot a graph for stock analysis using python. I took the NSE stock data using python. I used yahoo finance for the same. First you need to install Yahoo finance using following command: pip install yahoo-finance The below is the code: # Import yfinance package import yfinance as yf import matplotlib.pyplot as plt # Set the start and end date start_date = '2022-01-01' end_date = '2023-03-18' # Set the ticker ticker = 'HDFCBANK.NS' # Get the data data = yf.download(ticker, start_date, end_date) print(data) data.tail() # Plot adjusted close price data data['Adj Close'].plot() plt.show() # Plot the adjusted close price data['Adj Close'].plot(figsize=(10, 7)) # Define the label for the title of the figure plt.title("Adjusted Close Price of %s" % ticker, fontsize=16) # Define the labels for x-axis and y-axis plt.ylabel('Price', fontsize=14) plt.xlabel('...

complete file compare software in python with classification

complete file compare software in python with classification In previous article i have posted code for file comapre in python in this article i have have modified the code a lot. It is full working code. Kindly verify and revert if you like it. Also i have classified the records which are old ones and which are from new one in difference file. from tkinter import filedialog from tkinter import * import os window = Tk() window.title("My File Compare...") window.geometry('750x200') lbl1 = Label(window, text="Select Old File Path") lbl1.grid(column=0, row=0) txt1 = Entry(window,width=80) txt1.grid(column=1, row=0) lbl2 = Label(window, text="Select new File Path") lbl2.grid(column=0, row=2) txt2 = Entry(window,width=80) txt2.grid(column=1, row=2) def browsefunc1():     filename = filedialog.askopenfilename(initialdir = "D:/QA/")     print(filename)     txt1.delete(0,END)     txt1.insert(0,filena...

Complete file compare tool/software in python

Beyondcompare project in python  File compare tool/software in python. It works like beyondcompare software. It is a file compare project made by me. Kindly go through the code. It selects the files dynamically using file dialogue option using button. The file absolute path is seen on textboxes and the compare button generates the difference between two files are prints difference in the third file. The GUI is made in 'tkinter' library of python. In the below mentioned program/project you will learn  1) how to design GUI in python 2) how to reply to button click events 3) how to bind the values(input of file dialogue from user) to textboxes 4) how to use file dialogue 5) how to get directory path using full file path 6) how to get file name from full file path 7) logic to find the difference between two files Below is the code in which user selects 2 different files as a input and it will generate the difference and finally print the difference in an...

Compare two text files in python and print the difference in third file

Compare two text files in python and print the difference in third file Below is the code which takes 2 text files as a input and it will generate the difference(in csv or comma separated file) and finally print the difference in the third file. I have developed this for excel like record file. The code works for as many numbers of records or huge text data. Also the program execution is very faster. Here is the code: import os # Read in the original and new file          old = open(OLD_FILE_PATH,'r') new = open(NEW_FILE_PATH,'r') #in new but not in old new_extra = set(new) - set(old) # To see results in console if desired print('-------------------------------------------new file extra records------------------------------------------------------------') print(new_extra) # Write to header to csv file with open(NEW_FILE_PATH) as f1:     first_line1 = f1.readline()            with open(NEW_FILE_P...

MatPlotLib Complete Tutorial

# MatPlotLib Basics for drawing all kinds of graphs with all examples. ## Draw a line graph %matplotlib inline from scipy.stats import norm import matplotlib.pyplot as plt import numpy as np x = np.arange(-5, 5,0.1) plt.plot(x, norm.pdf(x)) plt.show() ## Mutiple Plots on One Graph plt.plot(x, norm.pdf(x)) plt.plot(x, norm.pdf(x, 3.0, 1)) plt.plot(x, norm.pdf(x, 2.0,1)) plt.show() ## Save it to a File plt.plot(x, norm.pdf(x)) plt.plot(x, norm.pdf(x, 1.0, 0.5)) plt.plot(x, norm.pdf(x, 2.0, 0.3)) plt.savefig('C:/Users/Antrixsh/Desktop/neeraj.pdf', format='pdf') ## Adjust the Axes axes = plt.axes() axes.set_xlim([-5, 5.0]) axes.set_ylim([0, 2.0]) axes.set_xticks([-5, -4, -3, -2, -1, 0, 1, 1.5, 2, 3, 4, 5]) axes.set_yticks([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0,1.1,1.2,1.3,1.4]) #axes.set_xT([-5, 5.0]) #axes.set_yt([0, 1.0]) axes.grid() plt.plot(x, norm.pdf(x)) plt.plot(x, norm.pdf(x, 1, 0.5)) plt.plot(x, norm.pdf...