shreyashnadage commited on
Commit
560ffaf
1 Parent(s): 3e3ccdc

Stock Analysis:
OHLC Plot
Chaikin, MACD indicator,
Candlestick Pattern recognition

Intraday Analysis:
Barrier Hit probability
VWAP analysis

Removed mutual fund tab.

.idea/ProjectRam.iml CHANGED
@@ -2,7 +2,7 @@
2
  <module type="PYTHON_MODULE" version="4">
3
  <component name="NewModuleRootManager">
4
  <content url="file://$MODULE_DIR$" />
5
- <orderEntry type="jdk" jdkName="Python 3.8 (tradeplatform)" jdkType="Python SDK" />
6
  <orderEntry type="sourceFolder" forTests="false" />
7
  </component>
8
  </module>
 
2
  <module type="PYTHON_MODULE" version="4">
3
  <component name="NewModuleRootManager">
4
  <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="jdk" jdkName="Python 3.8 (tradeplatform3)" jdkType="Python SDK" />
6
  <orderEntry type="sourceFolder" forTests="false" />
7
  </component>
8
  </module>
.idea/misc.xml CHANGED
@@ -1,4 +1,4 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <project version="4">
3
- <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (tradeplatform)" project-jdk-type="Python SDK" />
4
  </project>
 
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (tradeplatform3)" project-jdk-type="Python SDK" />
4
  </project>
