In [29]:
import numpy as np
import pandas as pd


import matplotlib.pyplot as plt
from nsepy.archives import get_price_history
from datetime import date


symbol="VEDL"
year=[2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016]
month=[1,2,3,4,5,6,7,8,9,10,11,12]
In [30]:
r1=[]
#1999 december month last day close value
result=get_price_history(stock = symbol,start = date(2000,12,1),end = date(2000,12,31))
if result.empty:
    r1.append(0)
else: 
    s2=result[['Close']]
    v1=s2.values.T.tolist()
    value=(v1[0][-1])
    r1.append(value)
    
In [31]:
for y in year:
    for m in month:
        if m in [1,3,5,7,8,10,12]:
            result=get_price_history(stock = symbol,start = date(y,m,1),end = date(y,m,31))
            if result.empty:
                r1.append(0)
            else: 
                s2=result[['Close']]
                v1=s2.values.T.tolist()
                value=(v1[0][-1])
                r1.append(value)
                
        elif  y in [2000,2004,2008,2012,2016] and m==2: #condition for leapyear
            result=get_price_history(stock = symbol,start = date(y,m,1),end = date(y,m,29))
            if result.empty:
                r1.append(0)
            else:    
                s2=result[['Close']]
                #v=s1.values.T.tolist()
                v1=s2.values.T.tolist()
                value=(v1[0][-1])
                r1.append(value)
        elif y not in [2000,2004,2008,2012,2016] and m==2:
            result=get_price_history(stock = symbol,start = date(y,m,1),end = date(y,m,28))
            if result.empty:
                r1.append(0)
            else:    
                s2=result[['Close']]
                #v=s1.values.T.tolist()
                v1=s2.values.T.tolist()
                value=(v1[0][-1])
                r1.append(value)    
                
        else:
            result=get_price_history(stock = symbol,start = date(y,m,1),end = date(y,m,30))
            if result.empty:
                r1.append(0)
            else:    
                s2=result[['Close']]
                #v=s1.values.T.tolist()
                v1=s2.values.T.tolist()
                value=(v1[0][-1])
                r1.append(value)


m=["January","February","March","April","May","June","July","August","September","October","November","December"]
In [25]:
[73.85, 97.3, 70.35, 64.5, 56.15, 54.15, 55.15, 49.65, 44.95, 44.1, 39.3, 73.7, 73.85, 100.35, 83.4, 52.9, 61.7, 61.55, 50.7, 52.25, 55.05, 49.0, 45.35, 56.05, 50.05, 47.75, 48.05, 48.3, 57.85, 68.55, 119.05, 77.3, 83.4, 79.6, 65.6, 67.5, 68.95, 65.35, 71.45, 61.35, 82.25, 133.4, 165.95, 171.65, 210.6, 303.65, 311.0, 441.5, 593.4, 604.7, 583.65, 478.5, 417.95, 353.85, 384.65, 538.0, 563.3, 636.3, 752.0, 809.0, 1032.8, 1317.9, 814.0, 731.7, 686.2, 655.1, 579.2, 714.25, 726.8, 1049.9, 943.65, 1026.25, 1010.8, 1059.0, 1127.8, 1284.7, 1337.2, 1219.35, 1116.9, 969.0, 953.95, 975.75, 1188.3, 1264.15, 1411.0, 1896.7, 1782.95, 1703.45, 1781.8, 1677.1, 1776.6, 1801.1, 1944.3, 2524.25, 3732.35, 3450.7, 3821.2, 3038.35, 3464.65, 3151.55, 4216.45, 4292.05, 3385.3, 3372.7, 158.5, 119.85, 80.6, 74.65, 85.85, 84.95, 81.0, 99.6, 111.85, 165.4, 182.6, 241.0, 212.3, 265.7, 302.45, 368.25, 410.8, 346.75, 400.35, 470.45, 428.95, 381.9, 352.65, 361.25, 317.8, 328.2, 321.6, 307.7, 328.55, 326.1, 261.2, 291.35, 313.9, 289.9, 282.05, 275.05, 234.05, 200.55, 207.35, 183.5, 163.4, 217.95, 214.4, 194.7, 188.4, 187.15, 191.65, 190.2, 171.45, 171.2, 171.15, 182.2, 195.45, 186.55, 154.85, 155.5, 158.75, 163.9, 142.8, 127.85, 188.75, 180.75, 202.0, 183.1, 201.95, 188.4, 177.65, 188.55, 185.35, 280.45, 292.35, 290.25, 277.15, 272.5, 255.95, 231.35, 214.5, 201.95, 217.6, 189.5, 209.85, 196.45, 174.15, 130.25, 98.65, 84.7, 99.95, 89.95, 90.4, 71.75, 70.6, 87.35, 0, 0, 0, 0, 0, 0, 0, 0, 0]
In [32]:
value=[]
j=0
for i in r1:
    if i >0 and r1[j+1]>0:
        if j<len(r1):
            s=(r1[j+1]-i)*100/i
            value.append(s)
            j=j+1
    elif i==0 and r1[j+1]==0:
        value.append(0)
        j=j+1
