Question
Problem 1. Simple Moving Average Write MovingAverage3.java, a program that reads stock prices, computes the 3-day simple moving average of the close prices, plots the
Problem 1. Simple Moving Average Write MovingAverage3.java, a program that reads stock prices, computes the 3-day simple moving average of the close prices, plots the prices and moving average, and prints the prices and moving average to standard out. Your program must handle all inputs that conform to the input specification. We will not test non-conforming inputs.
Computing the 3-day Simple Moving Average In finance, a moving average is a very popular stock price analysis indicator. It provides a smooth trend line, removing the distractions of higher frequency price fluctuations. In this problem, you will compute the simple moving average of the closing stock price. The simple moving average on day i is the average of the three most recent close prices, including the close price on day i. You can compute the average for day i by summing the close price for days i, i 1, and i 2 and dividing by 3. Do not compute the moving average for i = 0 and i = 1.
Input specification. The input is the same as part 1. The input will have at least three days of trading history.
Standard output specification. The output should match the input exactly except with the addition of a new column containing the 3-day simple moving average starting on the 3rd day. (The 3-day moving average has no meaning on the first two days.) Do not print any other output to standard output.
Plotting. The plotting will be performed by StockPlot.plot, the same function used in Problem 1. To plot the moving average, pass six arguments instead of four. These arguments are open, high, low, close, ma (the moving average), and days. The first five arguments passed must be double arrays of the same size. The last argument, days, an integer, expresses the moving average number of days (3 in this case). StockPlot.plot will ignore the values in ma for days less than days (index 0 and 1 in this case).
This is part 1
\% java-introcs PricesAndMovingAverage 10n 2013-01-02 35.0035.4534.7135.36 2013-01-03 35.1835.4534.7534.77 2013010434.8034.8033.9234.4034.84 2013010734.8034.8033.9034.3434.50 2013010834.5034.5033.1133.6834.14 2013-01-09 34.0134.1933.4033.6433.89 2013-01-10 33.8733.9933.3833.5333.62 2013-01-11 34.0434.0432.1132.9133.36 2013-01-14 33.0833.3832.8533.2633.23 2013-01-15 33.1134.2533.0833.9033.36 date open high low close ma Problem 1: Plot Prices. Write a program Prices.java that reads, prints, and plots stock prices. Your program must handle all inputs that conform to the input specification. We will not test non-conforming inputs. Input Specification. The input from standard input consists of a positive integer n on a line by itself, followed by a sequence of n lines, each representing one day of historical stock trading information. Each line contains a date string and four prices (doubles) for that day's trading. The four prices are the open (the price of the first trade that day), the high (the highest trade price for that day), the low (the lowest trade price for that day), and the close (the price of the last trade of the day). Two data files, TSLA.txt (Tesla Inc. stock prices for 2013) and TSLA-10.txt (Tesla Inc. stock prices for the first 10 days of 2013), are available via the Class Meetings page. Required Program Steps. 1. Read n, the number of days, from standard input. 2. Read, also from standard input, the date and the open, high, low, and close prices for each day into five parallel arrays. 3. Call StockPlot.plot to make a pretty plot. 4. Print n and the array contents to standard output. Standard Output Specification. The output should match the input exactly. Use \%.2f in the StdOut.printf format string for the doubles. Do not print any other output. Calling StockPlot.plot. Plot the stock prices using the StockPlot.plot function provided to you in the StockPlot. java file available from the Class Meetings page. The function StockPlot.plot takes four array arguments of the same size: open, high, low, and close. The plot generated is called a "candlestick plot" with the range between open and close in red and the remainder of the range between high and low in blackStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started