-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_testing.py
More file actions
89 lines (73 loc) · 2.74 KB
/
api_testing.py
File metadata and controls
89 lines (73 loc) · 2.74 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import requests
import json
import pandas as pd
import os
import urllib
############################
import time
from collections import deque, namedtuple
from keras.models import Sequential
from keras.layers import Dense, LSTM, Dropout
import numpy as np
import PIL.Image
import tensorflow as tf
import utils
from pyvirtualdisplay import Display
from keras import Sequential
from keras.losses import MSE
from keras.optimizers import Adam
####################
import numpy as np
import pandas as pd
from pandas_datareader import data
import matplotlib.pyplot as plt
import datetime as dt
import os
import urllib.request, json
import tensorflow as keras # Use the official 'tensorflow' package instead of 'keras'
from keras.models import Sequential
from keras.layers import Dense, LSTM, Dropout
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from keras.activations import sigmoid
from keras.callbacks import ModelCheckpoint, EarlyStopping
from keras.models import load_model
from keras import layers
from keras.layers import LSTM, Dropout, Dense, Input
from keras.models import Model
import pandas_ta as ta
from sklearn.model_selection import TimeSeriesSplit
from sklearn.metrics import mean_squared_error
from math import sqrt
import pandas_market_calendars as mcal
from sklearn.model_selection import KFold
from sklearn.preprocessing import StandardScaler
# Your API Key
api_key = '<RR02P5TH2UNCD10X>'
# Stock ticker symbol
ticker = "AAPL"
# Define the API endpoints
daily_time_series_url = f"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol={ticker}&outputsize=full&apikey={api_key}"
overview_url = f"https://www.alphavantage.co/query?function=OVERVIEW&symbol={ticker}&apikey={api_key}"
# Fetch the data from each endpoint
daily_time_series_response = requests.get(daily_time_series_url)
overview_response = requests.get(overview_url)
# Convert the responses to JSON
daily_time_series_data = daily_time_series_response.json()
overview_data = overview_response.json()
# Extract the time series data into a DataFrame
time_series_data = daily_time_series_data['Time Series (Daily)']
time_series_df = pd.DataFrame.from_dict(time_series_data, orient='index')
time_series_df.index.name = 'Date'
time_series_df.reset_index(inplace=True)
# Convert the overview data into a DataFrame
overview_df = pd.DataFrame([overview_data])
# Repeat the overview data to match the length of the time series data
overview_df = pd.concat([overview_df]*len(time_series_df), ignore_index=True)
# Concatenate the DataFrames horizontally
result_df = pd.concat([time_series_df, overview_df], axis=1)
# Save the DataFrame to a CSV file
result_df.to_csv('stock_market_data-%s.csv'%ticker, index=False)
df = (result_df)
print(df)
print(len(df))