|We would like to be able to predict tomorrow's price of a share of stock. We
have data on past daily prices. Based on that we will make a prediction.
Our plan is to use a weighted average of the 5 most recent prices as the
We will choose the appropriate weights as the ones that would have best predicted prices in the past. The weights must add up to one to be a weighted average, but some of them may be negative. We will restrict consideration to weights that are chosen from the following 21 values:
-1.0, -0.9, ... , -0.1, 0.0, 0.1, ..., 0.9, 1.0We define the "error" of a prediction to be the absolute value of the difference between the prediction and the price.We will evaluate a possible weighting by using it to predict each of the known prices (except for the first 5, which don't have enough predecessors). We will then choose the weighting that has the smallest average error for its predictions.
Before we use our weighted averaging scheme to make our fortune on the stock market we need to have some idea of how well it predicted past data. Create a class Predicting that contains a method avgError that will be given a double data and will return the average error made by our best weighting.
|-||The returned value must be accurate to within a relative or absolute value of 1E-9.|
|-||data will contain between 6 and 50 elements inclusive.|
|-||Each element of data will be between 10.0 and 100.0 inclusive.|