how to solve this

0 votes
from nsepy import get_history

from datetime import date

import csv

company=['TCS','RELIANCE','INFY','HDFCBANK','ITC','SUNPHARMA','HINDUNILVR','COALINDIA','ONGC','HDFC','SBIN','BHARTIARTL','WIPRO','ICICIBANK','KOTAKBANK','HCLTECH','LT','MARUTI','TATAMOTORS','NTPC','AXISBANK','IOC','ULTRACEMCO','ASIANPAINT','HINDZINC','M&M','POWERGRID','INFRATEL','BAJAJ-AUTO','LUPIN','BPCL','BOSCHLTD','HEROMOTOCO','INDUSINDBK','EICHERMOT','DRREDDY','ADANIPORTS','GODREJCP','TECHM','GAIL','DABUR','AUROPHARMA','SHREECEM','CIPLA','IDEA','SIEMENS','NMDC','BAJFINANCE','ZEEL','YESBANK','AMBUJACEM','GRASIM','MOTHERSUMI','BANKBARODA','MCDOWELL-N','CADILAHC','GLAXO','BRITANNIA','MARICO','INDIGO','TATASTEEL','JSWSTEEL','ASHOKLEY','PIDILITIND','TITAN','OFSS','BEL','CAIRN','BHEL','IBULHSGFIN','BAJAJFINSV','ABB','NHPC','HINDPETRO','VEDL','DIVISLAB','ACC','GSKCONS','LICHSGFIN','CONCOR','CUMMINSIND','TORNTPHARM','PFC','COLPAL','GLENMARK','UBL','SRTRANSFIN','EMAMILTD','UPL','DLF','PGHH','BHARATFORG','HAVELLS','OIL','PETRONET','CASTROLIND','APOLLOHOSP','RAJESHEXPO','HINDALCO','PEL','SAIL','TATAPOWER','BERGEPAINT','PNB','RECLTD','IDFCBANK','BAJAJHLDNG','MRF','ALKEM','TVSMOTOR','KANSAINER','AMARAJABAT','SUNTV','SUNDARMFIN','GILLETTE','BLUEDART','RELINFRA','M&MFIN','RPOWER','PAGEIND','IDBI','CRISIL','RCOM','AJANTPHARM','CENTRALBK','3MINDIA','NEYVELILIG','GODREJIND','SJVN','WABCOINDIA','EXIDEIND','MRPL','JSWENERGY','NBCC','APLLTD','CHOLAFIN','ABFRL','ALSTOMT&D','L&TFH','TORNTPOWER','MINDTREE','WOCKPHARMA','TATACOMM','ABIRLANUVO','VAKRANGEE','MPHASIS','CANBK','NATIONALUM','ADANIPOWER','WELSPUNIND','SHRIRAMCIT','STAR','BIOCON','TATACHEM','RAMCOCEM','SUPREMEIND','RELCAPITAL','NAUKRI','DISHTV','SANOFI','VOLTAS','MFSL','THERMAX','UNIONBANK','WHIRLPOOL','APOLLOTYRE','AIAENG','GRUH','GPPL','JUBLFOOD','SYMPHONY','PFIZER','OBEROIRLTY','IRB','FORTIS','HEXAWARE','ADANIENT','INDHOTEL','FEDERALBNK','GSPL','IGL','BANKINDIA','PIIND','SYNGENE','TATAGLOBAL','LALPATHLAB','KAJARIACER','GUJGASLTD','HONAUT','SRF','IPCALAB','TUBEINVEST','NATCOPHARM','SUZLON','MUTHOOTFIN','SPARC','ARVIND','GMRINFRA','SKSMICRO','TV18BRDCST','THOMASCOOK','SKFINDIA','JUBILANT','BATAINDIA','PCJEWELLER','IIFL','DALMIABHA','PRESTIGE','IDFC','AKZOINDIA','MAHINDCIE','FAGBEARING','CESC','SOLARINDS','JETAIRWAYS','GODFRYPHLP','BALKRISIND','PERSISTENT','EIHOTEL','CENTURYTEX','GODREJPROP','TATAELXSI','NH','INOXWIND','ENGINERSIN','DHFL','DBCORP','BAJAJCORP','GUJFLUORO','CUB','COROMANDEL','JINDALSTEL','JUSTDIAL','KARURVYSYA','ECLERX','TRENT','JYOTHYLAB','KRBL','JAGRAN','IOB','SADBHAV','RELIGARE','ADVANTA','TTKPRESTIG','RDEL','FRL','INDIANB','ASTRAL','VTL','CYIENT','JKCEMENT','GESHIP','HINDCOPPER','COFFEEDAY','NETWORK18','PHOENIXLTD','REDINGTON','EDELWEISS','ATUL','FINPIPE','HATSUN','SYNDIBANK','CEATLTD','RELAXO','BEML','SUNCLAYLTD','FINCABLES','AARTIIND','NCC','UCOBANK','ZENSARTECH','IFCI','AIL','PRISMCEM','JKLAKSHMI','CORPBANK','CAPF','ICRA','MOTILALOFS','ALLCARGO','ICIL','EIDPARRY','BASF','CENTURYPLY','ADANITRANS','LAXMIMACH','ENIL','MMTC','GRINDWELL','ASAHIINDIA','MOIL','REPCOHOME','SADBHIN','SUNDRMFAST','VIDEOIND','STRTECH','SEQUENT','BLUESTARCO','SBBJ','SCHNEIDER','SINTEX','MHRIL','PVR','ANDHRABANK','FCEL','MAHABANK','VRLLOG','LAOPALA','RALLIS','CARBORUNIV','HITACHIHOM','SHILPAMED','ALBK','FDC','SHK','AEGISCHEM','HATHWAY','ASHOKA','TRITURBINE','KALPATPOWR','KEC','KPRMILL','ORIENTCEM','TECHNO','CANFINHOME','HDIL','CROMPGREAV','COX&KINGS','KIRLOSENG','GDL','NIITTECH','SHOPERSTOP','SCI','GREAVESCOT','JMFINANCIL','TIMKEN','CHENNPETRO','DHANUKA','MANAPPURAM','RTNPOWER','J&KBANK','KPIT','ASTRAZEN','MONSANTO','ZYDUSWELL','BIRLACORPN','WABAG','SREINFRA','CARERATING','OCL','ORIENTBANK','SBT','PNCINFRA','DISHMAN','VIJAYABANK','SOBHA','INDOCO','JISLJALEQS','INDIACEM','VGUARD','OMAXE','BALRAMCHIN','WELCORP','TRIDENT','KSCL','TATAINVEST','NAVKARCORP','IBREALEST','SFCL','CCL','GSFC','BBTC','VSTIND','GULFOILLUB','GRANULES','ESSELPACK','RAYMOND','KWALITY','SUVEN','SITICABLE','SOUTHBANK','CERA','IL&FSTRANS','MANPASAND','CHAMBLFERT','TIDEWATER','LINDEINDIA','INTELLECT','FSL','DCMSHRIRAM','DCBBANK','KSBPUMPS','TEXRAIL','WONDERLA','MINDACORP','8KMILES','RUPA','KKCL','RESPONIND','RATNAMANI','TCI','RCF','NESCO','RAMCOSYS','BFUTILITIE','SHARDACROP','JBCHEPHARM','GREENPLY','BAJAJHIND','GMDCLTD','JKIL','HMT','KITEX','ELGIEQUIP','INGERRAND','AHLUCONT','MCLEODRUSS','HSIL','NAVNETEDUL','HFCL','UNICHEMLAB','VINATIORGA','BRFL','KTKBANK','HIMATSEIDE','BAJAJELEC','JKTYRE','PFS','POLARIS','MARKSANS','PTC','JPASSOCIAT','DENABANK','GAYAPROJ','INOXLEISUR','TVTODAY','HEIDELBERG','HMVL','AVANTIFEED','FMGOETZE','MAYURUNIQ','HTMEDIA','JINDALPOLY','APARINDS','MAGMA','TVSSRICHAK','TAKE','MYSOREBANK','MAHLIFE','SUPRAJIT','ESCORTS','DPSCLTD','ITDCEM','EVEREADY','IGARASHI','TATACOFFEE','LUXIND','SOMANYCERA','NAVINFLUOR','NILKAMAL','BALMLAWRIE','BRIGADE','BANARISUG','UNITEDBNK','MINDAIND','PRAJIND','CLNINDIA','EROSMEDIA','APLAPOLLO','PFOCUS','SONATSOFTW','TEAMLEASE','CAPLIPOINT','QUICKHEAL','PAPERPROD','DELTACORP','HCC','HCG','TNPL','FLFL','VESUVIUS','JBFIND','VIPIND','LAKSHVILAS','NBVENTURES','KNRCON','SUNTECK','PRECAM','GALLISPAT','GRAPHITE','MAHSCOOTER','KSK','NFL','PSB','LITL','JPPOWER','SKIPPER','RENUKA','GENUSPOWER','ONMOBILE'] #complete thee

    

        

