Geek7 commited on
Commit
adbc0ad
·
verified ·
1 Parent(s): 67bdd5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -5
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import requests
 
3
  import pandas as pd
4
 
5
  # Hard-coded API key for demonstration purposes
@@ -11,6 +12,12 @@ def fetch_alpha_vantage_data(api_key):
11
  alpha_vantage_data = response.json()
12
  return alpha_vantage_data
13
 
 
 
 
 
 
 
14
  def main():
15
  st.title("Stock Trend Predictor")
16
 
@@ -26,12 +33,27 @@ def main():
26
  df.index = pd.to_datetime(df.index)
27
  df = df.dropna(axis=0)
28
 
29
- # Print DataFrame for observation
30
- st.subheader("Raw Data:")
31
- st.write(df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- # Uncomment the next line if you want to stop the execution here to observe the data
34
- # st.stop()
35
 
36
  if __name__ == "__main__":
37
  main()
 
1
  import streamlit as st
2
  import requests
3
+ from Pandas_Market_Predictor import Pandas_Market_Predictor
4
  import pandas as pd
5
 
6
  # Hard-coded API key for demonstration purposes
 
12
  alpha_vantage_data = response.json()
13
  return alpha_vantage_data
14
 
15
+ def calculate_indicators(data):
16
+ # Example: Simple condition for doji and inside
17
+ data['Doji'] = abs(data['4. close'] - data['1. open']) <= 0.01 * (data['2. high'] - data['3. low'])
18
+ data['Inside'] = (data['2. high'] < data['3. high']) & (data['2. low'] > data['3. low'])
19
+ return data
20
+
21
  def main():
22
  st.title("Stock Trend Predictor")
23
 
 
33
  df.index = pd.to_datetime(df.index)
34
  df = df.dropna(axis=0)
35
 
36
+ # Rename columns
37
+ df = df.rename(columns={'1. open': 'open', '2. high': 'high', '3. low': 'low', '4. close': 'close', '5. volume': 'volume'})
38
+
39
+ # Calculate indicators
40
+ df = calculate_indicators(df)
41
+
42
+ # Create predictor
43
+ my_market_predictor = Pandas_Market_Predictor(df)
44
+
45
+ # Predict Trend
46
+ indicators = ["Doji", "Inside"]
47
+ trend = my_market_predictor.Trend_Detection(indicators, 10)
48
+
49
+ # Display results
50
+ st.subheader("Predicted Trend:")
51
+ st.write("Buy Trend :", trend['BUY'])
52
+ st.write("Sell Trend :", trend['SELL'])
53
+ st.write(f"Standard Deviation Percentage: {my_market_predictor.PERCENT_STD}%")
54
 
55
+ # Delete the DataFrame to release memory
56
+ del df
57
 
58
  if __name__ == "__main__":
59
  main()