-
Notifications
You must be signed in to change notification settings - Fork 4
/
nifty-fifty.py
71 lines (66 loc) · 3.76 KB
/
nifty-fifty.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
67
68
69
70
71
# coding: utf-8
########################################################################################################
##modules required : pandas
#pandas module can be installed using pip command
#pip install pandas
#if inside proxy server" pip --proxy proxy_server:port install pandas
#######################################################################################################
###let me know if any issues
########################################################################################################
import pandas as pd
import os
import time
import requests
from datetime import datetime, timedelta
##########################################################################################
timestr = time.strftime("%Y%m%d")
mydate=time.strftime("%d%m%Y")
s = mydate
date = datetime.strptime(s, "%d%m%Y")
modified_date = date + timedelta(days=-1)
old_date=datetime.strftime(modified_date, "%d%m%Y")
niftyfile="nifty_100.csv_"+timestr
os.system('curl https://www.nseindia.com/content/indices/ind_nifty100list.csv >'+ niftyfile)
volatalityfile="volatality.csv"
def exists(path):
r = requests.head(path)
return r.status_code == requests.codes.ok
#downloading the files
if exists('https://www.nseindia.com/archives/nsccl/volt/CMVOLT_'+ mydate +'.CSV') == True:
os.system('curl https://www.nseindia.com/archives/nsccl/volt/CMVOLT_'+ mydate +'.CSV >'+volatalityfile)
else:
os.system('curl https://www.nseindia.com/archives/nsccl/volt/CMVOLT_'+ old_date +'.CSV >'+volatalityfile)
#reading the files
df1 = pd.read_csv(niftyfile, header=None )
df2 = pd.read_csv(volatalityfile, header=None)
##########################################################################
#merging files on the basis of columns in both files
##########################################################################
merger = pd.merge(df1, df2, left_on = 2, right_on = 1)
merger.to_csv('combined.csv', header=None, index=False)
df=pd.read_csv('combined.csv')
#sorting values as required
df = df.sort_values(by=['Underlying Annualised Volatility (F) = E*Sqrt(365)', 'Previous Day Underlying Volatility (D)','Current Day Underlying Daily Volatility (E) = Sqrt(0.94*D*D + 0.06*C*C)'])
df.loc[:,'Previous Day Underlying Volatility (D)'] *= 100
df.loc[:,'Current Day Underlying Daily Volatility (E) = Sqrt(0.94*D*D + 0.06*C*C)'] *= 100
df.loc[:,'Underlying Annualised Volatility (F) = E*Sqrt(365)'] *= 100
################################################################################
#dropping columns as required
##########################################################################
df.drop(df.columns[[7,10]], axis=1, inplace=True)
df=df.loc[df['Current Day Underlying Daily Volatility (E) = Sqrt(0.94*D*D + 0.06*C*C)'] >= 2]
df.drop(df.columns[[3,4,5]], axis=1, inplace=True)
datestr=df.iloc[3,3]
df.drop(df.columns[[3]], axis=1, inplace=True)
df = df.sort_values('Current Day Underlying Daily Volatility (E) = Sqrt(0.94*D*D + 0.06*C*C)',ascending=[False])
df.rename(columns={'Previous Day Underlying Volatility (D)': 'previous volatality', 'Current Day Underlying Daily Volatility (E) = Sqrt(0.94*D*D + 0.06*C*C)': 'current volatality','Underlying Annualised Volatility (F) = E*Sqrt(365)':'annual volatality','Underlying Previous Day Close Price (B)':'previous close','Underlying Close Price (A)':'current close'}, inplace=True)
#datestr="testing"
final_file="fresh_data_"+datestr+".csv"
########################################################################################
#generating final file
##########################################################################################
df.to_csv(final_file,header=True)
os.remove('combined.csv')
os.system("mailx -a 'fresh_data_" +datestr+".csv' -s 'volatility' shashankshawak7@gmail.com < /dev/null" )
os.system('rm '+ niftyfile)
os.system('rm '+volatalityfile)