This commit is contained in:
William Wang 2023-05-06 23:26:45 -04:00
parent 05bd8134f2
commit e621542883
2 changed files with 44 additions and 12 deletions

View File

@ -2,18 +2,32 @@ import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt
ticker = input('Stock Symbol: ')
start_date = input('Start Date (YYYY-MM-DD): ')
end_date = input('End Date (YYYY-MM-DD): ')
def get_df(ticker, start_date, end_date):
stock = yf.Ticker(ticker)
df = stock.history(start=start_date, end=end_date)
return df
def plot(df, ticker):
plt.figure(figsize=(14, 8))
plt.plot(df['Close'])
plt.title(f'{ticker} Stock Price')
plt.xlabel('Date')
plt.ylabel('Price (USD)')
plt.grid()
plt.show()
def user_input():
ticker = input('Stock Symbol: ')
start_date = input('Start Date (YYYY-MM-DD): ')
end_date = input('End Date (YYYY-MM-DD): ')
return ticker, start_date, end_date
def stock_visualizer():
ticker, start_date, end_date = user_input()
df = get_df(ticker, start_date, end_date)
plot(df, ticker)
stock = yf.Ticker(ticker)
df = stock.history(start=start_date, end=end_date)
plt.figure(figsize=(14, 8))
plt.plot(df['Close'])
plt.title(f'{ticker} Stock Price')
plt.xlabel('Date')
plt.ylabel('Price (USD)')
plt.grid()
plt.show()

View File

@ -0,0 +1,18 @@
import yfinance as yf
from stock import (
get_df,
plot,
user_input,
stock_visualizer
)
def test_df():
stock = yf.Ticker("MSFT")
assert (get_df(stock, "2023-01-01", "2023-02-01") != None)
def test_plot():
stock = yf.Ticker("MSFT")
df = get_df(stock, "2023-01-01", "2023-02-01")
assert(plot(df, stock) != None)