Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
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)
|
9 |
+
alpha_vantage_data = response.json()
|
10 |
+
return alpha_vantage_data
|
11 |
+
|
12 |
+
def main():
|
13 |
+
st.title("Stock Trend Predictor")
|
14 |
+
|
15 |
+
# Get Alpha Vantage API key from user input
|
16 |
+
api_key = st.text_input("Enter your Alpha Vantage API key:")
|
17 |
+
|
18 |
+
# Fetch Alpha Vantage data
|
19 |
+
if api_key:
|
20 |
+
alpha_vantage_data = fetch_alpha_vantage_data(api_key)
|
21 |
+
|
22 |
+
# Extract relevant data from Alpha Vantage response
|
23 |
+
alpha_vantage_time_series = alpha_vantage_data.get('Time Series (5min)', {})
|
24 |
+
df = pd.DataFrame(alpha_vantage_time_series).T
|
25 |
+
df.index = pd.to_datetime(df.index)
|
26 |
+
df = df.dropna(axis=0)
|
27 |
+
|
28 |
+
# Create predictor
|
29 |
+
my_market_predictor = Pandas_Market_Predictor(df)
|
30 |
+
|
31 |
+
# Predict Trend
|
32 |
+
indicators = ["Indicator1", "Indicator2"]
|
33 |
+
trend = my_market_predictor.Trend_Detection(indicators, 10)
|
34 |
+
|
35 |
+
# Display results
|
36 |
+
st.subheader("Predicted Trend:")
|
37 |
+
st.write("Buy Trend :", trend['BUY'])
|
38 |
+
st.write("Sell Trend :", trend['SELL'])
|
39 |
+
st.write(f"Standard Deviation Percentage: {my_market_predictor.PERCENT_STD}%")
|
40 |
+
|
41 |
+
# Delete the DataFrame to release memory
|
42 |
+
del df
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
main()
|