-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
stock.py
33 lines (26 loc) · 929 Bytes
/
stock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This code is made by MRayan Asim
# Packages needed:
# pip install yfinance
import yfinance as yf
# Function to fetch stock information
def get_stock_info(symbol):
stock = yf.Ticker(symbol)
# Get stock info
info = stock.info
# Extract desired information
current_price = stock.history().tail(1)["Close"].iloc[0]
market_cap = info.get("marketCap", "N/A")
volume = info.get("regularMarketVolume", "N/A")
previous_close = info.get("previousClose", "N/A")
high = info.get("dayHigh", "N/A")
low = info.get("dayLow", "N/A")
# Print the stock information
print(f"Stock Symbol: {symbol}")
print(f"Current Price: {current_price}")
print(f"Market Cap: {market_cap}")
print(f"Volume: {volume}")
print(f"Previous Close: {previous_close}")
print(f"Day's High: {high}")
print(f"Day's Low: {low}")
symbol = input("Enter the stock symbol: ")
get_stock_info(symbol)