Commit
·
9c7b739
1
Parent(s):
5765482
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import pandas as pd
|
2 |
import numpy as np
|
3 |
import math
|
@@ -9,9 +10,8 @@ from tensorflow.keras.models import Sequential
|
|
9 |
from tensorflow.keras.layers import Dense
|
10 |
from tensorflow.keras.layers import LSTM
|
11 |
|
12 |
-
import gradio as gr
|
13 |
-
|
14 |
import yfinance as yf
|
|
|
15 |
|
16 |
def get_ans(inp):
|
17 |
plt.close()
|
@@ -105,8 +105,68 @@ def get_ans(inp):
|
|
105 |
df3['index']=range(1, len(df3) + 1)
|
106 |
lst_output = pd.DataFrame(lst_output, columns=["Values"])
|
107 |
lst_output['index']=range(1, len(lst_output) + 1)
|
108 |
-
|
|
|
|
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
with gr.Blocks() as demo:
|
112 |
with gr.Row().style(equal_height=True):
|
@@ -114,13 +174,36 @@ with gr.Blocks() as demo:
|
|
114 |
gr.Markdown("<center><h1>Stock Analysis Tool<h1></center>")
|
115 |
gr.Markdown("<center><h3>Give the Ticker of the company you want to analyse. We will provide complete insights on the given company.</h3></center>")
|
116 |
gr.Markdown("<center>To get the ticker of the company, click <a href = 'https://finance.yahoo.com/lookup/'>here.</a></center>")
|
117 |
-
|
118 |
with gr.Row():
|
119 |
with gr.Column():
|
120 |
Name_of_the_company = gr.Textbox(placeholder="eg, GOOG / MSFT / AAPL", label="TICKER of the company")
|
121 |
btn = gr.Button("ANALYSE")
|
122 |
gr.Markdown("<center><h2>Analysis<h2></center>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
gr.Markdown("<h3>Regression Trends of Price<h3>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
mp = gr.Plot()
|
125 |
gr.Markdown("<h3>Price over time<h3>")
|
126 |
with gr.Tab("All Time"):
|
@@ -134,6 +217,7 @@ with gr.Blocks() as demo:
|
|
134 |
Max_year = gr.Textbox(placeholder="The Maximum price for the last year", label='Maximum')
|
135 |
Min_year = gr.Textbox(placeholder="The Minimum price for the last year", label="Minimum")
|
136 |
with gr.Tab("Past few Days"):
|
|
|
137 |
mp3 = gr.LinePlot(visible=False, label="Past few Days")
|
138 |
with gr.Row():
|
139 |
Max_rec = gr.Textbox(placeholder="The Maximum price for the last few days", label='Recent Maximum')
|
@@ -146,5 +230,7 @@ with gr.Blocks() as demo:
|
|
146 |
|
147 |
|
148 |
btn.click(get_ans, inputs=Name_of_the_company, outputs= [mp,mp1,mp2,mp3, Max_all, Min_all,Max_year, Min_year, Max_rec, Min_rec, Next_day, Next_plot, Next_plot_all, Next_plot_year])
|
|
|
|
|
149 |
|
150 |
-
demo.launch(inline
|
|
|
1 |
+
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
import math
|
|
|
10 |
from tensorflow.keras.layers import Dense
|
11 |
from tensorflow.keras.layers import LSTM
|
12 |
|
|
|
|
|
13 |
import yfinance as yf
|
14 |
+
from statsmodels.tsa.seasonal import seasonal_decompose
|
15 |
|
16 |
def get_ans(inp):
|
17 |
plt.close()
|
|
|
105 |
df3['index']=range(1, len(df3) + 1)
|
106 |
lst_output = pd.DataFrame(lst_output, columns=["Values"])
|
107 |
lst_output['index']=range(1, len(lst_output) + 1)
|
108 |
+
the_max = max(np.asarray(df['Open']))
|
109 |
+
df3['Values'] = [i * the_max for i in df3['Values']]
|
110 |
+
return plt, gr.update(visible=True,value=df, x="Date",y="Open", height=500, width=800),gr.update(visible=True,value=df[-300:], x="Date",y="Open", height=500, width=800),gr.update(visible=True,value=df[-30:], x="Date",y="Open", height=500, width=800), max(np.asarray(df['Open'])), min(np.asarray(df['Open'])), max(np.asarray(df['Open'])[-300:]), min(np.asarray(df['Open'][-300:])), max(np.asarray(df['Open'])[-30:]), min(np.asarray(df['Open'][-30:])), (max(np.asarray(df['Open']))) * (lst_output["Values"][0]), gr.update(visible=True,value=lst_output, x="index",y="Values", height=500, width=800), gr.update(visible=True,value=df3, x="index",y="Values", height=500, width=800), gr.update(visible=True,value=df3[-300:], x="index",y="Values", height=500, width=800)
|
111 |
|
112 |
+
def get_seo(inp):
|
113 |
+
plt.close()
|
114 |
+
tickers = yf.Tickers(inp)
|
115 |
+
x = tickers.tickers[inp].history(period="15y")
|
116 |
+
df = x
|
117 |
+
df.reset_index(inplace=True)
|
118 |
+
df1 = df.reset_index()['Close']
|
119 |
+
df['Date'] = pd.to_datetime(df['Date'])
|
120 |
+
scaler = MinMaxScaler(feature_range=(0, 1))
|
121 |
+
df1 = scaler.fit_transform(np.array(df1).reshape(-1, 1))
|
122 |
+
def create_dataset(dataset, time_step=1):
|
123 |
+
dataX, dataY = [], []
|
124 |
+
for i in range(len(dataset) - time_step - 1):
|
125 |
+
a = dataset[i:(i + time_step), 0]
|
126 |
+
dataX.append(a)
|
127 |
+
dataY.append(dataset[i + time_step, 0])
|
128 |
+
return np.array(dataX), np.array(dataY)
|
129 |
+
X_train, y_train = create_dataset(df1, time_step)
|
130 |
+
decompose_result_mult = seasonal_decompose(X_train, model="additive", period=time_step)
|
131 |
+
trend = decompose_result_mult.trend
|
132 |
+
seasonal = decompose_result_mult.seasonal
|
133 |
+
residual = decompose_result_mult.resid
|
134 |
+
|
135 |
+
z = [i[0] for i in trend]
|
136 |
+
z = pd.DataFrame(z, columns=['Values'])
|
137 |
+
z['index'] = range(1, len(z) + 1)
|
138 |
+
|
139 |
+
y = [i[0] for i in seasonal]
|
140 |
+
y = pd.DataFrame(y, columns=['Values'])
|
141 |
+
y['index'] = range(1, len(z) + 1)
|
142 |
+
|
143 |
+
a = [i[0] for i in residual]
|
144 |
+
a = pd.DataFrame(a, columns=['Values'])
|
145 |
+
a['index'] = range(1, len(a) + 1)
|
146 |
+
|
147 |
+
return gr.update(visible=True, value=z, x='index', y='Values', height=500, width=800), gr.update(visible=True, value=y[:100], x='index', y='Values', height=500, width=800), gr.update(visible=True, value=a, x='index', y='Values', height=500, width=800)
|
148 |
+
|
149 |
+
|
150 |
+
def get_info(inp):
|
151 |
+
tickers = yf.Ticker(inp)
|
152 |
+
info = tickers.info
|
153 |
+
balance = tickers.balance_sheet
|
154 |
+
|
155 |
+
long_info= info['longBusinessSummary']
|
156 |
+
curr_rat = info['currentRatio']
|
157 |
+
quick_rat = info['quickRatio']
|
158 |
+
short_rat = info['shortRatio']
|
159 |
+
debt_eq = info['debtToEquity']
|
160 |
+
volume = info['volume']
|
161 |
+
market_cap = info['marketCap']
|
162 |
+
curr_price = info['currentPrice']
|
163 |
+
rev_per = info['revenuePerShare']
|
164 |
+
|
165 |
+
|
166 |
+
|
167 |
+
|
168 |
+
|
169 |
+
return long_info, curr_rat, quick_rat, short_rat, debt_eq, volume, market_cap, curr_price, rev_per
|
170 |
|
171 |
with gr.Blocks() as demo:
|
172 |
with gr.Row().style(equal_height=True):
|
|
|
174 |
gr.Markdown("<center><h1>Stock Analysis Tool<h1></center>")
|
175 |
gr.Markdown("<center><h3>Give the Ticker of the company you want to analyse. We will provide complete insights on the given company.</h3></center>")
|
176 |
gr.Markdown("<center>To get the ticker of the company, click <a href = 'https://finance.yahoo.com/lookup/'>here.</a></center>")
|
|
|
177 |
with gr.Row():
|
178 |
with gr.Column():
|
179 |
Name_of_the_company = gr.Textbox(placeholder="eg, GOOG / MSFT / AAPL", label="TICKER of the company")
|
180 |
btn = gr.Button("ANALYSE")
|
181 |
gr.Markdown("<center><h2>Analysis<h2></center>")
|
182 |
+
gr.Markdown("<center><h3>Inportant Information</h3></center>")
|
183 |
+
info1 = gr.Textbox()
|
184 |
+
gr.Markdown("<h4>Insightful Ratios</h4>")
|
185 |
+
with gr.Row():
|
186 |
+
ratio1 = gr.Textbox(label='Current Ratio')
|
187 |
+
ratio2 = gr.Textbox(label='Quick Ratio')
|
188 |
+
ratio3 = gr.Textbox(label='Short Ratio')
|
189 |
+
ratio4 = gr.Textbox(label='Debt to Equity Ratio')
|
190 |
+
|
191 |
+
gr.Markdown("<center><h3>General Information</h3></center>")
|
192 |
+
with gr.Row():
|
193 |
+
curr_price = gr.Textbox(label='Current Price of Stock')
|
194 |
+
rev_per = gr.Textbox(label='Revenue per Share')
|
195 |
+
vol = gr.Textbox(label='Volume')
|
196 |
+
mar_cap = gr.Textbox(label='Market Cap')
|
197 |
+
|
198 |
gr.Markdown("<h3>Regression Trends of Price<h3>")
|
199 |
+
with gr.Tab("Overall Trend"):
|
200 |
+
trend_g = gr.LinePlot(visible=False, label='Trend of stock over its lifetime', height=1000, width=1000)
|
201 |
+
with gr.Tab("Seasonal Trends"):
|
202 |
+
Seaso = gr.LinePlot(visible=False,label="This is for one season", height=1000, width=1000)
|
203 |
+
with gr.Tab("Residual Variation"):
|
204 |
+
resid = gr.LinePlot(visible=False, label="Residual Variation over time", height=1000, width=1000)
|
205 |
+
|
206 |
+
|
207 |
mp = gr.Plot()
|
208 |
gr.Markdown("<h3>Price over time<h3>")
|
209 |
with gr.Tab("All Time"):
|
|
|
217 |
Max_year = gr.Textbox(placeholder="The Maximum price for the last year", label='Maximum')
|
218 |
Min_year = gr.Textbox(placeholder="The Minimum price for the last year", label="Minimum")
|
219 |
with gr.Tab("Past few Days"):
|
220 |
+
|
221 |
mp3 = gr.LinePlot(visible=False, label="Past few Days")
|
222 |
with gr.Row():
|
223 |
Max_rec = gr.Textbox(placeholder="The Maximum price for the last few days", label='Recent Maximum')
|
|
|
230 |
|
231 |
|
232 |
btn.click(get_ans, inputs=Name_of_the_company, outputs= [mp,mp1,mp2,mp3, Max_all, Min_all,Max_year, Min_year, Max_rec, Min_rec, Next_day, Next_plot, Next_plot_all, Next_plot_year])
|
233 |
+
btn.click(get_info, inputs=Name_of_the_company, outputs=[info1, ratio1, ratio2, ratio3, ratio4, vol, mar_cap, curr_price, rev_per])
|
234 |
+
btn.click(get_seo, inputs=Name_of_the_company, outputs=[trend_g, Seaso, resid])
|
235 |
|
236 |
+
demo.launch(inline=False)
|