In [33]:
k=(value[i:i+12] for i in range(0, len(value), 12))

#print len(k)

out=[]
for s in k:
    out.append(s)

print len(out)

m=["January","February","March","April","May","June","July","August","September","October","November","December"]
17
In [34]:
import numpy as np
import pandas as pd
import seaborn as sns

import matplotlib.pyplot as plt

%pylab inline

import seaborn.matrix as smatrix




#actual verification
#sns.set(style="white")
#s=np.array(out)
sns.set()
data = pd.DataFrame(out, columns=m, index = range(2000, 2017, 1))
print data

fig, ax = plt.subplots()
# the size of A4 paper
fig.set_size_inches(11.7, 8.27)

# plot heatmap
sns.heatmap(data.T,cbar=False,
                square=False,robust=True,annot=True,fmt=".1f",annot_kws={"size": 10},linewidths=0.5,cmap="RdYlGn", ax=ax)
#print ax
cax = plt.gcf().axes[-1]
cax.tick_params(width=12)
cax = plt.gcf().axes[-1]
cax.tick_params(labelsize=20)
#turn the axis label
for item in ax.get_yticklabels():
    item.set_rotation(0)

for item in ax.get_xticklabels():
    item.set_rotation(90)
Populating the interactive namespace from numpy and matplotlib
        January   February      March      April        May       June  \
2000  31.753555 -27.697842  -8.315565 -12.945736  -3.561888   1.846722   
2001  35.883548 -16.890882 -36.570743  16.635161  -0.243112 -17.627945   
2002  -4.595405   0.628272   0.520291  19.772257  18.496111  73.668855   
2003  -5.221175   9.334353 -14.135759  34.066830  62.188450  24.400300   
2004   1.904280  -3.481065 -18.015934 -12.654127 -15.336763   8.704253   
2005  27.604570 -38.235071 -10.110565  -6.218396  -4.532206 -11.586017   
2006   4.768500   6.496695  13.912041   4.086557  -8.813192  -8.402017   
2007  34.422395  -5.997258  -4.458902   4.599489  -5.876080   5.932860   
2008 -20.487020  14.030642  -9.036988  33.789723   1.792978 -21.126268   
2009  -1.048340  -4.649794  22.962963  12.299197  47.876620  10.399033   
2010 -15.591529  15.457823  17.509679  -8.821341 -10.968644  -7.659073   
2011  -0.745701 -19.901871  11.542879   7.739832  -7.645747  -2.707830   
2012  33.384333  -1.628814  -9.188433  -3.235747  -0.663482   2.404488   
2013  -4.553594 -16.992763   0.419761   2.090032   3.244094 -12.873703   
2014  -6.709582  -5.705945   6.135660  -1.697163  51.308336   4.243181   
2015  -5.850816   7.749443 -12.913603  10.738786  -6.385513 -11.351489   
2016 -20.630531  -1.602787  23.725212   0.000000   0.000000   0.000000   

           July     August  September    October   November   December  
2000  -9.972801  -9.466264  -1.890990 -10.884354  87.531807   0.203528  
2001   3.057199   5.358852 -10.990009  -7.448980  23.594267 -10.704728  
2002 -35.069299   7.891332  -4.556355 -17.587940   2.896341   2.148148  
2003   3.434770  22.691523  44.183286   2.420550  41.961415  34.405436  
2004  39.867412   4.702602  12.959347  18.183247   7.579787  27.663782  
2005  23.316644   1.757088  44.455146 -10.120011   8.753245  -1.505481  
2006 -13.242009  -1.553148   2.285235  21.783244   6.383068  11.616501  
2007   1.379039   7.950697  29.828216  47.859760  -7.546184  10.736952  
2008  -0.372197 -95.300501 -24.384858 -32.749270  -7.382134  15.003349  
2009  31.982475 -11.908714  25.153085  13.831389  21.755662  11.554650  
2010   2.438679 -12.027682   3.272498  -2.010969  -4.322139   6.776081  
2011  -2.481829 -14.906381 -14.313181   3.390676 -11.502291 -10.953678  
2012  -0.756588  -9.858044  -0.145815  -0.029206   6.456325   7.272228  
2013 -10.469188  47.633946  -4.238411  11.756570  -9.356436  10.294921  
2014  -0.718317  -4.513351  -1.677792  -6.073394  -9.611252  -7.283337  
2015 -25.208154 -24.261036 -14.140902  18.004723 -10.005003   0.500278  
2016   0.000000   0.000000   0.000000   0.000000   0.000000   0.000000  
In [ ]: