netflypsb commited on
Commit
34e8571
·
verified ·
1 Parent(s): 7ec50ee

Delete app2.py

Browse files
Files changed (1) hide show
  1. app2.py +0 -55
app2.py DELETED
@@ -1,55 +0,0 @@
1
- import yfinance as yf
2
- import pandas as pd
3
- import plotly.graph_objects as go
4
- import streamlit as st
5
-
6
- # Sidebar inputs for stock symbol
7
- sidebar = st.sidebar
8
- symbol = sidebar.text_input("Enter stock symbol:", "AAPL")
9
- data = yf.download(symbol, start="2020-01-01", end="2021-01-01")
10
-
11
- # Check if data is empty
12
- if data.empty:
13
- st.error("No data available for the selected symbol. Please try another symbol.")
14
- else:
15
- # Determine the valid date range for Fibonacci analysis
16
- min_date, max_date = data.index.min().date(), data.index.max().date()
17
-
18
- # Dynamic default dates based on data range
19
- default_start, default_end = min_date, max_date
20
-
21
- # Sidebar inputs for Fibonacci time frame
22
- fib_start_date = sidebar.date_input("Fibonacci Start Date", value=default_start, min_value=min_date, max_value=max_date)
23
- fib_end_date = sidebar.date_input("Fibonacci End Date", value=default_end, min_value=min_date, max_value=max_date)
24
-
25
- if fib_start_date >= fib_end_date:
26
- st.error("Error: The start date must be before the end date.")
27
- else:
28
- # Filter data for Fibonacci analysis
29
- fib_data = data.loc[fib_start_date:fib_end_date]
30
-
31
- # Calculate high and low prices for Fibonacci levels
32
- high_price = fib_data['High'].max()
33
- low_price = fib_data['Low'].min()
34
-
35
- # Fibonacci retracement levels
36
- fib_levels = [0, 0.236, 0.382, 0.5, 0.618, 0.786, 1]
37
- price_diff = high_price - low_price
38
-
39
- # Initialize figure for plotting
40
- fig = go.Figure()
41
-
42
- # Plot close prices and moving averages
43
- fig.add_trace(go.Scatter(x=data.index, y=data['Close'], name='Close Price', line=dict(color='black')))
44
- for ma in [20, 50, 200]:
45
- ma_label = f"MA{ma}"
46
- data[ma_label] = data['Close'].rolling(window=ma).mean()
47
- fig.add_trace(go.Scatter(x=data.index, y=data[ma_label], name=ma_label, line=dict(width=2)))
48
-
49
- # Plot Fibonacci levels
50
- for level in fib_levels:
51
- value = high_price - (price_diff * level)
52
- fig.add_hline(y=value, line_dash="dot", annotation_text=f"{level*100}%", annotation_position="right")
53
-
54
- # Display chart
55
- st.plotly_chart(fig)