Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Unlock Financial Insights with FinancialFreedom
- # 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.
- # 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.
- # Import necessary libraries
- import sqlite3
- from googlesearch import search
- import yfinance as yf
- import datetime
- # Initialize SQLite database
- conn = sqlite3.connect('financial_data.db')
- c = conn.cursor()
- c.execute('''CREATE TABLE IF NOT EXISTS stocks(
- id INTEGER PRIMARY KEY,
- symbol TEXT,
- price REAL,
- date TEXT)''')
- # Function to query and parse financial data
- def query_stock_data(query):
- results = search(query, num=1, stop=1)
- for url in results:
- stock_symbol = url.split('/')[-1].split(':')[0]
- stock_info = yf.Ticker(stock_symbol)
- hist = stock_info.history(period="1d")
- current_price = hist['Close'][0]
- date = https://t.co/2SOskHf38t().strftime("%Y-%m-%d")
- check_price_change_and_update_database(stock_symbol, current_price, date)
- # Function to check price change and update database
- def check_price_change_and_update_database(symbol, price, date):
- c.execute("SELECT price FROM stocks WHERE symbol=?", (symbol,))
- previous_price = c.fetchone()
- if previous_price:
- previous_price = previous_price[0]
- if price != previous_price:
- print(f"{symbol} price change detected! Previous price: {previous_price}, Current price: {price}")
- c.execute("UPDATE stocks SET price=?, date=? WHERE symbol=?", (price, date, symbol))
- else:
- print(f"{symbol} price remains the same. No change detected.")
- else:
- print(f"Adding {symbol} to the database with price: {price}")
- c.execute("INSERT INTO stocks (symbol, price, date) VALUES (?, ?, ?)", (symbol, price, date))
- conn.commit()
- # Function to analyze price change probability
- def analyze_price_change_probability():
- c.execute("SELECT symbol, price, date FROM stocks")
- data = c.fetchall()
- increase_count = 0
- total_count = 0
- for row in data:
- total_count += 1
- symbol, price, date = row
- if price > 65:
- increase_count += 1
- probability = (increase_count / total_count) * 100
- print(f"The probability of stocks/crypto with price > 65% likely to increase: {probability:.2f}%")
- # Help menu with examples
- def help_menu():
- print("Welcome to the Financial Data Tool!\n")
- print("Usage:")
- print("python financial_data_tool.py <action> <query>\n")
- print("Actions:")
- print("- query: Query financial data for a specific stock or cryptocurrency")
- print("- analyze: Analyze the probability of price increase for stocks/cryptocurrency\n")
- print("Examples:")
- print("Query financial data for Apple Inc. stock:\n python financial_data_tool.py query 'Apple Inc. stock'")
- print("Analyze the probability of price increase:\n python financial_data_tool.py analyze")
- # Main execution
- if __name__ == '__main__':
- import sys
- if len(sys.argv) < 3:
- help_menu()
- else:
- action = sys.argv[1]
- query = ' '.join(sys.argv[2:])
- if action == 'query':
- query_stock_data(query)
- elif action == 'analyze':
- analyze_price_change_probability()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement