Spaces:
Sleeping
Sleeping
Update space_stock_plot.py
Browse files- space_stock_plot.py +7 -4
space_stock_plot.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
'''
|
| 2 |
graphical line diagram of stock cumulative returns
|
| 3 |
-
|
| 4 |
Note: Raw Data is from Yahoo Finance using python yfinance
|
| 5 |
'''
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Import the libraries
|
| 8 |
import gradio as gr
|
| 9 |
import yfinance as yf
|
|
@@ -11,7 +14,8 @@ import pandas as pd
|
|
| 11 |
|
| 12 |
def stock_return_df(tickers, start, end):
|
| 13 |
# Download the historical data
|
| 14 |
-
data = yf.download(tickers, start=start, end=end)
|
|
|
|
| 15 |
# Calculate the daily and cumulative percentage change
|
| 16 |
data_adj_close = data['Adj Close']
|
| 17 |
data_adj_close_pct = data_adj_close.pct_change()
|
|
@@ -41,4 +45,3 @@ interface = gr.Interface(
|
|
| 41 |
# Launch the interface
|
| 42 |
interface.launch(debug=False)
|
| 43 |
|
| 44 |
-
|
|
|
|
| 1 |
'''
|
| 2 |
graphical line diagram of stock cumulative returns
|
|
|
|
| 3 |
Note: Raw Data is from Yahoo Finance using python yfinance
|
| 4 |
'''
|
| 5 |
+
# versions:
|
| 6 |
+
# 2024-01-28.1: creation of the file
|
| 7 |
+
# 2025-0223-1104: yf.download default changed to auto_adjust=True at yfinance version 0.2.54,
|
| 8 |
+
# when auto_adjust=True, Close = Adj Close and Adj Close does not exist
|
| 9 |
+
script_version = '(2025-0223-1104)'
|
| 10 |
# Import the libraries
|
| 11 |
import gradio as gr
|
| 12 |
import yfinance as yf
|
|
|
|
| 14 |
|
| 15 |
def stock_return_df(tickers, start, end):
|
| 16 |
# Download the historical data
|
| 17 |
+
data = yf.download(tickers, start=start, end=end, auto_adjust=False) # yf.download default changed to auto_adjust=True at yfinance version 0.2.54,
|
| 18 |
+
# when auto_adjust=True, Close = Adj Close and Adj Close does not exist
|
| 19 |
# Calculate the daily and cumulative percentage change
|
| 20 |
data_adj_close = data['Adj Close']
|
| 21 |
data_adj_close_pct = data_adj_close.pct_change()
|
|
|
|
| 45 |
# Launch the interface
|
| 46 |
interface.launch(debug=False)
|
| 47 |
|
|
|