-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStock_screening.py
66 lines (57 loc) · 1.86 KB
/
Stock_screening.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pandas as pd
import streamlit as st
from datetime import datetime
import plotly.graph_objects as go
from symlist import *
df = pd.read_csv('NSE_Bhavcopy.csv')
df['TIMESTAMP']= pd.to_datetime(df['TIMESTAMP'])
st.title('Stock Technical Analysis')
st.sidebar.title("Stock Technical Analysis")
select_type = st.sidebar.selectbox('Select Type',['All','CN100'] )
select = 'ITC'
if select_type == 'All':
select = st.sidebar.selectbox('Select SYMBOL',All)
elif select_type == 'CN100':
select = st.sidebar.selectbox('Select SYMBOL',CN100)
#Simple Moving average calculation
df_for_plot = df.loc[(df['SYMBOL'] == select) & (df['SERIES'] == 'EQ')]
df_for_plot['SMA44'] = df_for_plot['CLOSE'].rolling(44).mean()
df_for_plot['SMA10'] = df_for_plot['CLOSE'].rolling(10).mean()
df_for_plot['SMA20'] = df_for_plot['CLOSE'].rolling(20).mean()
#Data for plotting
data1 = { 'x': df_for_plot.TIMESTAMP,
'open': df_for_plot.OPEN,
'close': df_for_plot.CLOSE,
'high': df_for_plot.HIGH,
'low': df_for_plot.LOW,
'type': 'candlestick',}
data2 = { 'x': df_for_plot.TIMESTAMP,
'y': df_for_plot.SMA44,
'type': 'scatter',
'mode': 'lines',
'line': { 'width': 1, 'color': 'blue' },
'name': 'SMA 44'}
data3 = { 'x': df_for_plot.TIMESTAMP,
'y': df_for_plot.SMA20,
'type': 'scatter',
'mode': 'lines',
'line': { 'width': 1, 'color': 'red' },
'name': 'SMA 20'}
data4 = { 'x': df_for_plot.TIMESTAMP,
'y': df_for_plot.SMA10,
'type': 'scatter',
'mode': 'lines',
'line': { 'width': 1, 'color': 'green' },
'name': 'SMA 10 periods'}
data = [data1, data2, data3, data4]
fig = go.Figure(data=data)
#update figure layout
fig.update_layout(
title={
'text': "SYMBOL = " + select,
'xanchor': 'left',
'yanchor': 'top'}
)
st.subheader('Candlestick chart with SMA curves')
st.write('Data Range: 04/01/2021 to 30/07/2021')
st.plotly_chart(fig)