I have the code below (attach). What I want to do is to prompt a user to enter a ticker from Quandl website (financial/economic data) so that the dataset is retrieved. One condition, the data should be of 1-month length starting from the time when a user enters ticker.Let'say if the program is run on 22/01/2018 so the data should be from 22/12/2017 till 22/01/2018 (That is the first thing I am struggling with). Second, I want to make sure that the ticker is entered correctly, so I want to make a condition such that "if the command "quandl.get("ticker", start_date=trim_start, end_date=trim_end)" does not retrieve the data- re-enter the ticker" Please, advise me this issue.
'''Installation steps - go to "Command line" and pass "pip install quandl"'''
import quandl #To extract the data from Quandl
website
import matplotlib.pyplot as plt #Plotting library
import datetime
def MainFormula():
ticker = None
while ticker is None:
ticker = input("Please, enter stock ticker (should be available in Quandl Website): ")
try:
trim_end=datetime.datetime.now()
trim_start= trim_end - 30
if quandl.get("ticker", start_date=trim_start, end_date=trim_end) == True:
print("Here are the results: ")
else:
print("Please, enter correct stock ticker (check Quandl website)! ")
except ValueError as e1:
print("Please, enter correct alpha (should be float - example: 0.2) ")
program = MainFormula()
print(program)
Aucun commentaire:
Enregistrer un commentaire