In this project you will develop a bash script to download and process historic stock price data.
Successful completion will demonstrate competence in basic bash scripting and awk programming. These skills are valuable in automating and simplifying manifold text and data processing tasks in scientific computing.
The terminal goal is to write an interactive bash script to repeatedly ask the user for a stock ticker symbol (e.g. AAPL - Apple Inc., DOW - Dow Chemical) and a historic month and year (e.g. 9/2008) to produce files containing the adjusted daily closing stock price for each trading day that month.
The desired format of the file is two columns titled "Date" and "Adjusted Closing Price / ¢" listing the closing stock price in US cents for each trading day in that month in reverse chronological order. The file should be titled <stockSymbol>_<Month>_<Year>.txt
.
You should submit your script via email to by 11:59pm on 30 January 2020. Scripts must run on the EWS Linux machines. Late submissions will not be accepted.**
Points will be awarded for the specific expectations listed below, and for the overall script usability, performance, clarity, and presence of useful in-script comments/documentation.
It is strongly advised that students write the script using vi/emacs or a simple text editor on a machine running Linux or Mac OS X or via ssh to EWS). Scripts written on Windows machines often contain extraneous characters that make them non-portable to other environments.
[10 pts] Use the read function to obtain and store user input (stock name, month, year) into appropriately named variables.
[10 pts] Yahoo! Finance maintains an archive of historic stock data that can be easily accessed using the script available at this URL: github.com/bradlucas/get-yahoo-quotes For example, to download all historical stock prices for Apple (AAPL) we would execute ./get-yahoo-quotes.sh AAPL
This will produce a CSV file with all of the data. You will need to modify this script (make a copy of the script, and start editing your own version) to make sure that your script sets start and end dates based on user input. Make sure to automatically use the correct end day depending on the user-selected month (otherwise when you use date
to convert it to seconds for START_DATE
and END_DATE
you will have a problem). We must automatically specify the end day depending on the user-selected month. Special care is necessary for the month of February in leap years.
$?
holds the return code for the most recent call made in your script. It will hold a value of 0 if the call was successful, and will hold a non-zero value if the call failed. You may wish to use this special symbol in an if loop (e.g., if [ $? -ne 0 ] ; then
) to determine whether or not your call to wget succeeded.AAPL_2009.txt
, in the above example) will contain a number of fields and a header line containing field descriptors. Using a call to awk within your script, convert this file into the desired file format. You will use awk to extract the pertinent fields from the raw data, and generate a file in the desired format, and with the desired title.awk -F '<delimiter>'
, where <delimiter>
=comma, semi-colon, colon, etc.NR
to ignore header lines in your input file.Doe_John.txt
, and I have variable firstName=John
and lastName=Doe
, I would write: echo "Hello, world!" > "${lastName}_${firstName}.txt"
. If we omit the curly braces, bash gets confused because it thinks you are trying to dereference the (nonexistent) variable lastName_.Perhaps you wish your script to simply produce a blank file, perhaps exit gracefully and tell the user the file is blank, or perhaps give the user another chance to enter a legal symbol/date pair. Justify your decision.