Th3Nic3Guy commited on
Commit
a1c95e2
·
1 Parent(s): 17abef6
Files changed (5) hide show
  1. .gitignore +3 -0
  2. app.py +263 -0
  3. nifty250.csv +253 -0
  4. nifty50.csv +50 -0
  5. requirements.txt +14 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ __pycache__/
2
+ .venv/
3
+ *.ipynb
app.py ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import yfinance as yf
3
+ from retry import retry
4
+ from tqdm.auto import tqdm
5
+ import pandas as pd
6
+ import time
7
+ import mplfinance as mpf
8
+ from pypfopt import risk_models, expected_returns
9
+ from pypfopt import plotting
10
+ from pypfopt import EfficientFrontier, objective_functions
11
+ import numpy as np
12
+ from warnings import filterwarnings
13
+
14
+ filterwarnings("ignore")
15
+
16
+ data = pd.DataFrame()
17
+
18
+
19
+ def load_data(ticker_list="", start_year=2021):
20
+
21
+ data = yf.download(
22
+ list(map(lambda x: x.strip().upper(), ticker_list.split(','))),
23
+ start=f'{start_year}-01-01',
24
+ interval='1d',
25
+ keepna=True,
26
+ period="5y",
27
+ rounding=True,
28
+ )['Close'].reset_index().fillna(method='ffill')
29
+
30
+ data.Date = pd.to_datetime(data.Date)
31
+ return data
32
+
33
+
34
+ def _prep_evaluation_report(
35
+ hist_data,
36
+ backtest_days,
37
+ investment_size, weights
38
+ ):
39
+ allocation_df = pd.DataFrame({k: [weights[k]] for k in weights}).T
40
+ testing_data = hist_data[-backtest_days:].copy()
41
+
42
+ allocation_df.columns = ['weights']
43
+ init_df = testing_data.iloc[0]
44
+ end_df = testing_data.iloc[-1]
45
+ allocation_df = allocation_df.merge(
46
+ init_df, left_index=True, right_index=True)
47
+
48
+ allocation_df = allocation_df.merge(
49
+ end_df, left_index=True, right_index=True)
50
+
51
+ allocation_df.columns = ['weights', 'cost_price', 'sell_price']
52
+
53
+ allocation_df['amount_allocation'] = allocation_df.weights * \
54
+ investment_size
55
+
56
+ allocation_df['unit_pnl'] = allocation_df.sell_price - \
57
+ allocation_df.cost_price
58
+
59
+ allocation_df['units'] = allocation_df.weights * \
60
+ investment_size // allocation_df.cost_price
61
+
62
+ allocation_df['value'] = allocation_df.units * allocation_df.cost_price
63
+
64
+ allocation_df['pnl'] = allocation_df.units * allocation_df.unit_pnl
65
+
66
+ profit = np.round(allocation_df.pnl.sum(), 2)
67
+ cagr = np.round(
68
+ (
69
+ (
70
+ (investment_size + profit)/investment_size
71
+ )**(
72
+ 1/(backtest_days/365)
73
+ ) - 1
74
+ )*100,
75
+ 2
76
+ )
77
+ return allocation_df.round(2).reset_index(), profit, cagr
78
+
79
+
80
+ def re_optimize(
81
+ hist_data: pd.DataFrame,
82
+ allocation_df: pd.DataFrame,
83
+ backtest_days: int,
84
+ investment_size: int
85
+ ):
86
+ return find_weights(
87
+ hist_data.drop(
88
+ columns=allocation_df[allocation_df.units == 0]['index']
89
+ ),
90
+ backtest_days,
91
+ investment_size
92
+ )
93
+
94
+
95
+ def find_weights(
96
+ hist_data: pd.DataFrame,
97
+ backtest_days: int,
98
+ investment_size: int
99
+ ):
100
+ training_data = hist_data[:-backtest_days].copy().set_index(
101
+ 'Date'
102
+ ).fillna(0).astype(float)
103
+
104
+ mu = expected_returns.capm_return(training_data)
105
+
106
+ S = risk_models.semicovariance(training_data)
107
+ initial_weights = np.array(
108
+ [1/len(training_data.columns)] * len(training_data.columns))
109
+
110
+ ef = EfficientFrontier(mu, S)
111
+
112
+ ef.add_objective(
113
+ objective_functions.transaction_cost,
114
+ w_prev=initial_weights,
115
+ k=0.02
116
+ )
117
+ ef.add_objective(objective_functions.L2_reg)
118
+
119
+ ef.max_sharpe()
120
+ weights = ef.clean_weights()
121
+ (
122
+ expected_annual_return,
123
+ annual_volatility,
124
+ sharpe_ratio
125
+ ) = ef.portfolio_performance()
126
+
127
+ pnl_df, profit, cagr = _prep_evaluation_report(
128
+ hist_data,
129
+ backtest_days,
130
+ investment_size,
131
+ weights
132
+ )
133
+
134
+ return f'''
135
+ > ## Portfolio Performance
136
+ |Expected Annual Return|Annual Volatility|Sharpe Ratio|Profit|Profit %|CAGR|
137
+ |:---:|:---:|:---:|:---:|:---:|:---:|
138
+ |{expected_annual_return*100:.2f}|{annual_volatility*100:.2f}%|{sharpe_ratio:.2f}|{profit:.2f}|{profit/investment_size*100:.2f}%|{cagr:.2f}|
139
+ ''', pnl_df.sort_values('pnl', ascending=False)
140
+
141
+
142
+ with gr.Blocks() as demo:
143
+ # with gr.Blocks() as demo:
144
+
145
+ with gr.Row():
146
+ with gr.Column():
147
+ stocks = gr.Textbox(
148
+ label="TickerCodes",
149
+ show_label=True,
150
+ interactive=True
151
+ )
152
+ backtest_days = gr.Slider(
153
+ minimum=1,
154
+ maximum=200,
155
+ value=90,
156
+ label="Backtest Days",
157
+ interactive=True
158
+ )
159
+ investment_size = gr.Slider(
160
+ minimum=10_000,
161
+ maximum=10_00_000,
162
+ value=100_000,
163
+ interactive=True,
164
+ step=10_000,
165
+ label="Investment Amount"
166
+ )
167
+ start_year = gr.Slider(
168
+ minimum=2020,
169
+ maximum=2024,
170
+ interactive=True,
171
+ value=2021,
172
+ label="Analysis Start Year"
173
+ )
174
+ with gr.Row():
175
+ fetch_data = gr.Button("Load Data")
176
+ optimize = gr.Button("Optimize")
177
+ reoptimize = gr.Button("Re-Optimize")
178
+
179
+ with gr.Row():
180
+ with gr.Column():
181
+ performance = gr.Markdown()
182
+ pnl_statement = gr.DataFrame()
183
+ historical_data = gr.DataFrame()
184
+
185
+ fetch_data.click(
186
+ load_data,
187
+ [stocks, start_year],
188
+ [historical_data]
189
+ )
190
+ optimize.click(
191
+ find_weights,
192
+ [historical_data, backtest_days, investment_size],
193
+ [performance, pnl_statement]
194
+ )
195
+ reoptimize.click(
196
+ re_optimize,
197
+ [historical_data, pnl_statement, backtest_days, investment_size],
198
+ [performance, pnl_statement]
199
+ )
200
+
201
+ gr.Examples(
202
+ examples=[
203
+ [','.join(
204
+ ['ADANIENT.BO',
205
+ 'ADANIPORTS.NS',
206
+ 'APOLLOHOSP.NS',
207
+ 'ASIANPAINT.NS',
208
+ 'AXISBANK.BO',
209
+ 'BAJAJ-AUTO.NS',
210
+ 'BAJAJFINSV.NS',
211
+ 'BAJFINANCE.NS',
212
+ 'BHARTIARTL.BO',
213
+ 'BPCL.NS',
214
+ 'BRITANNIA.NS',
215
+ 'CIPLA.NS',
216
+ 'COALINDIA.NS',
217
+ 'DIVISLAB.NS',
218
+ 'DRREDDY.BO',
219
+ 'EICHERMOT.BO',
220
+ 'GRASIM.NS',
221
+ 'HCLTECH.NS',
222
+ 'HDFCBANK.NS',
223
+ 'HDFCLIFE.BO',
224
+ 'HEROMOTOCO.BO',
225
+ 'HINDALCO.BO',
226
+ 'HINDUNILVR.BO',
227
+ 'ICICIBANK.NS',
228
+ 'INDUSINDBK.NS',
229
+ 'INFY.NS',
230
+ 'ITC.NS',
231
+ 'JSWSTEEL.BO',
232
+ 'KOTAKBANK.BO',
233
+ 'LT.BO',
234
+ 'LTIM.BO',
235
+ 'M&M.NS',
236
+ 'MARUTI.NS',
237
+ 'NTPC.BO',
238
+ 'ONGC.NS',
239
+ 'POWERGRID.BO',
240
+ 'RELIANCE.NS',
241
+ 'SBILIFE.BO',
242
+ 'SBIN.NS',
243
+ 'SHRIRAMFIN.BO',
244
+ 'SUNPHARMA.NS',
245
+ 'TATACONSUM.BO',
246
+ 'TATAMOTORS.BO',
247
+ 'TATASTEEL.BO',
248
+ 'TCS.NS',
249
+ 'TECHM.BO',
250
+ 'TITAN.BO',
251
+ 'ULTRACEMCO.NS',
252
+ 'WIPRO.BO'
253
+ ]
254
+ ),
255
+ 90,
256
+ 100000,
257
+ 2021
258
+ ]
259
+ ],
260
+ inputs=[stocks, backtest_days, investment_size, start_year]
261
+ )
262
+
263
+ demo.launch(debug=True, )
nifty250.csv ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Company Name,Industry,Symbol,Series,ISIN Code
2
+ 360 ONE WAM Ltd.,Financial Services,360ONE,EQ,INE466L01038
3
+ Aarti Industries Ltd.,Chemicals,AARTIIND,EQ,INE769A01020
4
+ Aavas Financiers Ltd.,Financial Services,AAVAS,EQ,INE216P01012
5
+ Action Construction Equipment Ltd.,Capital Goods,ACE,EQ,INE731H01025
6
+ Aegis Logistics Ltd.,Oil Gas & Consumable Fuels,AEGISLOG,EQ,INE208C01025
7
+ Aether Industries Ltd.,Chemicals,AETHER,EQ,INE0BWX01014
8
+ Affle (India) Ltd.,Information Technology,AFFLE,EQ,INE00WC01027
9
+ Alembic Pharmaceuticals Ltd.,Healthcare,APLLTD,EQ,INE901L01018
10
+ Alkyl Amines Chemicals Ltd.,Chemicals,ALKYLAMINE,EQ,INE150B01039
11
+ Allcargo Logistics Ltd.,Services,ALLCARGO,EQ,INE418H01029
12
+ Alok Industries Ltd.,Textiles,ALOKINDS,EQ,INE270A01029
13
+ Amara Raja Energy & Mobility Ltd.,Automobile and Auto Components,ARE&M,EQ,INE885A01032
14
+ Amber Enterprises India Ltd.,Consumer Durables,AMBER,EQ,INE371P01015
15
+ Anand Rathi Wealth Ltd.,Financial Services,ANANDRATHI,EQ,INE463V01026
16
+ Angel One Ltd.,Financial Services,ANGELONE,EQ,INE732I01013
17
+ Anupam Rasayan India Ltd.,Chemicals,ANURAS,EQ,INE930P01018
18
+ Apar Industries Ltd.,Capital Goods,APARINDS,EQ,INE372A01015
19
+ Aptus Value Housing Finance India Ltd.,Financial Services,APTUS,EQ,INE852O01025
20
+ Archean Chemical Industries Ltd.,Chemicals,ACI,EQ,INE128X01021
21
+ Asahi India Glass Ltd.,Automobile and Auto Components,ASAHIINDIA,EQ,INE439A01020
22
+ Aster DM Healthcare Ltd.,Healthcare,ASTERDM,EQ,INE914M01019
23
+ AstraZenca Pharma India Ltd.,Healthcare,ASTRAZEN,EQ,INE203A01020
24
+ Avanti Feeds Ltd.,Fast Moving Consumer Goods,AVANTIFEED,EQ,INE871C01038
25
+ BEML Ltd.,Capital Goods,BEML,EQ,INE258A01016
26
+ BLS International Services Ltd.,Consumer Services,BLS,EQ,INE153T01027
27
+ Balaji Amines Ltd.,Chemicals,BALAMINES,EQ,INE050E01027
28
+ Balrampur Chini Mills Ltd.,Fast Moving Consumer Goods,BALRAMCHIN,EQ,INE119A01028
29
+ Bikaji Foods International Ltd.,Fast Moving Consumer Goods,BIKAJI,EQ,INE00E101023
30
+ Birla Corporation Ltd.,Construction Materials,BIRLACORPN,EQ,INE340A01012
31
+ Birlasoft Ltd.,Information Technology,BSOFT,EQ,INE836A01035
32
+ Blue Dart Express Ltd.,Services,BLUEDART,EQ,INE233B01017
33
+ Blue Star Ltd.,Consumer Durables,BLUESTARCO,EQ,INE472A01039
34
+ Bombay Burmah Trading Corporation Ltd.,Fast Moving Consumer Goods,BBTC,EQ,INE050A01025
35
+ Borosil Renewables Ltd.,Capital Goods,BORORENEW,EQ,INE666D01022
36
+ Brigade Enterprises Ltd.,Realty,BRIGADE,EQ,INE791I01019
37
+ C.E. Info Systems Ltd.,Information Technology,MAPMYINDIA,EQ,INE0BV301023
38
+ CCL Products (I) Ltd.,Fast Moving Consumer Goods,CCL,EQ,INE421D01022
39
+ CESC Ltd.,Power,CESC,EQ,INE486A01021
40
+ CIE Automotive India Ltd.,Automobile and Auto Components,CIEINDIA,EQ,INE536H01010
41
+ CSB Bank Ltd.,Financial Services,CSBBANK,EQ,INE679A01013
42
+ Campus Activewear Ltd.,Consumer Durables,CAMPUS,EQ,INE278Y01022
43
+ Can Fin Homes Ltd.,Financial Services,CANFINHOME,EQ,INE477A01020
44
+ Caplin Point Laboratories Ltd.,Healthcare,CAPLIPOINT,EQ,INE475E01026
45
+ Capri Global Capital Ltd.,Financial Services,CGCL,EQ,INE180C01042
46
+ Castrol India Ltd.,Oil Gas & Consumable Fuels,CASTROLIND,EQ,INE172A01027
47
+ Ceat Ltd.,Automobile and Auto Components,CEATLTD,EQ,INE482A01020
48
+ Cello World Ltd.,Consumer Durables,CELLO,EQ,INE0LMW01024
49
+ Central Bank of India,Financial Services,CENTRALBK,EQ,INE483A01010
50
+ Central Depository Services (India) Ltd.,Financial Services,CDSL,EQ,INE736A01011
51
+ Century Plyboards (India) Ltd.,Consumer Durables,CENTURYPLY,EQ,INE348B01021
52
+ Century Textile & Industries Ltd.,Forest Materials,CENTURYTEX,EQ,INE055A01016
53
+ Cera Sanitaryware Ltd,Consumer Durables,CERA,EQ,INE739E01017
54
+ Chalet Hotels Ltd.,Consumer Services,CHALET,EQ,INE427F01016
55
+ Chambal Fertilizers & Chemicals Ltd.,Chemicals,CHAMBLFERT,EQ,INE085A01013
56
+ Chemplast Sanmar Ltd.,Chemicals,CHEMPLASTS,EQ,INE488A01050
57
+ Chennai Petroleum Corporation Ltd.,Oil Gas & Consumable Fuels,CHENNPETRO,EQ,INE178A01016
58
+ Cholamandalam Financial Holdings Ltd.,Financial Services,CHOLAHLDNG,EQ,INE149A01033
59
+ City Union Bank Ltd.,Financial Services,CUB,EQ,INE491A01021
60
+ Clean Science and Technology Ltd.,Chemicals,CLEAN,EQ,INE227W01023
61
+ Cochin Shipyard Ltd.,Capital Goods,COCHINSHIP,EQ,INE704P01025
62
+ Computer Age Management Services Ltd.,Financial Services,CAMS,EQ,INE596I01012
63
+ Concord Biotech Ltd.,Healthcare,CONCORDBIO,EQ,INE338H01029
64
+ Craftsman Automation Ltd.,Automobile and Auto Components,CRAFTSMAN,EQ,INE00LO01017
65
+ CreditAccess Grameen Ltd.,Financial Services,CREDITACC,EQ,INE741K01010
66
+ Crompton Greaves Consumer Electricals Ltd.,Consumer Durables,CROMPTON,EQ,INE299U01018
67
+ Cyient Ltd.,Information Technology,CYIENT,EQ,INE136B01020
68
+ DCM Shriram Ltd.,Diversified,DCMSHRIRAM,EQ,INE499A01024
69
+ DOMS Industries Ltd.,Fast Moving Consumer Goods,DOMS,EQ,INE321T01012
70
+ Data Patterns (India) Ltd.,Capital Goods,DATAPATTNS,EQ,INE0IX101010
71
+ Deepak Fertilisers & Petrochemicals Corp. Ltd.,Chemicals,DEEPAKFERT,EQ,INE501A01019
72
+ Dummy Raymond Ltd.,Textiles,DUMMYRAYMD,BE,DUM301A01014
73
+ Dummy Sanofi India Ltd.,Healthcare,DUMMYSANOF,BE,DUM058A01010
74
+ E.I.D. Parry (India) Ltd.,Chemicals,EIDPARRY,EQ,INE126A01031
75
+ EIH Ltd.,Consumer Services,EIHOTEL,EQ,INE230A01023
76
+ EPL Ltd.,Capital Goods,EPL,EQ,INE255A01020
77
+ Easy Trip Planners Ltd.,Consumer Services,EASEMYTRIP,EQ,INE07O001026
78
+ Elecon Engineering Co. Ltd.,Capital Goods,ELECON,EQ,INE205B01031
79
+ Elgi Equipments Ltd.,Capital Goods,ELGIEQUIP,EQ,INE285A01027
80
+ Engineers India Ltd.,Construction,ENGINERSIN,EQ,INE510A01028
81
+ Equitas Small Finance Bank Ltd.,Financial Services,EQUITASBNK,EQ,INE063P01018
82
+ Eris Lifesciences Ltd.,Healthcare,ERIS,EQ,INE406M01024
83
+ Exide Industries Ltd.,Automobile and Auto Components,EXIDEIND,EQ,INE302A01020
84
+ FDC Ltd.,Healthcare,FDC,EQ,INE258B01022
85
+ Fine Organic Industries Ltd.,Chemicals,FINEORG,EQ,INE686Y01026
86
+ Finolex Cables Ltd.,Capital Goods,FINCABLES,EQ,INE235A01022
87
+ Finolex Industries Ltd.,Capital Goods,FINPIPE,EQ,INE183A01024
88
+ Firstsource Solutions Ltd.,Services,FSL,EQ,INE684F01012
89
+ Five-Star Business Finance Ltd.,Financial Services,FIVESTAR,EQ,INE128S01021
90
+ GMM Pfaudler Ltd.,Capital Goods,GMMPFAUDLR,EQ,INE541A01023
91
+ Garden Reach Shipbuilders & Engineers Ltd.,Capital Goods,GRSE,EQ,INE382Z01011
92
+ Gillette India Ltd.,Fast Moving Consumer Goods,GILLETTE,EQ,INE322A01010
93
+ Glenmark Life Sciences Ltd.,Healthcare,GLS,EQ,INE03Q201024
94
+ Glenmark Pharmaceuticals Ltd.,Healthcare,GLENMARK,EQ,INE935A01035
95
+ Global Health Ltd.,Healthcare,MEDANTA,EQ,INE474Q01031
96
+ Godawari Power & Ispat Ltd.,Capital Goods,GPIL,EQ,INE177H01021
97
+ Godfrey Phillips India Ltd.,Fast Moving Consumer Goods,GODFRYPHLP,EQ,INE260B01028
98
+ Granules India Ltd.,Healthcare,GRANULES,EQ,INE101D01020
99
+ Graphite India Ltd.,Capital Goods,GRAPHITE,EQ,INE371A01025
100
+ Great Eastern Shipping Co. Ltd.,Services,GESHIP,EQ,INE017A01032
101
+ Gujarat Ambuja Exports Ltd.,Fast Moving Consumer Goods,GAEL,EQ,INE036B01030
102
+ Gujarat Mineral Development Corporation Ltd.,Metals & Mining,GMDCLTD,EQ,INE131A01031
103
+ Gujarat Narmada Valley Fertilizers and Chemicals Ltd.,Chemicals,GNFC,EQ,INE113A01013
104
+ Gujarat Pipavav Port Ltd.,Services,GPPL,EQ,INE517F01014
105
+ Gujarat State Fertilizers & Chemicals Ltd.,Chemicals,GSFC,EQ,INE026A01025
106
+ Gujarat State Petronet Ltd.,Oil Gas & Consumable Fuels,GSPL,EQ,INE246F01010
107
+ H.E.G. Ltd.,Capital Goods,HEG,EQ,INE545A01016
108
+ HBL Power Systems Ltd.,Automobile and Auto Components,HBLPOWER,EQ,INE292B01021
109
+ HFCL Ltd.,Telecommunication,HFCL,EQ,INE548A01028
110
+ Happiest Minds Technologies Ltd.,Information Technology,HAPPSTMNDS,EQ,INE419U01012
111
+ Happy Forgings Ltd.,Capital Goods,HAPPYFORGE,EQ,INE330T01021
112
+ Himadri Speciality Chemical Ltd.,Chemicals,HSCL,EQ,INE019C01026
113
+ Hindustan Copper Ltd.,Metals & Mining,HINDCOPPER,EQ,INE531E01026
114
+ Hitachi Energy India Ltd.,Capital Goods,POWERINDIA,EQ,INE07Y701011
115
+ Home First Finance Company India Ltd.,Financial Services,HOMEFIRST,EQ,INE481N01025
116
+ Honasa Consumer Ltd.,Fast Moving Consumer Goods,HONASA,EQ,INE0J5401028
117
+ Housing & Urban Development Corporation Ltd.,Financial Services,HUDCO,EQ,INE031A01017
118
+ IDFC Ltd.,Financial Services,IDFC,EQ,INE043D01016
119
+ IIFL Finance Ltd.,Financial Services,IIFL,EQ,INE530B01024
120
+ IRB Infrastructure Developers Ltd.,Construction,IRB,EQ,INE821I01022
121
+ IRCON International Ltd.,Construction,IRCON,EQ,INE962Y01021
122
+ ITI Ltd.,Telecommunication,ITI,EQ,INE248A01017
123
+ India Cements Ltd.,Construction Materials,INDIACEM,EQ,INE383A01012
124
+ Indiabulls Housing Finance Ltd.,Financial Services,IBULHSGFIN,EQ,INE148I01020
125
+ Indiamart Intermesh Ltd.,Consumer Services,INDIAMART,EQ,INE933S01016
126
+ Indian Energy Exchange Ltd.,Financial Services,IEX,EQ,INE022Q01020
127
+ Indian Overseas Bank,Financial Services,IOB,EQ,INE565A01014
128
+ Indigo Paints Ltd.,Consumer Durables,INDIGOPNTS,EQ,INE09VQ01012
129
+ Inox Wind Ltd.,Capital Goods,INOXWIND,EQ,INE066P01011
130
+ Intellect Design Arena Ltd.,Information Technology,INTELLECT,EQ,INE306R01017
131
+ J.B. Chemicals & Pharmaceuticals Ltd.,Healthcare,JBCHEPHARM,EQ,INE572A01036
132
+ JBM Auto Ltd.,Automobile and Auto Components,JBMA,EQ,INE927D01044
133
+ JK Lakshmi Cement Ltd.,Construction Materials,JKLAKSHMI,EQ,INE786A01032
134
+ JK Paper Ltd.,Forest Materials,JKPAPER,EQ,INE789E01012
135
+ JM Financial Ltd.,Financial Services,JMFINANCIL,EQ,INE780C01023
136
+ Jai Balaji Industries Ltd.,Metals & Mining,JAIBALAJI,BE,INE091G01018
137
+ Jammu & Kashmir Bank Ltd.,Financial Services,J&KBANK,EQ,INE168A01041
138
+ Jindal Saw Ltd.,Capital Goods,JINDALSAW,EQ,INE324A01024
139
+ Jubilant Ingrevia Ltd.,Chemicals,JUBLINGREA,EQ,INE0BY001018
140
+ Jubilant Pharmova Ltd.,Healthcare,JUBLPHARMA,EQ,INE700A01033
141
+ Jupiter Wagons Ltd.,Capital Goods,JWL,EQ,INE209L01016
142
+ Justdial Ltd.,Consumer Services,JUSTDIAL,EQ,INE599M01018
143
+ Jyothy Labs Ltd.,Fast Moving Consumer Goods,JYOTHYLAB,EQ,INE668F01031
144
+ KNR Constructions Ltd.,Construction,KNRCON,EQ,INE634I01029
145
+ KRBL Ltd.,Fast Moving Consumer Goods,KRBL,EQ,INE001B01026
146
+ KSB Ltd.,Capital Goods,KSB,EQ,INE999A01023
147
+ Kalpataru Projects International Ltd.,Construction,KPIL,EQ,INE220B01022
148
+ Karur Vysya Bank Ltd.,Financial Services,KARURVYSYA,EQ,INE036D01028
149
+ Kaynes Technology India Ltd.,Capital Goods,KAYNES,EQ,INE918Z01012
150
+ Kec International Ltd.,Construction,KEC,EQ,INE389H01022
151
+ Kfin Technologies Ltd.,Financial Services,KFINTECH,EQ,INE138Y01010
152
+ Krishna Institute of Medical Sciences Ltd.,Healthcare,KIMS,EQ,INE967H01017
153
+ Latent View Analytics Ltd.,Information Technology,LATENTVIEW,EQ,INE0I7C01011
154
+ Laxmi Organic Industries Ltd.,Chemicals,LXCHEM,EQ,INE576O01020
155
+ Lemon Tree Hotels Ltd.,Consumer Services,LEMONTREE,EQ,INE970X01018
156
+ MMTC Ltd.,Services,MMTC,EQ,INE123F01029
157
+ MTAR Technologies Ltd.,Capital Goods,MTARTECH,EQ,INE864I01014
158
+ Mahanagar Gas Ltd.,Oil Gas & Consumable Fuels,MGL,EQ,INE002S01010
159
+ Maharashtra Seamless Ltd.,Capital Goods,MAHSEAMLES,EQ,INE271B01025
160
+ Mahindra Holidays & Resorts India Ltd.,Consumer Services,MHRIL,EQ,INE998I01010
161
+ Mahindra Lifespace Developers Ltd.,Realty,MAHLIFE,EQ,INE813A01018
162
+ Manappuram Finance Ltd.,Financial Services,MANAPPURAM,EQ,INE522D01027
163
+ Mangalore Refinery & Petrochemicals Ltd.,Oil Gas & Consumable Fuels,MRPL,EQ,INE103A01014
164
+ Mastek Ltd.,Information Technology,MASTEK,EQ,INE759A01021
165
+ Medplus Health Services Ltd.,Consumer Services,MEDPLUS,EQ,INE804L01022
166
+ Metropolis Healthcare Ltd.,Healthcare,METROPOLIS,EQ,INE112L01020
167
+ Minda Corporation Ltd.,Automobile and Auto Components,MINDACORP,EQ,INE842C01021
168
+ Motilal Oswal Financial Services Ltd.,Financial Services,MOTILALOFS,EQ,INE338I01027
169
+ Multi Commodity Exchange of India Ltd.,Financial Services,MCX,EQ,INE745G01035
170
+ NATCO Pharma Ltd.,Healthcare,NATCOPHARM,EQ,INE987B01026
171
+ NBCC (India) Ltd.,Construction,NBCC,EQ,INE095N01031
172
+ NCC Ltd.,Construction,NCC,EQ,INE868B01028
173
+ NLC India Ltd.,Power,NLCINDIA,EQ,INE589A01014
174
+ NMDC Steel Ltd.,Metals & Mining,NSLNISP,EQ,INE0NNS01018
175
+ Narayana Hrudayalaya Ltd.,Healthcare,NH,EQ,INE410P01011
176
+ National Aluminium Co. Ltd.,Metals & Mining,NATIONALUM,EQ,INE139A01034
177
+ Navin Fluorine International Ltd.,Chemicals,NAVINFLUOR,EQ,INE048G01026
178
+ Network18 Media & Investments Ltd.,Media Entertainment & Publication,NETWORK18,EQ,INE870H01013
179
+ Nippon Life India Asset Management Ltd.,Financial Services,NAM-INDIA,EQ,INE298J01013
180
+ Nuvama Wealth Management Ltd.,Financial Services,NUVAMA,EQ,INE531F01015
181
+ Nuvoco Vistas Corporation Ltd.,Construction Materials,NUVOCO,EQ,INE118D01016
182
+ Olectra Greentech Ltd.,Automobile and Auto Components,OLECTRA,EQ,INE260D01016
183
+ PCBL Ltd.,Chemicals,PCBL,EQ,INE602A01031
184
+ PNB Housing Finance Ltd.,Financial Services,PNBHOUSING,EQ,INE572E01012
185
+ PNC Infratech Ltd.,Construction,PNCINFRA,EQ,INE195J01029
186
+ PVR INOX Ltd.,Media Entertainment & Publication,PVRINOX,EQ,INE191H01014
187
+ Piramal Pharma Ltd.,Healthcare,PPLPHARMA,EQ,INE0DK501011
188
+ Poly Medicure Ltd.,Healthcare,POLYMED,EQ,INE205C01021
189
+ Praj Industries Ltd.,Capital Goods,PRAJIND,EQ,INE074A01025
190
+ Prince Pipes and Fittings Ltd.,Capital Goods,PRINCEPIPE,EQ,INE689W01016
191
+ Prism Johnson Ltd.,Construction Materials,PRSMJOHNSN,EQ,INE010A01011
192
+ Quess Corp Ltd.,Services,QUESS,EQ,INE615P01015
193
+ R R Kabel Ltd.,Capital Goods,RRKABEL,EQ,INE777K01022
194
+ RBL Bank Ltd.,Financial Services,RBLBANK,EQ,INE976G01028
195
+ RHI MAGNESITA INDIA LTD.,Capital Goods,RHIM,EQ,INE743M01012
196
+ RITES Ltd.,Construction,RITES,EQ,INE320J01015
197
+ Radico Khaitan Ltd,Fast Moving Consumer Goods,RADICO,EQ,INE944F01028
198
+ Railtel Corporation Of India Ltd.,Telecommunication,RAILTEL,EQ,INE0DD101019
199
+ Rainbow Childrens Medicare Ltd.,Healthcare,RAINBOW,EQ,INE961O01016
200
+ Rajesh Exports Ltd.,Consumer Durables,RAJESHEXPO,EQ,INE343B01030
201
+ Ramkrishna Forgings Ltd.,Automobile and Auto Components,RKFORGE,EQ,INE399G01023
202
+ Rashtriya Chemicals & Fertilizers Ltd.,Chemicals,RCF,EQ,INE027A01015
203
+ Ratnamani Metals & Tubes Ltd.,Capital Goods,RATNAMANI,EQ,INE703B01027
204
+ RattanIndia Enterprises Ltd.,Consumer Services,RTNINDIA,EQ,INE834M01019
205
+ Raymond Ltd.,Realty,RAYMOND,BE,INE301A01014
206
+ Redington Ltd.,Services,REDINGTON,EQ,INE891D01026
207
+ Restaurant Brands Asia Ltd.,Consumer Services,RBA,EQ,INE07T201019
208
+ Route Mobile Ltd.,Telecommunication,ROUTE,EQ,INE450U01017
209
+ SBFC Finance Ltd.,Financial Services,SBFC,EQ,INE423Y01016
210
+ Safari Industries (India) Ltd.,Consumer Durables,SAFARI,EQ,INE429E01023
211
+ Sanofi India Ltd.,Healthcare,SANOFI,EQ,INE058A01010
212
+ Sapphire Foods India Ltd.,Consumer Services,SAPPHIRE,EQ,INE806T01012
213
+ Saregama India Ltd,Media Entertainment & Publication,SAREGAMA,EQ,INE979A01025
214
+ Schneider Electric Infrastructure Ltd.,Capital Goods,SCHNEIDER,EQ,INE839M01018
215
+ Shree Renuka Sugars Ltd.,Fast Moving Consumer Goods,RENUKA,EQ,INE087H01022
216
+ Shyam Metalics and Energy Ltd.,Capital Goods,SHYAMMETL,EQ,INE810G01011
217
+ Signatureglobal (India) Ltd.,Realty,SIGNATURE,EQ,INE903U01023
218
+ Sobha Ltd.,Realty,SOBHA,EQ,INE671H01015
219
+ Sonata Software Ltd.,Information Technology,SONATSOFTW,EQ,INE269A01021
220
+ Sterling and Wilson Renewable Energy Ltd.,Construction,SWSOLAR,EQ,INE00M201021
221
+ Sterlite Technologies Ltd.,Telecommunication,STLTECH,EQ,INE089C01029
222
+ Sun Pharma Advanced Research Company Ltd.,Healthcare,SPARC,EQ,INE232I01014
223
+ Sunteck Realty Ltd.,Realty,SUNTECK,EQ,INE805D01034
224
+ Suven Pharmaceuticals Ltd.,Healthcare,SUVENPHAR,EQ,INE03QK01018
225
+ Swan Energy Ltd.,Diversified,SWANENERGY,EQ,INE665A01038
226
+ Syrma SGS Technology Ltd.,Capital Goods,SYRMA,EQ,INE0DYJ01015
227
+ TV18 Broadcast Ltd.,Media Entertainment & Publication,TV18BRDCST,EQ,INE886H01027
228
+ TVS Supply Chain Solutions Ltd.,Services,TVSSCS,EQ,INE395N01027
229
+ Tamilnad Mercantile Bank Ltd.,Financial Services,TMB,EQ,INE668A01016
230
+ Tanla Platforms Ltd.,Information Technology,TANLA,EQ,INE483C01032
231
+ Tata Investment Corporation Ltd.,Financial Services,TATAINVEST,EQ,INE672A01018
232
+ Tata Teleservices (Maharashtra) Ltd.,Telecommunication,TTML,EQ,INE517B01013
233
+ Tejas Networks Ltd.,Telecommunication,TEJASNET,EQ,INE010J01012
234
+ Titagarh Rail Systems Ltd.,Capital Goods,TITAGARH,EQ,INE615H01020
235
+ Trident Ltd.,Textiles,TRIDENT,EQ,INE064C01022
236
+ Triveni Engineering & Industries Ltd.,Fast Moving Consumer Goods,TRIVENI,EQ,INE256C01024
237
+ Triveni Turbine Ltd.,Capital Goods,TRITURBINE,EQ,INE152M01016
238
+ UCO Bank,Financial Services,UCOBANK,EQ,INE691A01018
239
+ UTI Asset Management Company Ltd.,Financial Services,UTIAMC,EQ,INE094J01016
240
+ Ujjivan Small Finance Bank Ltd.,Financial Services,UJJIVANSFB,EQ,INE551W01018
241
+ Usha Martin Ltd.,Capital Goods,USHAMART,EQ,INE228A01035
242
+ V-Guard Industries Ltd.,Consumer Durables,VGUARD,EQ,INE951I01027
243
+ V.I.P. Industries Ltd.,Consumer Durables,VIPIND,EQ,INE054A01027
244
+ Vaibhav Global Ltd.,Consumer Durables,VAIBHAVGBL,EQ,INE884A01027
245
+ Vardhman Textiles Ltd.,Textiles,VTL,EQ,INE825A01020
246
+ Varroc Engineering Ltd.,Automobile and Auto Components,VARROC,EQ,INE665L01035
247
+ Vijaya Diagnostic Centre Ltd.,Healthcare,VIJAYA,EQ,INE043W01024
248
+ Welspun Corp Ltd.,Capital Goods,WELCORP,EQ,INE191B01025
249
+ Welspun Living Ltd.,Textiles,WELSPUNLIV,EQ,INE192B01031
250
+ Westlife Foodworld Ltd.,Consumer Services,WESTLIFE,EQ,INE274F01020
251
+ Whirlpool of India Ltd.,Consumer Durables,WHIRLPOOL,EQ,INE716A01013
252
+ Zensar Technolgies Ltd.,Information Technology,ZENSARTECH,EQ,INE520A01027
253
+ eClerx Services Ltd.,Services,ECLERX,EQ,INE738I01010
nifty50.csv ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Company Name,Industry,Symbol,Series,ISIN Code
2
+ Adani Enterprises Ltd.,Metals & Mining,ADANIENT,EQ,INE423A01024
3
+ Adani Ports and Special Economic Zone Ltd.,Services,ADANIPORTS,EQ,INE742F01042
4
+ Apollo Hospitals Enterprise Ltd.,Healthcare,APOLLOHOSP,EQ,INE437A01024
5
+ Asian Paints Ltd.,Consumer Durables,ASIANPAINT,EQ,INE021A01026
6
+ Axis Bank Ltd.,Financial Services,AXISBANK,EQ,INE238A01034
7
+ Bajaj Auto Ltd.,Automobile and Auto Components,BAJAJ-AUTO,EQ,INE917I01010
8
+ Bajaj Finance Ltd.,Financial Services,BAJFINANCE,EQ,INE296A01024
9
+ Bajaj Finserv Ltd.,Financial Services,BAJAJFINSV,EQ,INE918I01026
10
+ Bharat Petroleum Corporation Ltd.,Oil Gas & Consumable Fuels,BPCL,EQ,INE029A01011
11
+ Bharti Airtel Ltd.,Telecommunication,BHARTIARTL,EQ,INE397D01024
12
+ Britannia Industries Ltd.,Fast Moving Consumer Goods,BRITANNIA,EQ,INE216A01030
13
+ Cipla Ltd.,Healthcare,CIPLA,EQ,INE059A01026
14
+ Coal India Ltd.,Oil Gas & Consumable Fuels,COALINDIA,EQ,INE522F01014
15
+ Divi's Laboratories Ltd.,Healthcare,DIVISLAB,EQ,INE361B01024
16
+ Dr. Reddy's Laboratories Ltd.,Healthcare,DRREDDY,EQ,INE089A01023
17
+ Eicher Motors Ltd.,Automobile and Auto Components,EICHERMOT,EQ,INE066A01021
18
+ Grasim Industries Ltd.,Construction Materials,GRASIM,EQ,INE047A01021
19
+ HCL Technologies Ltd.,Information Technology,HCLTECH,EQ,INE860A01027
20
+ HDFC Bank Ltd.,Financial Services,HDFCBANK,EQ,INE040A01034
21
+ HDFC Life Insurance Company Ltd.,Financial Services,HDFCLIFE,EQ,INE795G01014
22
+ Hero MotoCorp Ltd.,Automobile and Auto Components,HEROMOTOCO,EQ,INE158A01026
23
+ Hindalco Industries Ltd.,Metals & Mining,HINDALCO,EQ,INE038A01020
24
+ Hindustan Unilever Ltd.,Fast Moving Consumer Goods,HINDUNILVR,EQ,INE030A01027
25
+ ICICI Bank Ltd.,Financial Services,ICICIBANK,EQ,INE090A01021
26
+ ITC Ltd.,Fast Moving Consumer Goods,ITC,EQ,INE154A01025
27
+ IndusInd Bank Ltd.,Financial Services,INDUSINDBK,EQ,INE095A01012
28
+ Infosys Ltd.,Information Technology,INFY,EQ,INE009A01021
29
+ JSW Steel Ltd.,Metals & Mining,JSWSTEEL,EQ,INE019A01038
30
+ Kotak Mahindra Bank Ltd.,Financial Services,KOTAKBANK,EQ,INE237A01028
31
+ LTIMindtree Ltd.,Information Technology,LTIM,EQ,INE214T01019
32
+ Larsen & Toubro Ltd.,Construction,LT,EQ,INE018A01030
33
+ Mahindra & Mahindra Ltd.,Automobile and Auto Components,M&M,EQ,INE101A01026
34
+ Maruti Suzuki India Ltd.,Automobile and Auto Components,MARUTI,EQ,INE585B01010
35
+ NTPC Ltd.,Power,NTPC,EQ,INE733E01010
36
+ Oil & Natural Gas Corporation Ltd.,Oil Gas & Consumable Fuels,ONGC,EQ,INE213A01029
37
+ Power Grid Corporation of India Ltd.,Power,POWERGRID,EQ,INE752E01010
38
+ Reliance Industries Ltd.,Oil Gas & Consumable Fuels,RELIANCE,EQ,INE002A01018
39
+ SBI Life Insurance Company Ltd.,Financial Services,SBILIFE,EQ,INE123W01016
40
+ Shriram Finance Ltd.,Financial Services,SHRIRAMFIN,EQ,INE721A01013
41
+ State Bank of India,Financial Services,SBIN,EQ,INE062A01020
42
+ Sun Pharmaceutical Industries Ltd.,Healthcare,SUNPHARMA,EQ,INE044A01036
43
+ Tata Consultancy Services Ltd.,Information Technology,TCS,EQ,INE467B01029
44
+ Tata Consumer Products Ltd.,Fast Moving Consumer Goods,TATACONSUM,EQ,INE192A01025
45
+ Tata Motors Ltd.,Automobile and Auto Components,TATAMOTORS,EQ,INE155A01022
46
+ Tata Steel Ltd.,Metals & Mining,TATASTEEL,EQ,INE081A01020
47
+ Tech Mahindra Ltd.,Information Technology,TECHM,EQ,INE669C01036
48
+ Titan Company Ltd.,Consumer Durables,TITAN,EQ,INE280A01028
49
+ UltraTech Cement Ltd.,Construction Materials,ULTRACEMCO,EQ,INE481G01011
50
+ Wipro Ltd.,Information Technology,WIPRO,EQ,INE075A01022
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ autopep8
2
+ yfinance
3
+ pyportfolioopt
4
+ numpy<2
5
+ pandas
6
+ matplotlib<3.6
7
+ seaborn
8
+ scipy
9
+ retry
10
+ gradio
11
+ mplfinance
12
+ seaborn
13
+ seaborn[stats]
14
+ tabulate