QuantumLearner commited on
Commit
edcd0fc
·
verified ·
1 Parent(s): 9ad2380

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -28,12 +28,8 @@ st.sidebar.title("Input Parameters")
28
  with st.sidebar.expander("Stop-Loss Strategy", expanded=True):
29
  page = st.radio("Select Mode", ["Run Strategy", "Optimize Parameters"])
30
 
31
- # Select the page
32
- #page = st.sidebar.radio("Select Mode", ["Run Strategy", "Optimize Parameters"])
33
-
34
  # Common user inputs in the sidebar with collapsible sections
35
  with st.sidebar:
36
-
37
  with st.expander("How to use", expanded=False):
38
  st.header("How to Use")
39
  st.markdown("""
@@ -42,7 +38,6 @@ with st.sidebar:
42
  3. Set the symbol, date range, and strategy parameters in the **Parameters** section.
43
  4. Click **Run Strategy** or **Run Optimization** to execute the selected operation.
44
  """)
45
- #st.header("Parameters")
46
 
47
  # Symbol and Date Section
48
  with st.expander("Symbol and Date Range", expanded=True):
@@ -70,12 +65,14 @@ st.markdown("""
70
  This application esimates dynamic stop-loss levels using the Average True Range (ATR) indicator. You can either run a strategy with specific ATR parameters or optimize those parameters to find the best stop-loss settings. The app works with both stocks and cryptocurrency pairs.
71
  """)
72
 
73
- # Function to fetch data
74
  @st.cache_data(show_spinner=False)
75
  def fetch_data(symbol, start, end):
76
- data = yf.download(symbol, start=start, end=end)
 
 
77
  if data.empty:
78
- raise ValueError("No data fetched.")
79
  return data
80
 
81
  # Function to compute Relative Strength Index (RSI)
 
28
  with st.sidebar.expander("Stop-Loss Strategy", expanded=True):
29
  page = st.radio("Select Mode", ["Run Strategy", "Optimize Parameters"])
30
 
 
 
 
31
  # Common user inputs in the sidebar with collapsible sections
32
  with st.sidebar:
 
33
  with st.expander("How to use", expanded=False):
34
  st.header("How to Use")
35
  st.markdown("""
 
38
  3. Set the symbol, date range, and strategy parameters in the **Parameters** section.
39
  4. Click **Run Strategy** or **Run Optimization** to execute the selected operation.
40
  """)
 
41
 
42
  # Symbol and Date Section
43
  with st.expander("Symbol and Date Range", expanded=True):
 
65
  This application esimates dynamic stop-loss levels using the Average True Range (ATR) indicator. You can either run a strategy with specific ATR parameters or optimize those parameters to find the best stop-loss settings. The app works with both stocks and cryptocurrency pairs.
66
  """)
67
 
68
+ # Function to fetch data with yfinance adjustments
69
  @st.cache_data(show_spinner=False)
70
  def fetch_data(symbol, start, end):
71
+ data = yf.download(symbol, start=start, end=end, auto_adjust=False)
72
+ if isinstance(data.columns, pd.MultiIndex):
73
+ data.columns = data.columns.get_level_values(0)
74
  if data.empty:
75
+ raise ValueError(f"No data fetched for {symbol} from {start} to {end}.")
76
  return data
77
 
78
  # Function to compute Relative Strength Index (RSI)