forked from androodle/Project_3a_alv2y3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StockDataAnalyzer.py
28 lines (21 loc) · 777 Bytes
/
StockDataAnalyzer.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
import pandas as pd
from alpha_vantage.timeseries import TimeSeries
def get_data(symbol, api_key, time_series):
ts = TimeSeries(key=api_key, output_format='pandas')
try:
data, _ = ts.get_daily(symbol=symbol, outputsize='full') # Simplified for testing
except Exception as e:
print(f"API call error: {e}")
return None
if data.empty:
print(f"No data available for symbol {symbol}")
return None
return data
def filter_by_date_range(data, start_date, end_date):
start_date = pd.to_datetime(start_date)
end_date = pd.to_datetime(end_date)
data = data.sort_index()
return data.loc[start_date:end_date]
def get_stock_symbols(filename):
df = pd.read_csv(filename)
return df['Symbol'].tolist()