Advertisement
xGHOSTSECx

Financial Freedom Bot

Dec 28th, 2023
1,682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.37 KB | None | 0 0
  1. # Unlock Financial Insights with FinancialFreedom
  2.  
  3. # FinancialFreedom is your key to unlocking valuable insights into the dynamic world of stocks and cryptocurrencies. Imagine effortlessly staying informed about the latest market trends, all at your fingertips. This Python tool seamlessly integrates with popular libraries to provide real-time data on stock prices. Through a user-friendly command-line interface, you can effortlessly query specific stocks or cryptocurrencies, receive instant updates on price changes, and even analyze the probability of price increases. FinancialFreedom empowers both seasoned investors and curious learners by making financial data accessible and actionable.
  4.  
  5. # This tool goes beyond traditional market tracking by dynamically retrieving and organizing data in a SQLite database. With its intuitive design, users can easily navigate through the command-line interface, executing actions like querying specific stocks or assessing the likelihood of price changes. FinancialFreedom simplifies financial data analysis, ensuring that you can make informed decisions in the ever-evolving landscape of stocks and cryptocurrencies. Explore the world of finance with confidence, armed with the insights provided by FinancialFreedom.
  6.  
  7. # Import necessary libraries
  8. import sqlite3
  9. from googlesearch import search
  10. import yfinance as yf
  11. import datetime
  12.  
  13. # Initialize SQLite database
  14. conn = sqlite3.connect('financial_data.db')
  15. c = conn.cursor()
  16. c.execute('''CREATE TABLE IF NOT EXISTS stocks(
  17.                id INTEGER PRIMARY KEY,
  18.                symbol TEXT,
  19.                price REAL,
  20.                date TEXT)''')
  21.  
  22. # Function to query and parse financial data
  23. def query_stock_data(query):
  24.     results = search(query, num=1, stop=1)
  25.     for url in results:
  26.         stock_symbol = url.split('/')[-1].split(':')[0]
  27.         stock_info = yf.Ticker(stock_symbol)
  28.         hist = stock_info.history(period="1d")
  29.         current_price = hist['Close'][0]
  30.         date = https://t.co/2SOskHf38t().strftime("%Y-%m-%d")
  31.         check_price_change_and_update_database(stock_symbol, current_price, date)
  32.  
  33. # Function to check price change and update database
  34. def check_price_change_and_update_database(symbol, price, date):
  35.     c.execute("SELECT price FROM stocks WHERE symbol=?", (symbol,))
  36.     previous_price = c.fetchone()
  37.     if previous_price:
  38.         previous_price = previous_price[0]
  39.         if price != previous_price:
  40.             print(f"{symbol} price change detected! Previous price: {previous_price}, Current price: {price}")
  41.             c.execute("UPDATE stocks SET price=?, date=? WHERE symbol=?", (price, date, symbol))
  42.         else:
  43.             print(f"{symbol} price remains the same. No change detected.")
  44.     else:
  45.         print(f"Adding {symbol} to the database with price: {price}")
  46.         c.execute("INSERT INTO stocks (symbol, price, date) VALUES (?, ?, ?)", (symbol, price, date))
  47.     conn.commit()
  48.  
  49. # Function to analyze price change probability
  50. def analyze_price_change_probability():
  51.     c.execute("SELECT symbol, price, date FROM stocks")
  52.     data = c.fetchall()
  53.     increase_count = 0
  54.     total_count = 0
  55.     for row in data:
  56.         total_count += 1
  57.         symbol, price, date = row
  58.         if price > 65:
  59.             increase_count += 1
  60.     probability = (increase_count / total_count) * 100
  61.     print(f"The probability of stocks/crypto with price > 65% likely to increase: {probability:.2f}%")
  62.  
  63. # Help menu with examples
  64. def help_menu():
  65.     print("Welcome to the Financial Data Tool!\n")
  66.     print("Usage:")
  67.     print("python financial_data_tool.py <action> <query>\n")
  68.     print("Actions:")
  69.     print("- query: Query financial data for a specific stock or cryptocurrency")
  70.     print("- analyze: Analyze the probability of price increase for stocks/cryptocurrency\n")
  71.     print("Examples:")
  72.     print("Query financial data for Apple Inc. stock:\n python financial_data_tool.py query 'Apple Inc. stock'")
  73.     print("Analyze the probability of price increase:\n python financial_data_tool.py analyze")
  74.  
  75. # Main execution
  76. if __name__ == '__main__':
  77.     import sys
  78.  
  79.     if len(sys.argv) < 3:
  80.         help_menu()
  81.     else:
  82.         action = sys.argv[1]
  83.         query = ' '.join(sys.argv[2:])
  84.  
  85.         if action == 'query':
  86.             query_stock_data(query)
  87.         elif action == 'analyze':
  88.             analyze_price_change_probability()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement