Stock profit

danbihan · June 13, 2021
stock_prices = [10,5,20,32,25,12]
dts = [
  '2019-01-01', 
  '2019-01-02',
  '2019-01-03',
  '2019-01-04',
  '2019-01-05',
  '2019-01-06',
]

def get_profit_dates(stock_prices, dts):
    profit = max(stock_prices) - min(stock_prices)
    
    for index, price in enumerate(stock_prices):
        if min(stock_prices) == price:
            buy_date = dts[index]
        elif max(stock_prices) == price:
            sell_date = dts[index]
    
    return (profit, buy_date, sell_date)

print(get_profit_dates(stock_prices, dts))
Output

Comments

Please sign up or log in to contribute to the discussion.