Analyzing Stock Data Project

Hello,

INTRODUCTION TO PYTHON

Analyzing Stock Data

I’m unable to figure out whats wrong below. Any help or suggestions is appreciated.

def display_as_percentage(val):
 return '{:.1f}%'.format(val * 100)

amazon_prices = [1699.8, 1777.44, 2012.71, 2003.0, 1598.01, 1690.17, 1501.97, 1718.73, 1639.83, 1780.75, 1926.52, 1775.07, 1893.63]
ebay_prices = [35.98, 33.2, 34.35, 32.77, 28.81, 29.62, 27.86, 33.39, 37.01, 37.0, 38.6, 35.93, 39.5]

# Write code here

def get_returns(prices):
 returns=[]
 for i in range(len(prices)):
   start_price = prices[i]
   end_price = prices[i-1]
   log_return = calculate_log_return(start_price, end_price)
   returns.append(log_return)
 return returns
amazon_returns = get_returns(amazon_prices)
ebay_returns = get_returns(ebay_prices)

print(amazon_returns)

you call a function here:

log_return = calculate_log_return(start_price, end_price)

where is calculate_log_return defined? Could you share the project url? So we can access the lesson

here is mine… dont know what went wrong either

I set the range to (len(prices)-1). The length of the get_returns result would be 12, shorter than the length of prices (13). If we leave range equal len(prices), the end_price would be (i+1) = (13+1) = the 14th price, which does not exist.

def get_returns(prices):
 returns=[]
 for i in range(len(prices)-1):
   start_price = prices[i]
   end_price = prices[i+1]
   log_return = calculate_log_return(start_price, end_price)
   returns.append(log_return)
 return returns

amazon_returns = get_returns(amazon_prices)
ebay_returns = get_returns(ebay_prices)