Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,9 @@ import requests
|
|
3 |
from Pandas_Market_Predictor import Pandas_Market_Predictor
|
4 |
import pandas as pd
|
5 |
|
|
|
|
|
|
|
6 |
def fetch_alpha_vantage_data(api_key):
|
7 |
url = f'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=IBM&interval=5min&apikey={api_key}'
|
8 |
response = requests.get(url)
|
@@ -12,34 +15,33 @@ def fetch_alpha_vantage_data(api_key):
|
|
12 |
def main():
|
13 |
st.title("Stock Trend Predictor")
|
14 |
|
15 |
-
#
|
16 |
-
api_key =
|
17 |
|
18 |
# Fetch Alpha Vantage data
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
del df
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
main()
|
|
|
3 |
from Pandas_Market_Predictor import Pandas_Market_Predictor
|
4 |
import pandas as pd
|
5 |
|
6 |
+
# Hard-coded API key for demonstration purposes
|
7 |
+
API_KEY = "QR8F9B7T6R2SWTAT"
|
8 |
+
|
9 |
def fetch_alpha_vantage_data(api_key):
|
10 |
url = f'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=IBM&interval=5min&apikey={api_key}'
|
11 |
response = requests.get(url)
|
|
|
15 |
def main():
|
16 |
st.title("Stock Trend Predictor")
|
17 |
|
18 |
+
# Use the hard-coded API key
|
19 |
+
api_key = API_KEY
|
20 |
|
21 |
# Fetch Alpha Vantage data
|
22 |
+
alpha_vantage_data = fetch_alpha_vantage_data(api_key)
|
23 |
+
|
24 |
+
# Extract relevant data from Alpha Vantage response
|
25 |
+
alpha_vantage_time_series = alpha_vantage_data.get('Time Series (5min)', {})
|
26 |
+
df = pd.DataFrame(alpha_vantage_time_series).T
|
27 |
+
df.index = pd.to_datetime(df.index)
|
28 |
+
df = df.dropna(axis=0)
|
29 |
+
|
30 |
+
# Create predictor
|
31 |
+
my_market_predictor = Pandas_Market_Predictor(df)
|
32 |
+
|
33 |
+
# Predict Trend
|
34 |
+
indicators = ["Indicator1", "Indicator2"]
|
35 |
+
trend = my_market_predictor.Trend_Detection(indicators, 10)
|
36 |
+
|
37 |
+
# Display results
|
38 |
+
st.subheader("Predicted Trend:")
|
39 |
+
st.write("Buy Trend :", trend['BUY'])
|
40 |
+
st.write("Sell Trend :", trend['SELL'])
|
41 |
+
st.write(f"Standard Deviation Percentage: {my_market_predictor.PERCENT_STD}%")
|
42 |
+
|
43 |
+
# Delete the DataFrame to release memory
|
44 |
+
del df
|
|
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
main()
|