Created
August 2, 2019 13:44
-
-
Save mmeasic/81650c98fb1b8b6a4f823c44154fbcd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<You rock> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First, I wanna know how much money I could have made yesterday if I'd been trading Apple stocks all day. | |
So I grabbed Apple's stock prices from yesterday and put them in a list called stock_prices, where: | |
The indices are the time (in minutes) past trade opening time, which was 9:30am local time. | |
The values are the price (in US dollars) of one share of Apple stock at that time. | |
So if the stock cost $500 at 10:30am, that means stock_prices[60] = 500. | |
Write an efficient function that takes stock_prices and returns the best profit I could have made from one purchase and one sale of one share of Apple stock yesterday. | |
For example: | |
stock_prices = [10, 7, 5, 8, 11, 9] | |
get_max_profit(stock_prices) | |
# Returns 6 (buying for $5 and selling for $11) | |
No "shorting"—you need to buy before you can sell. Also, you can't buy and sell in the same time step—at least 1 minute has to pass. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment