No project description provided
Project description
Stock & Financial Data Analysis Script
This Python script allows you to fetch, analyze, and display stock-related information for various tickers. The script leverages the yfinance library to retrieve stock data, calculates technical indicators like EMA (Exponential Moving Average) and RSI (Relative Strength Index), and provides detailed market information such as bid/ask prices, volume, market cap, and more.
Created by: Francesco Vito Giotta (LemonPower21)
This library was created by Francesco Vito Giotta to provide a set of tools for financial analysis using Python. It leverages the yfinance and ta libraries for retrieving stock data, calculating technical indicators, and sending email notifications.
Features
- Stock Data Retrieval: Fetches live stock data (bid, ask, volume, etc.) for a given ticker symbol.
- Technical Indicators: Computes key technical indicators like RSI, EMA, and ATH (All-Time High).
- Market Information: Provides details such as market cap, shares outstanding, exchange, currency, etc.
- Real-time Alerts: Optionally sends alerts or logs when certain conditions are met.
- Email Notifications: Sends email alerts with detailed data logs attached.
- Customizable Output: Displays stock information in a user-friendly formatted table.
Requirements
- Python 3.x
yfinancelibraryta(technical analysis library)smtplibfor sending emailscoloramafor colored output in the terminal
You can install the required libraries by running the following:
pip install yfinance ta colorama
Functions
bid(ticker)
- Purpose: Retrieves the current bid price for the specified stock ticker.
- Returns: The bid price (float) or
0if unavailable.
ask(ticker)
- Purpose: Retrieves the current ask price for the specified stock ticker.
- Returns: The ask price (float) or
0if unavailable.
start()
- Purpose: Records the start time for calculating the elapsed time.
stop(start)
- Purpose: Calculates and returns the elapsed time since the provided
starttime. - Returns: Elapsed time in years, months, days, hours, minutes, and seconds.
log(text)
- Purpose: Logs events to a file (
log.txt). - Returns: None.
last(ticker)
- Purpose: Retrieves the last closing price for the specified ticker.
- Returns: The last closing price (float) or
Noneif unavailable.
rsi(ticker, periods, chart, timeframe)
- Purpose: Calculates the RSI (Relative Strength Index) for the specified ticker.
- Returns: The RSI value (float) or
Noneif unavailable.
ema(ticker, periods, chart, timeframe)
- Purpose: Calculates the Exponential Moving Average (EMA) for the specified ticker.
- Returns: The EMA value (float) or
Noneif unavailable.
clean()
- Purpose: Clears the terminal screen (cross-platform support).
email(server, port, user, password, recipient, subject, body)
- Purpose: Sends an email with the log file attached.
- Returns: None.
ychart(ticker)
- Purpose: Opens the Yahoo Finance chart for the specified ticker in a browser.
- Returns: None.
ynews()
- Purpose: Opens the Yahoo Finance news page in a browser.
- Returns: None.
change(pair)
- Purpose: Retrieves the exchange rate for a given currency pair against EUR.
- Returns: Exchange rate (float) or
Noneif unavailable.
ath(ticker)
- Purpose: Retrieves the All-Time High (ATH) for the specified ticker.
- Returns: ATH value (float) or
Noneif unavailable.
currency(ticker)
- Purpose: Retrieves the currency used by the stock ticker.
- Returns: Currency symbol (e.g., USD, EUR) or
Noneif unavailable.
exchange(ticker)
- Purpose: Retrieves the exchange name for the specified ticker.
- Returns: Exchange name (string) or
Noneif unavailable.
volume(ticker)
- Purpose: Retrieves the real-time market volume for the specified ticker.
- Returns: Volume (integer) or
Noneif unavailable.
marketcap(ticker)
- Purpose: Retrieves the market capitalization for the specified ticker.
- Returns: Market cap (float) or
Noneif unavailable.
shares(ticker)
- Purpose: Retrieves the shares outstanding for the specified ticker.
- Returns: Shares outstanding (integer) or
Noneif unavailable.
invested(qty, buyprice)
- Purpose: Calculates the total amount invested based on the quantity and buy price.
- Returns: Investment amount (float) or
Noneif unavailable.
roi(buyprice, lastprice)
- Purpose: Calculates the Return on Investment (ROI) percentage based on the buy price and last price.
- Returns: ROI percentage (float) or
Noneif unavailable.
pandl(roiperc, invested)
- Purpose: Calculates the profit or loss based on the ROI percentage and investment.
- Returns: Profit or loss (float) or
Noneif unavailable.
initprint()
- Purpose: Initializes the table header for formatted output in the terminal.
- Returns: None.
printall(...)
- Purpose: Prints detailed stock information including price, indicators, market data, and elapsed time in a formatted table.
- Returns: None.
Usage Example
Here's how to use the script:
-
Get stock data:
Call the functions for your desired ticker, e.g.,bid('AAPL')orrsi('AAPL', 14, '1d', '5m'). -
Track a stock's performance:
Useprintall(...)to display the stock's information in a table format. -
Email log:
Use theemail(...)function to send an email with the logs attached. -
View charts and news:
Useychart()andynews()to view the latest stock charts and news.
Example Output
Ticker Exchange Currency Change Quantity Invested Buy Last TP(%) P&L(%) P&L(€) EMA RSI ATH Bid Ask Spread Shares Volume MarketCap Elapsed time
AAPL NASDAQ USD 0.0056 100 15000.00 150.00 153.20 2.00 2.14 320.00 150.10 45.32 157.89 152.50 153.50 1.00 1000 50000 2.5B 1Y, 2M, 3d, 4h, 5m, 6.00s
Conclusion
This script is a powerful tool for analyzing and tracking stock market data in real-time. With easy-to-use functions for retrieving financial data, computing technical indicators, and generating reports, it's a great resource for traders, analysts, and developers alike.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gfinancelib-2.11.tar.gz.
File metadata
- Download URL: gfinancelib-2.11.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78dd57779189cb3ccecfb54f7048a490ce2a359aea79c25339b28396ce51093d
|
|
| MD5 |
6a9267b788777bf96666716d19f05663
|
|
| BLAKE2b-256 |
5df416600834d0d1299ea00e8f24d8f9ec5a1be6012186ba0f9d7f9b2c1e6521
|
File details
Details for the file gfinancelib-2.11-py3-none-any.whl.
File metadata
- Download URL: gfinancelib-2.11-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beed9925e1ffc03753b28481ce569020162a5d197eb81fe948d99f495b244cc9
|
|
| MD5 |
8cf56b6c33a6f17839f6666343ead570
|
|
| BLAKE2b-256 |
19b94c535cb695b37c1203ba21e6e6ade5e6c24286c67072ee4debc582c86d14
|