2

Python 3.6 The experiment is to do the following

I have this following code with given daily EOD/OHLC stock data getting it from quandl for every day.

class YahooQuote(Quote):
''' Daily quotes from Yahoo. Date format='yyyy-mm-dd' '''
def __init__(self,symbol,date,end_date=datetime.date.today().isoformat()):
    super(YahooQuote,self).__init__()
    self.symbol = symbol.upper()
    url_string = "https://www.quandl.com/api/v3/datasets/NSE/CEATLTD.csv?&order=asc&collapse=daily&start_date=2017-04-18&end_date=2017-05-19&api_key=rFp-5oz3wKzJtNAuvzxC"
    csv = urllib.request.urlopen(url_string).readlines()
    csv.pop(0)
    print(csv)
    for bar in range(0,len(csv)):
        ds,open_,high,low,last,close,volume,adjc = csv[bar].decode().rstrip().split(',')
        open_,high,low,last,close,volume,adjc = [float(x) for x in [open_,high,low,last,close,volume,adjc]]
        dt = datetime.datetime.strptime(ds,'%Y-%m-%d')

The csv has the daily EOD data from 2017-04-18 to 2017-05-19 in OHLC format

I want this data to be converted to Weekly in one CSV and Monthly in another CSV.How to do that in very efficient way in python.

While doing Weekly conversion up to the date given, the data should be updated.

i referred some of the existing code in the link since i am new i am not able to proceed.Any python expert help with right code will help solving the issues.

Convert daily pandas stock data to monthly data using first trade day of the month

Marx Babu
  • 750
  • 3
  • 11
  • 34
  • Hello Marx, and welcome to the site. We try to keep questions very to-the-point here, so I edited yours down a little bit. Feel free to edit it again if you aren't happy with it. – MackM May 19 '17 at 18:18
  • Quandl have an [official Python API library](https://www.quandl.com/tools/python), you really should use that instead of rolling your own functions. – Tomalak May 22 '17 at 11:01
  • Hello All I am sure there will be a way but i am not know how to do that;Dont mistake me i am really new to this python hence it looks heavy and eating my weeks. i tried pandas but no good gain. The "csv" python has all the required data.If some one can give the code which converts this daily EOD data to Weekly in one csv file and monthly in another csv as the way yahoo charts are showing will be greatful. – Marx Babu May 23 '17 at 10:06
  • https://www.quandl.com/api/v3/datasets/NSE/BHEL.csv?&order=asc&collapse=daily&start_date=2017-04-01&end_date=2017-05-23 use this link to know what the data comes in CSV. Date,Open,High,Low,Last,Close,TotalTrade,Turnover are the csvs i am getting ; while converting from Daily to weekly (Monday-Friday should be considered) also only Open High Low close ,Total traded value to be considered. The logic should execute very fast so that i can automate and do the algorithm for 500scripts. Please support getting the code for montly and weekly .This quandle itself has weekly and monthly but wrong – Marx Babu May 23 '17 at 10:11

0 Answers0