File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22import yfinance as yf
33import matplotlib .pyplot as plt
44
5- ticker = input ('Stock Symbol: ' )
6- start_date = input ('Start Date (YYYY-MM-DD): ' )
7- end_date = input ('End Date (YYYY-MM-DD): ' )
8-
9- stock = yf .Ticker (ticker )
10- df = stock .history (start = start_date , end = end_date )
11-
12- plt .figure (figsize = (14 , 8 ))
13- plt .plot (df ['Close' ])
14- plt .title (f'{ ticker } Stock Price' )
15- plt .xlabel ('Date' )
16- plt .ylabel ('Price (USD)' )
17- plt .grid ()
18- plt .show ()
5+ def get_df (ticker , start_date , end_date ):
6+ stock = yf .Ticker (ticker )
7+ df = stock .history (start = start_date , end = end_date )
8+ return df
9+
10+ def plot (df , ticker ):
11+ plt .figure (figsize = (14 , 8 ))
12+ plt .plot (df ['Close' ])
13+ plt .title (f'{ ticker } Stock Price' )
14+ plt .xlabel ('Date' )
15+ plt .ylabel ('Price (USD)' )
16+ plt .grid ()
17+ plt .show ()
18+
19+ def user_input ():
20+ ticker = input ('Stock Symbol: ' )
21+ start_date = input ('Start Date (YYYY-MM-DD): ' )
22+ end_date = input ('End Date (YYYY-MM-DD): ' )
23+ return ticker , start_date , end_date
24+
25+ def stock_visualizer ():
26+ ticker , start_date , end_date = user_input ()
27+ df = get_df (ticker , start_date , end_date )
28+ plot (df , ticker )
29+
30+
31+
32+
1933
Original file line number Diff line number Diff line change 1+ import yfinance as yf
2+ from stock import (
3+ get_df ,
4+ plot ,
5+ user_input ,
6+ stock_visualizer
7+ )
8+
9+ def test_df ():
10+ stock = yf .Ticker ("MSFT" )
11+ assert (get_df (stock , "2023-01-01" , "2023-02-01" ) != None )
12+
13+ def test_plot ():
14+ stock = yf .Ticker ("MSFT" )
15+ df = get_df (stock , "2023-01-01" , "2023-02-01" )
16+ assert (plot (df , stock ) != None )
17+
18+
You can’t perform that action at this time.
0 commit comments