import xlsxwriter

workbook = xlsxwriter.Workbook('Stock.xlsx')

worksheet = workbook.add_worksheet()

k=0

for i in company:

    

    for j in range(len(company)):

    data = get_history(symbol=j, start=date(2019,12,10), end=date(2020,12,10))               

    data.keys()

    SUM=sum(data['Close'])

    TOTAL=len(data['Close'])

    SMA=SUM/TOTAL

    print(SMA)

    worksheet.write(0, k, i)

    for row_num, di in enumerate(data[i]):

        worksheet.write(row_num+1, k, di)

    k+=1

workbook.close()  

from openpyxl import load_workbook

wb2 = load_workbook('Stock.xlsx')

wb2.create_sheet('SBIN')

wb2.save('Stock.xlsx')
Dec 11, 2020 in Python by Pawan
• 120 points
89 views

Hi, @Pawan, 

Are you getting any error while executing your code? Please post that.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

Getting AttributeError: 'module' object (scipy) has no attribute 'misc' in Python. How to solve this?

>>> import scipy >>> scipy.misc Traceback (most recent call ...READ MORE

answered Dec 24, 2018 in Python by Nymeria
• 3,520 points
5,905 views
0 votes
0 answers

But when I run this, I get NameError: name 'alphabeta' is not defined error. How to solve this?

tree = [[[5, 1, 2], [8, -8, ...READ MORE

Sep 5, 2020 in Python by MUHAMMAD
• 160 points

retagged Sep 7, 2020 by Gitika 214 views
0 votes
1 answer

when I run this, I get NameError: name 'state' is not defined error. How to solve this?

Hi@MUHAMMAD, I tried to run the exact code ...READ MORE

answered Sep 8, 2020 in Python by MD
• 95,200 points
705 views
0 votes
1 answer
0 votes
1 answer

how to solve this IndexError: list index out of range in python and streamlit?

Hi,  @Erick, To solve the “index error: list ...READ MORE

answered Sep 24, 2020 in Python by Roshni
• 10,480 points
13,069 views
+1 vote
10 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

Just for the record: >>> int('55063.000000') Traceback (most recent ...READ MORE

answered Aug 17, 2020 in Python by pakainfo
• 200 points
279,497 views
0 votes
1 answer

How to solve indentation in the below code?

Python does not use brackets, it uses ...READ MORE

answered Feb 9, 2019 in Python by Omkar
• 69,150 points
159 views
0 votes
2 answers

How to solve the error - ssl module not found?

Hey, @There, nstall the necessary packages for Python ...READ MORE

answered Oct 23, 2020 in Python by Gitika
• 65,910 points
898 views