Hello, I have the code below.
import DatastreamPy as dsws
import pandas as pd
# set up connection
def connection_DSWS():
DSWS_username = open("DSWSUsername.txt","r")
DSWS_password = open("DSWSPassword.txt","r")
ds = dsws.Datastream(username = str(DSWS_username.read()),
password = str(DSWS_password.read()))
DSWS_username.close()
DSWS_password.close()
return ds
def return_data(start, end, tickers, eom=False, period=12, format_date="Other"):
ds = connection_DSWS()
df = ds.get_data(tickers=tickers, start=start, end=end, freq="M")
df
return df
Tickers = 'USCONPRCE(ES)*DUMMYMTE,USCNFBUSQ(ES)*DUMMYMTE,TRUS10T(RY)*DUMMYMTE'
StartDate = "2020-12-31" #Put start date with the following format "yyyy-mm-dd"
EndDate = "2022-02-22" #same above for end date
FormatDate = "yyyymmdd" #Format in the csv
Period = 3 # Period of ROC and MOM
path = "Output.csv"
EndOfMonth = True #True if you use *DUMMYMTE, you have to use it for all elements to have EOM data
df = return_data(StartDate, EndDate, Tickers, EndOfMonth, Period, FormatDate)
df
How to clean the dataframe so that the output into a csv file, comma delimited, with the ticker names in the headline and the date into the yyyymmdd format, will be exactly like this (see below) ?
Date,USCONPRCE,USCNFBUSQ,TRUS10T
20201231,261.564,60.5,0.912
20210129,262.200,59.4,1.094
20210226,263.346,60.9,1.456
20210331,265.028,63.7,1.746
Thanks!