Question: Matlab question Function Name: fallingStocks Inputs: 1. ( double) 1xN Vector of initial stock prices 2. ( double) 1xN Vector of projected final stock prices
Matlab question
Function Name: fallingStocks
Inputs:
1. ( double) 1xN Vector of initial stock prices
2. ( double) 1xN Vector of projected final stock prices
3. ( double) Total amount of money to invest
Outputs:
1. (double) Vector of money that could be made by buying each stock
Background:
Fall is in the air, and coincidentally the stock prices have also been falling for a while.
However, you're a pro investor, so you know that the stocks are about to rebound. You think it's
time to invest in some stocks so you can make some money, and you turn to MATLAB to figure
out how much money you can make!
Function Description:
Given a vector describing initial stock prices and a vector of the predicted final stock
prices, as well as how much money you have to invest, you will figure out the best stocks, in
order, to spend your money on
Calculate the amount of money you could make by purchasing a stock. Do this for each
stock and store these values in a vector.
Calculate the number of each type of stock you are able to buy with the money you have
using their initial prices. Assume you can only buy a whole number of stocks.
Use these values to figure out the profit you can make by spending as much of your
money on each type of stock.
Sort the output vector from the greatest amount of money that could be made to the
least.
Example:
fallingStocks([20,30,40], [30,60,80], 100) => [90, 80, 50]
Notes:
Round the output vector to the third decimal place.
CS 1371 TAs are not liable for any losses incurred on the stock market as a result of this
problem.
It is okay if some of the values end up negative.
Hints:
The 'descend' option for sort() may be useful.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