CS_pattern_rankings.py CHANGED
@@ -123,4 +123,133 @@ candle_rankings = {
123
  "CDL3STARSINSOUTH_Bear": 103,
124
  "CDLDOJI_Bull": 104,
125
  "CDLDOJI_Bear": 104
126
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  "CDL3STARSINSOUTH_Bear": 103,
124
  "CDLDOJI_Bull": 104,
125
  "CDLDOJI_Bear": 104
126
+ }
127
+
128
+ candlestick_patterns = {
129
+ "CDL3BLACKCROWS": "Three Black Crows",
130
+ "CDL3INSIDE": "Three Inside Up/Down",
131
+ "CDL3LINESTRIKE": "Three-Line Strike",
132
+ "CDL3OUTSIDE": "Three Outside Up/Down",
133
+ "CDL3STARSINSOUTH": "Three Stars In The South",
134
+ "CDL3WHITESOLDIERS": "Three Advancing White Soldiers",
135
+ "CDLABANDONEDBABY": "Abandoned Baby",
136
+ "CDLADVANCEBLOCK": "Advance Block",
137
+ "CDLBELTHOLD": "Belt-hold",
138
+ "CDLBREAKAWAY": "Breakaway",
139
+ "CDLCLOSINGMARUBOZU": "Closing Marubozu",
140
+ "CDLCONCEALBABYSWALL": "Concealing Baby Swallow",
141
+ "CDLCOUNTERATTACK": "Counterattack",
142
+ "CDLDARKCLOUDCOVER": "Dark Cloud Cover",
143
+ "CDLDOJI": "Doji",
144
+ "CDLDOJISTAR": "Doji Star",
145
+ "CDLDRAGONFLYDOJI": "Dragonfly Doji",
146
+ "CDLENGULFING": "Engulfing Pattern",
147
+ "CDLEVENINGDOJISTAR": "Evening Doji Star",
148
+ "CDLEVENINGSTAR": "Evening Star",
149
+ "CDLGAPSIDESIDEWHITE": "Up/Down-gap side-by-side white lines",
150
+ "CDLGRAVESTONEDOJI": "Gravestone Doji",
151
+ "CDLHAMMER": "Hammer",
152
+ "CDLHANGINGMAN": "Hanging Man",
153
+ "CDLHARAMI": "Harami Pattern",
154
+ "CDLHARAMICROSS": "Harami Cross Pattern",
155
+ "CDLHIGHWAVE": "High-Wave Candle",
156
+ "CDLHIKKAKE": "Hikkake Pattern",
157
+ "CDLHIKKAKEMOD": "Modified Hikkake Pattern",
158
+ "CDLHOMINGPIGEON": "Homing Pigeon",
159
+ "CDLIDENTICAL3CROWS": "Identical Three Crows",
160
+ "CDLINNECK": "In-Neck Pattern",
161
+ "CDLINVERTEDHAMMER": "Inverted Hammer",
162
+ "CDLKICKING": "Kicking",
163
+ "CDLKICKINGBYLENGTH": "Kicking - bull/bear determined by the longer marubozu",
164
+ "CDLLADDERBOTTOM": "Ladder Bottom",
165
+ "CDLLONGLEGGEDDOJI": "Long Legged Doji",
166
+ "CDLLONGLINE": "Long Line Candle",
167
+ "CDLMARUBOZU": "Marubozu",
168
+ "CDLMATCHINGLOW": "Matching Low",
169
+ "CDLMATHOLD": "Mat Hold",
170
+ "CDLMORNINGDOJISTAR": "Morning Doji Star",
171
+ "CDLMORNINGSTAR": "Morning Star",
172
+ "CDLONNECK": "On-Neck Pattern",
173
+ "CDLPIERCING": "Piercing Pattern",
174
+ "CDLRICKSHAWMAN": "Rickshaw Man",
175
+ "CDLRISEFALL3METHODS": "Rising/Falling Three Methods",
176
+ "CDLSEPARATINGLINES": "Separating Lines",
177
+ "CDLSHOOTINGSTAR": "Shooting Star",
178
+ "CDLSHORTLINE": "Short Line Candle",
179
+ "CDLSPINNINGTOP": "Spinning Top",
180
+ "CDLSTALLEDPATTERN": "Stalled Pattern",
181
+ "CDLSTICKSANDWICH": "Stick Sandwich",
182
+ "CDLTAKURI": "Takuri (Dragonfly Doji with very long lower shadow)",
183
+ "CDLTASUKIGAP": "Tasuki Gap",
184
+ "CDLTHRUSTING": "Thrusting Pattern",
185
+ "CDLTRISTAR": "Tristar Pattern",
186
+ "CDLUNIQUE3RIVER": "Unique 3 River",
187
+ "CDLUPSIDEGAP2CROWS": "Upside Gap Two Crows",
188
+ "CDLXSIDEGAP3METHODS": "Upside/Downside Gap Three Methods"
189
+ }
190
+
191
+ candlestick_patterns_description = {
192
+ "CDL2CROWS": "Two red candlesticks in a row, suggesting a potential trend reversal",
193
+ "CDL3BLACKCROWS": "Three consecutive red candlesticks, with each open within the previous candlestick's real body and each close lower, indicating a strong bearish trend",
194
+ "CDL3INSIDE": "Three candlesticks where the first is red, the second is green, and the third is red again, with the third red candlestick's high within the second green one's real body, suggesting a potential trend reversal",
195
+ "CDL3LINESTRIKE": "Three red or green candlesticks in a row with progressively higher highs or lower lows, indicating a strong trend",
196
+ "CDL3OUTSIDE": "Three candlesticks where the first is red, the second is green, and the third is red again, with the third red candlestick's high above the first red one's high and low below the second green one's low, suggesting a trend reversal",
197
+ "CDL3STARSINSOUTH": "Three red candlesticks with each having a small real body, where the first two are contained within the prior red candlestick's real body and the third has a lower close, suggesting a potential trend reversal",
198
+ "CDL3WHITESOLDIERS": "Three green candlesticks in a row, each with a higher close, indicating a strong bullish trend",
199
+ "CDLABANDONEDBABY": "A gap followed by a doji, which is a candle with a small real body, where the doji is above or below the gap, suggesting a trend reversal",
200
+ "CDLADVANCEBLOCK": "Three red candlesticks with each having a higher high and progressively higher lows, indicating a potential trend reversal",
201
+ "CDLBELTHOLD": "A red or green candlestick with a long real body, followed by a doji with a similar color and a small real body, where the doji is above or below the first candlestick, suggesting indecision in the market",
202
+ "CDLBREAKAWAY": "A gap followed by a red or green candlestick with a long real body, where the color of the real body continues the preceding trend, indicating a potential trend continuation",
203
+ "CDLCLOSINGMARUBOZU": "A red or green candlestick with no shadow and a long real body, indicating strong buying or selling pressure",
204
+ "CDLCONCEALBABYSWALL": "A green candlestick followed by a red or doji candlestick that is fully contained within the real body of the green candle, suggesting a potential trend reversal",
205
+ "CDLCOUNTERATTACK": "A red candlestick with a long real body followed by a green candlestick with a smaller real body, where the green candle's real body is contained within the prior red candle's real body, indicating a potential trend reversal",
206
+ "CDLDARKCLOUDCOVER": "A green candlestick followed by a red candlestick, where the red candle's real body is partially contained within the prior green candle's real body, indicating a potential trend reversal",
207
+ "CDLDOJI": "A candlestick with the same opening and closing price, suggesting indecision in the market",
208
+ "CLDOJISTAR": "A doji with a small real body and long upper and lower shadows, where the doji is above or below the preceding trend, suggesting a potential trend reversal",
209
+ "CDLDRAGONFLYDOJI": "A doji with a long lower shadow and no upper shadow, suggesting bullishness",
210
+ "CDLENGULFING": "A red candlestick with a long real body that completely engulfs the prior green candlestick, indicating a potential trend reversal",
211
+ "CDLEVENINGDOJISTAR": "A doji with a small real body and long upper shadow, where the doji is above or below the preceding trend, suggesting a potential trend reversal",
212
+ "CDLEVENINGSTAR": "A small real body candle that gaps above or below a long real body candle, where the color of the small candle is opposite to that of the long candle, suggesting a potential trend reversal",
213
+ "CDLGAPSIDESIDEWHITE": "A green candlestick with no shadows and a high that is above the prior red candlestick's high and a low that is below the prior red candlestick's low, suggesting a potential trend reversal",
214
+ "CDLGRAVESTONEDOJI": "A doji with long upper and lower shadows and no real body, indicating potential trend reversal",
215
+ "CDLHAMMER": "A green or red candlestick with a small real body and a long lower shadow that is at least twice the length of the real body, indicating potential bullishness or bearishness",
216
+ "CDLHANGINGMAN": "A red or green candlestick with a small real body and a long lower shadow that is at least twice the length of the real body, where the candle is at the top of an uptrend, indicating potential bearishness",
217
+ "CDLHARAMI": "A red candlestick followed by a green candlestick with a real body that is contained within the prior red candlestick's real body, indicating a potential trend reversal",
218
+ "CDLHARAMICROSS": "A red candlestick followed by a doji, where the doji is contained within the prior red candlestick's real body, indicating a potential trend reversal",
219
+ "CDLHIGHWAVE": "A green or red candlestick with a long real body, no shadows, and a longer than average upper shadow, suggesting potential bullishness or bearishness",
220
+ "CDLHIKKAKE": "A gap followed by a doji, where the color of the doji is opposite to that of the preceding trend, suggesting a potential trend reversal",
221
+ "CDLHIKKAKEMOD": "A gap followed by a doji, where the color of the doji is opposite to that of the preceding trend and the doji is contained within the gap, suggesting a potential trend reversal",
222
+ "CDLHOMINGPIGEON": "A green candlestick followed by a doji, where the doji is contained within the prior green candle's real body, indicating a potential trend reversal",
223
+ "CDLIDENTICAL3CROWS": "Three red candlesticks in a row with identical real body lengths and lower closes, indicating a strong bearish trend",
224
+ "CDLINNECK": "A red or green candlestick with a long real body and no or very short shadows, where the real body is at the extreme end of the trend, indicating a potential trend reversal",
225
+ "CDLINVERTEDHAMMER": "A green or red candlestick with a small real body and a long upper shadow that is at least twice the length of the real body, indicating potential bullishness or bearishness",
226
+ "CDLKICKING": "A red or green candlestick with a long real body that follows a doji and gaps away from the doji, indicating a potential trend reversal",
227
+ "CDLKICKINGBYLENGTH": "A red or green candlestick with a long real body that follows a doji, where the real body is longer than the doji, indicating a potential trend reversal",
228
+ "CDLLADDERBOTTOM": "A pattern of three or more dojis where the prices are consistently getting higher, indicating a potential bullish trend",
229
+ "CDLLONGLEGGEDDOJI": "A doji with long upper and lower shadows, indicating potential trend reversal",
230
+ "CDLLONGLINE": "A green or red candlestick with a very long real body, indicating potential trend continuation",
231
+ "CDLMARUBOZU": "A green or red candlestick with no shadows, indicating potential trend continuation",
232
+ "CDLMATCHINGLOW": "A green or red candlestick with a low that is equal to the prior candlestick's low, indicating potential trend reversal or continuation",
233
+ "CDLMATHOLD": "A red candlestick followed by a green candlestick that has a high that is equal to the prior red candlestick's high, indicating potential trend reversal",
234
+ "CDLMORNINGDOJISTAR": "A doji with a small real body and long lower shadow, where the doji is above or below the preceding trend, suggesting a potential trend reversal",
235
+ "CDLMORNINGSTAR": "A small real body candle that gaps above or below a long real body candle, where the color of the small candle is opposite to that of the long candle, suggesting a potential trend reversal",
236
+ "CDLONNECK": "A red or green candlestick with a long real body and no or very short shadows, where the real body is at the extreme end of the trend, indicating a potential trend reversal",
237
+ "CDLPIERCING": "A green candlestick that opens below the prior red candlestick's low and closes above the midpoint of the prior red candlestick's real body, indicating potential bullishness",
238
+ "CDLRICKSHAWMAN": "A pattern of two or more dojis, indicating potential trend reversal or market indecision",
239
+ "CDLRISEFALL3METHODS": "A pattern of three candlesticks, where a long red candle is followed by a green candle that gaps above the red candle and a third red candle that closes within the gap, indicating a potential trend reversal",
240
+ "CDLSEPARATINGLINES": "A red candlestick followed by a green candlestick that has a higher high and a higher low, indicating potential bullishness",
241
+ "CDLSHOOTINGSTAR": "A red or green candlestick with a small real body and a long upper shadow that is at least twice the length of the real body, where the color of the small body is opposite to that of the preceding trend, indicating a potential trend reversal",
242
+ "CDLSHORTLINE": "A green or red candlestick with a short real body, indicating potential trend continuation",
243
+ "CDLSPINNINGTOP": "A green or red candlestick with a small real body and long upper and lower shadows, indicating market indecision",
244
+ "CDLSTALLEDPATTERN": "A pattern of two candlesticks where the first candle is a long red or green real body and the second candle is a spinning top, where the color of the spinning top is opposite to that of the first candle, indicating potential trend reversal",
245
+ "CDLSTICKSANDWICH": "A pattern of three candlesticks, where a green candle is sandwiched between two red candles with lower highs, indicating potential trend reversal",
246
+ "CDLTAKURI": "A green or red candlestick with a small real body and a long upper shadow, where the color of the small body is the same as that of the preceding trend, indicating potential trend continuation",
247
+ "CDLTASUKIGAP": "A pattern of two candlesticks, where the second candle opens above or below the first candle, gaps away, and then closes, indicating potential trend reversal or continuation",
248
+ "CDLTHRUSTING": "A pattern of two candlesticks, where the first candle is a long red or green real body and the second candle is a spinning top, where the color of the spinning top is the same as that of the first candle, indicating potential trend continuation",
249
+ "CDLTRISTAR": "A pattern of three dojis, where the middle doji is higher or lower than the first and last dojis, indicating potential trend reversal",
250
+ "CDLUNIQUE3RIVER": "A pattern of three candlesticks where a green candle is followed by three small red candles that are progressively lower, indicating potential trend reversal",
251
+ "CDLUPSIDEGAP2CROWS": "A pattern of three candlesticks, where a green candle is followed by a gap and then two red candles, indicating potential trend reversal",
252
+ "CDLXSIDEGAP3METHODS": "A pattern of three candlesticks, where a long red candle is followed by a gap and then a green candle that closes within the gap, indicating a potential trend reversal"
253
+ }
254
+
255
+
NewsAnalyzer.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pygooglenews import GoogleNews
2
+ from transformers import BertTokenizer, BertForSequenceClassification
3
+ from transformers import pipeline
4
+ import pandas as pd
5
+
6
+ finbert = BertForSequenceClassification.from_pretrained('yiyanghkust/finbert-tone',num_labels=3)
7
+ tokenizer = BertTokenizer.from_pretrained('yiyanghkust/finbert-tone')
8
+ nlp = pipeline("sentiment-analysis", model=finbert, tokenizer=tokenizer)
9
+
10
+ num_top_headlines = 10
11
+
12
+ gn = GoogleNews(lang='en',country='IN')
13
+
14
+ def get_headlines(searchterm='Nifty'):
15
+ test = gn.search(searchterm, when='5d')
16
+ newslist = [i['title'] for i in test['entries']]
17
+ return newslist[:num_top_headlines]
18
+
19
+ def get_sentimental_analysis(newslist):
20
+ results = nlp(newslist)
21
+ df = pd.DataFrame({'headlines': newslist, \
22
+ 'results': [i['label'] for i in results]})
23
+ return df.results.value_counts().sort_values(ascending=False).index[0]
24
+
25
+ def get_nifty_sentiment():
26
+ newslist = get_headlines()
27
+ return get_sentimental_analysis(newslist)
28
+
29
+
PatternRecognition.py CHANGED
@@ -38,3 +38,4 @@ def ComputeMACDSignal(stock_data_df):
38
  ta.MACD(macd_data_df.Close, fastperiod=12, slowperiod=26, signalperiod=9)
39
  macd_data_df.dropna(inplace=True)
40
  return macd_data_df
 
 
38
  ta.MACD(macd_data_df.Close, fastperiod=12, slowperiod=26, signalperiod=9)
39
  macd_data_df.dropna(inplace=True)
40
  return macd_data_df
41
+
main.py CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
2
  from nsetools import Nse
3
  from nsepy import get_history
4
  from datetime import date, timedelta
 
 
5
  from PatternRecognition import *
6
  from VixAnalysis import *
7
  from TopMovers import *
@@ -12,9 +14,9 @@ import numpy as np
12
  import pandas as pd
13
  import yfinance as yf
14
  from plotly.subplots import make_subplots
15
- from random import randrange
16
 
17
- buy_sell_color_dict = {"Buy":"green", "Sell":"red", "Hold":"yellow"}
18
 
19
  today = date.today()
20
  nse = Nse()
@@ -49,6 +51,12 @@ with main_sidebar:
49
  except:
50
  st.error("Issues fetching VIX Data!")
51
 
 
 
 
 
 
 
52
  top_losers = st.container()
53
  with top_losers:
54
  if GetTopLosers() is not None:
@@ -120,8 +128,8 @@ with stock_tab:
120
  matched_pattern, tech_df = GetPatternForData(stock_data_df=stock_data_df)
121
  if matched_pattern is not None:
122
  with pattern_expander_col:
123
- with st.expander(matched_pattern):
124
- st.write("Will add description here")
125
  with cs_gauge_col:
126
  score_cs_pattern = tech_df[[matched_pattern]].astype(float).sum()[0]
127
  if score_cs_pattern < 0:
@@ -197,7 +205,19 @@ with stock_tab:
197
  fig_macd.update_yaxes(title_text="MACD", showgrid=False, row=3, col=1)
198
  st.plotly_chart(fig_macd, use_container_width=True)
199
 
200
-
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
  with intraday_tab:
203
 
@@ -288,5 +308,9 @@ with intraday_tab:
288
 
289
  time.sleep(5)
290
 
291
- with mf_tab:
292
- st.write("Coming soon...")
 
 
 
 
 
2
  from nsetools import Nse
3
  from nsepy import get_history
4
  from datetime import date, timedelta
5
+
6
+ import CS_pattern_rankings
7
  from PatternRecognition import *
8
  from VixAnalysis import *
9
  from TopMovers import *
 
14
  import pandas as pd
15
  import yfinance as yf
16
  from plotly.subplots import make_subplots
17
+ from NewsAnalyzer import *
18
 
19
+ buy_sell_color_dict = {"Buy": "green", "Sell": "red", "Hold": "yellow"}
20
 
