[CS230 Home Page] [Syllabus] [Assignments] [Documentation] [CS Dept.]
In this assignment, you will use Input/Ouput and LinkedLists to create a system to manage stock quotes based on real historical stock data that can be obtained from the Internet.
In order for your system to support queries about stock prices, you will need to access historical stock data from the Internet. Yahoo Finance is one of several web sites from which such data can be downloaded. The following URL is a template that can be used to download stock price information for a particular stock during a given range of time:
http://ichart.finance.yaho.com/table.csv?s=<stock-symbol>&a=<start-month>
&b=<start-day>&c=<start-year>&d=<stop-month>&e=<stop-day>&f=<stop-year>
&g=<frequency-code>&ignore=.csv
In this template,
For example, the URL used in the following example specifies daily stock
information for Google from Dec 22, 2006 to Jan. 16, 2007:
[btjaden@puma Stocks] java FileOps displayWebPage "http://ichart.finance.yahoo.com/table.csv?s=GOOG&a=11&b=22&c=2006&d=0&e=16&f=2007&g=d&ignore=.csv" The information is provided in tabular format known as comma-separated-value (CSV)
format, in which each row is a line of text having columns that are separated by commas. The first line of the
table lists titles for the columns and the remaining lines are the content rows of the table. In this assignment,
you will focus on only the first and last columns. The first column specifies a date in the format
YYYY-MM-DD1, while the last column gives
the so-called adjusted closing price2 of the
stock for that date. For example, on Jan. 3, 2007, the adjusted closing price of Google stock was $467.59. Note that the information provided by Yahoo is in reverse chronological order -
the more recent dates are listed earlier in the table. Also note that information is provided only for dates on
which the stock exchange was open. In the above example, Dec. 22 is a Friday, and the exchange was closed for the
Dec. 23/24 weekend, Christmas (Mon. Dec. 25), the Dec. 30/31 weekend, New Year's (Mon. Jan. 1 and Tues Jan. 2),
the Jan. 6/7 weekend, the Jan. 13/14 weekend, and Martin Luther King day (Mon. Jan. 15). It appears that the database of stock prices supplied by Yahoo only goes back to 1962.
Yahoo ignores any dates specified before this time and any dates specified after the current date. So you can
get all daily stock information for a given stock by specifying any year before 1962 as the
<start-year> (e.g., 1900),
any year after the current year as the
<stop-year>
(e.g., 2020), and d as the
<frequency-code>.
For example:
[btjaden@puma Stocks] java FileOps displayWebPage "http://ichart.finance.yahoo.com/table.csv?s=GOOG&a=0&b=1&c=1900&d=0&e=1&f=2020&g=d&ignore=.csv" Google stock was introduced on Aug. 19, 2004, so the records don't go back any farther
than this for Google. The tasks for this assignment lead you through the construction of a simple stock quote
system that uses data from the Yahoo finance site. First, copy the /home/cs230/downolad/Stocks directory on puma to your own CS230 subdirectory. This directory contains a subdirectory named SampleSolution that has several class files, which you can execute, that contain a sample solution to the assignment. In addition, the directory contains a helper class, CS230Date, which helps manage operations for dates. You should read the contract for the CS230Date class. You will be creating two new files from scratch for this assignment: StockQuote.java and StockInfo.java.
A stock quote is the price of a stock at a specified point in time. In this assignment,
a stock quote will always refer to the adjusted closing price of a stock on a particular day. In this problem, your task is to create a StockQuote class in a file
StockQuote.java that you write from scratch. The StockQuote
class must implement the
StockQuote contract found here. Each instance of the StockQuote class simply
pairs a date with a stock price on that date. (The stock-ticker symbol is not mentioned in the
StockQuote instance.) Dates are represented as instances of the CS230Date class,
which has already been implemented for you. Below are some sample statements and expressions involving StockQuote instances.
The notation E ⇒ V means that expression E evaluates to value V. In addition to implementing all methods in the
StockQuote contract,
you should write a main method that tests your methods.
In this problem, your task is to create a StockInfo class in a file
StockInfo.java that you write from scratch. The StockInfo
class must implement the
StockInfo contract found here. Conceptually, each instance of the
StockInfo class has two pieces of information: Additional information and requirements for your StockInfo class are listed below.
Date,Open,High,Low,Close,Volume,Adj Close
2007-01-16,507.55,513.00,503.30,504.28,7568900,504.28
2007-01-12,501.99,505.00,500.00,505.00,4473700,505.00
2007-01-11,497.20,501.75,496.18,499.72,7208200,499.72
2007-01-10,484.43,493.55,482.04,489.46,5968500,489.46
2007-01-09,485.45,488.25,481.20,485.50,5381400,485.50
2007-01-08,487.69,489.87,482.20,483.58,4754400,483.58
2007-01-05,482.50,487.50,478.11,487.19,6872100,487.19
2007-01-04,469.00,483.95,468.35,483.26,7887600,483.26
2007-01-03,466.00,476.66,461.11,467.59,7706500,467.59
2006-12-29,462.10,464.47,459.86,460.48,2559200,460.48
2006-12-28,467.12,468.58,462.25,462.56,3116200,462.56
2006-12-27,460.00,468.08,459.10,468.03,4231500,468.03
2006-12-26,456.52,459.47,454.59,457.53,2074300,457.53
2006-12-22,457.50,458.64,452.73,455.58,3988300,455.58
Date,Open,High,Low,Close,Volume,Adj Close
2008-09-26,428.00,437.16,421.03,431.04,5292500,431.04
2008-09-25,438.84,450.00,435.98,439.60,5020300,439.60
... many lines omitted ...
2004-08-20,101.01,109.08,100.50,108.31,11428600,108.31
2004-08-19,100.00,104.06,95.96,100.34,22351900,100.34
StockQuote.java
StockQuote q = new StockQuote(CS230Date.fromString("2007-06-15", 522.7);
q.date().toString() ⇒ "2007-06-15"
q.price() ⇒ 522.7
q.toString() ⇒ "2007-06-15 522.7"
StockQuote q2 = new StockQuote(CS230Date.fromString("2007-06-14", 502.84));
StockQuote q3 = new StockQuote(CS230Date.fromString("2007-06-15", 522.7));
StockQuote q4 = new StockQuote(CS230Date.fromString("2007-06-20", 509.97));
StockQuote q5 = new StockQuote(CS230Date.fromString("2007-06-20", 522.7));
StockQuote q6 = new StockQuote(CS230Date.fromString("2007-06-21", 531.00));
q.equals(q2) ⇒ false ; Similar if q2 is replaced by q4, q5, or q6
q.equals(q3) ⇒ true
q.compareTo(q2) ⇒ a positive integer ; similar if q2 is replaced by q4
q.compareTo(q3) ⇒ 0
q.compareTo(q5) ⇒ a negative integer ; similar if q5 is replace by q6
; From low to high, the above quotes are ordered: q2, q4, q=q3, q5, q6
StockInfo.java
import java.io.*; // Allows use of BufferedReader, InputStreamReader
import java.util.*; // Allows use of LinkedList
import java.net.*; // Allows use of URL
throw new RuntimeException("*** include appropriate error message here ***");A sample transcript of the StockInfo program demonstrating its execution
|
|
submit cs230 Stocks *.*