Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import yfinance as yf
|
3 |
+
import plotly.graph_objs as go
|
4 |
+
from datetime import datetime
|
5 |
+
|
6 |
+
# Function to load data
|
7 |
+
def load_data(ticker, start_date, end_date):
|
8 |
+
data = yf.download(ticker, start=start_date, end=end_date)
|
9 |
+
data.reset_index(inplace=True)
|
10 |
+
return data
|
11 |
+
|
12 |
+
# Function to plot candlestick chart
|
13 |
+
def plot_candlestick_chart(data):
|
14 |
+
fig = go.Figure(data=[go.Candlestick(
|
15 |
+
x=data['Date'],
|
16 |
+
open=data['Open'], high=data['High'],
|
17 |
+
low=data['Low'], close=data['Close'],
|
18 |
+
name='Candlestick')])
|
19 |
+
fig.update_layout(title='Candlestick Chart', xaxis_rangeslider_visible=False)
|
20 |
+
return fig
|
21 |
+
|
22 |
+
# Streamlit user interface
|
23 |
+
st.sidebar.header('User Input Features')
|
24 |
+
ticker = st.sidebar.text_input('Ticker', 'AAPL')
|
25 |
+
start_date = st.sidebar.date_input('Start Date', datetime(2020, 1, 1))
|
26 |
+
end_date = st.sidebar.date_input('End Date', datetime.today())
|
27 |
+
|
28 |
+
button = st.sidebar.button('Analyze')
|
29 |
+
|
30 |
+
st.title('Fight the Tiger Trading Strategy Visualization')
|
31 |
+
st.markdown("""
|
32 |
+
This app analyzes and visualizes the "Fight the Tiger" trading strategy using historical stock data fetched from Yahoo Finance.
|
33 |
+
Simply enter a stock ticker and select a date range to view the candlestick chart. Look for significant weekly candlesticks that suggest potential buy or sell signals according to the "Fight the Tiger" strategy.
|
34 |
+
""")
|
35 |
+
|
36 |
+
if button:
|
37 |
+
if start_date < end_date:
|
38 |
+
data = load_data(ticker, start_date, end_date)
|
39 |
+
fig = plot_candlestick_chart(data)
|
40 |
+
st.plotly_chart(fig, use_container_width=True)
|
41 |
+
else:
|
42 |
+
st.error('Error: End date must be after start date.')
|
43 |
+
|