21
  today = date.today()
22
  nse = Nse()
 
51
  except:
52
  st.error("Issues fetching VIX Data!")
53
 
54
+ Nifty_sentiment_container = st.container()
55
+ with Nifty_sentiment_container:
56
+ with st.spinner(text="Loading NIFTY live sentiment..."):
57
+ st.subheader("Live NIFTY Sentiment")
58
+ st.markdown(f"**{get_nifty_sentiment()}**")
59
+
60
  top_losers = st.container()
61
  with top_losers:
62
  if GetTopLosers() is not None:
 
128
  matched_pattern, tech_df = GetPatternForData(stock_data_df=stock_data_df)
129
  if matched_pattern is not None:
130
  with pattern_expander_col:
131
+ with st.expander(CS_pattern_rankings.candlestick_patterns[matched_pattern]):
132
+ st.write(CS_pattern_rankings.candlestick_patterns_description[matched_pattern])
133
  with cs_gauge_col:
134
  score_cs_pattern = tech_df[[matched_pattern]].astype(float).sum()[0]
135
  if score_cs_pattern < 0:
 
205
  fig_macd.update_yaxes(title_text="MACD", showgrid=False, row=3, col=1)
206
  st.plotly_chart(fig_macd, use_container_width=True)
207
 
208
+ st.markdown("***")
209
+ st.subheader("Sentiment Analysis:")
210
+ newsheadlines = get_headlines(searchterm=selected_stock)
211
+ newsheadlines_col, sentimet_col = st.columns(2)
212
+ with newsheadlines_col:
213
+ st.subheader(f"Top Headlines For {ticker_yf}:")
214
+ for news in newsheadlines[:5]:
215
+ st.markdown(news)
216
+
217
+ with sentimet_col:
218
+ sentiment = get_sentimental_analysis(newsheadlines)
219
+ st.subheader(f"Live sentiment for {ticker_yf.split('.')[0]}:")
220
+ st.markdown(f"**{sentiment}**")
221
 
222
  with intraday_tab:
223
 
 
308
 
309
  time.sleep(5)
310
 
311
+ with portfolio_tab:
312
+
313
+ # with mf_tab:
314
+ # test_tab1, test_tab2 = st.tabs(['tab1', 'tab2'])
315
+ # with test_tab1:
316
+ # st.write("Coming soon...")
requirements.txt DELETED
@@ -1,10 +0,0 @@
1
- hmmlearn
2
- nsepy
3
- nsetools
4
- numpy
5
- pandas
6
- plotly
7
- scipy
8
- streamlit
9
- TA_Lib
10
- yfinance