Skip to content

Instantly share code, notes, and snippets.

@jedavidson
Last active January 28, 2024 07:42
Show Gist options
  • Save jedavidson/0081e7c4ac9985eb5ed24d0665492eb7 to your computer and use it in GitHub Desktop.
Save jedavidson/0081e7c4ac9985eb5ed24d0665492eb7 to your computer and use it in GitHub Desktop.
#include <cassert>
#include <vector>
// Given some price information at discrete time intervals, returns a suitable
// value for the price at a given time interval. You may assume that times is
// sorted in ascending order, and that there are at least two datapoints (i.e.
// prices for at least two times).
auto stock_price(int time, std::vector<int> const &times,
std::vector<float> const &prices) -> float {
return 0;
}
auto main() -> int {
// Some sample time and price data. You might want to call stock_price for
// different time arguments to test your function.
auto const times = std::vector<int>{1, 3, 6, 11, 17, 20};
auto const prices =
std::vector<float>{100.00, 106.00, 109.00, 104.00, 107.00, 113.00};
}
from typing import List
def stock_price(time: int, times: List[int], prices: List[float]) -> float:
"""
Given some price information at discrete time intervals, returns a suitable
value for the price at a given time interval. You may assume that times is
sorted in ascending order, and that there are at least two datapoints (i.e.
prices for at least two times).
"""
return 0
if __name__ == "__main__":
# Some sample time and price data. You might want to call stock_price for
# different time arguments to test your function.
times = [ 1, 3, 6, 11, 17, 20]
prices = [100.00, 106.00, 109.00, 104.00, 107.00, 113.00]
@jedavidson
Copy link
Author

Other nice financial-themed problems:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment