Skip to main content

Posts

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   ...

MySQL connection in JAVA

 Below is the code for MySQL connection in JAVA import java.sql.Connection; import java.sql.DriverManager; public class TestMySql { public static Connection con = null; public static void main(String[] args) { try{   String host = "";         String uName = "";         String uPass= "";        Class.forName("com.mysql.cj.jdbc.Driver");   con = DriverManager.getConnection(host, uName, uPass); System.out.println("Connection Successful..."); con.close();   } catch(Exception e) {  System.out.println(e);}   } }

File Comparison in JAVA

Below is the code for File Comparison in JAVA:  import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException;   public class CompareTextFiles {     public static void main(String[] args) throws IOException     {         BufferedReader reader1 = new BufferedReader(new FileReader("C:\\FileCompare\\File1.txt"));                   BufferedReader reader2 = new BufferedReader(new FileReader("C:\\FileCompare\\File2.txt"));                   String line1 = reader1.readLine();                   String line2 = reader2.readLine();                   boolean areEqual = true;                   int lineNum = 1;                   while (line1 != null || li...

Multiple files creation logic in JAVA

  import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Multiple_Files_Creation_logic { public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub int totalCount = 1001; //userinput String filePath = "C:\\Users\\vmalge\\Desktop\\Test"; String fileName= "V_SHPT_OFR_MDCTEST4_"; String fileType = "csv"; File input = new File(filePath+fileName+"."+fileType);                   for(int counter = 1; counter < totalCount; counter++){     //int size = 250;     //tbd     File myFile = new File("C:\\Test\\result"+fileName+counter+"."+fileType);                                try { ...

Email monitoring in JAVA

 Email monitoring in JAVA. Here is the code: import java.util.Properties; import javax.activation.DataHandler; import javax.activation.DataSource; import javax.activation.FileDataSource; import javax.mail.Authenticator; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; public class MonitoringMail { //public static void sendMail(String mailServer, String from,String username, String password,String port, String[] to, String subject, String messageBody, String attachmentPath, String attachmentName) throws MessagingException, AddressException public void sendMail(String mailServer, String from, String[] to, String subject, String mess...

Excel operations in JAVA

 import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Calendar; import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFCreationHelper; import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.XSSFHyperlink; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelReader { public  String path; public  FileInputStream fis = null; public  FileOutputStream fi...

Generate Logs in Python

 Below is the code which will show how Logging is done in Python: import logging import time class Logger: def __init__ ( self , logger , file_level=logging.info): self .logger = logging.getLogger(logger) self .logger.setLevel(logging.INFO) """ self.logger.setLevel(logging.DEBUG) self.logger.setLevel(logging.INFO) self.logger.setLevel(logging.WARNING) self.logger.setLevel(logging.ERROR) self.logger.setLevel(logging.CRITICAL) """ fmt = logging.Formatter( '%(asctime)s - %(filename)s:[%(lineno)s] - [%(levelname)s] - %(message)s' ) curr_time = time.strftime( "%Y-%m-%d" ) self .LogFileName = '. \\ Logs \\ log' + curr_time + '.log' # "a" to append the logs in same file, "w" to generate new logs and delete old one fh = logging.FileHandler( self .LogFileName , mode = "a" ) fh.set...