Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

comp20005 Intro. to Numerical Computation in C

Semester 1, 2022

Assignment 1

Learning Outcomes

In this project you will demonstrate your understanding of loops, if statements, functions, and arrays; writing a program that first reads some numeric data and then performs a range of processing tasks on it. The sample solution that will be provided to you after the assignment is completed will also make use of structures (covered in Chapter 8, and the Week 9 videos), and you may do likewise if you wish. But there is no requirement for you to make use of struct types, and the required tasks can equally well be carried out using parallel arrays.

Sequential Data

Scientific, engineering, and financial datasets are often stored in text files using comma separated values ( .csv format) or tab separated values ( .txt or .tsv format), usually with a header line describing the contents of the columns. The simplest framework for processing such data is to first read the complete set of input rows into arrays, one array per column of data, and then pass that set of parallel arrays (and a single buddy variable) into functions that carry out the required data transformations and analysis. Your task in this project is to use that processing approach to analyze some financial data available as a time series.  While this assignment uses one specific example of such data, the processing modes you will need to develop can be applied more generally as well.

For example, the data file asx-5.tsv contains these values in tab-separated format:

date

day

month

year

asx

44547

17

12

2021

7304.0

44554

24

12

2021

7420.3

44561

31

12

2021

7444.6

44568

7

1

2022

7453.3

44575

14

1

2022

7393.9

There will always be a single header line in all input files, and then rows each containing five values separated by “tab” characters (’\t’ in C). Once the first line has been bypassed (write a function that uses getchar() to read and discard characters until it has seen a newline character, ’\n’), each data line can be read as a set of int and double variables using scanf("%d%d%d%d%lf",...), with five values per row. The five values in each row represent:

● date: a day number, with 1 January 1900 designated as “day 1”

● day, month, and year: the corresponding date (so 17 December 2021 was day number 44,547)

● asx: the closing value of the ASX All Ordinaries stock exchange index on that date (or the day before if that date was a public holiday).

All of the dates in any input file that you are provided with will be Fridays, and in any given input file all dates will be at seven day intervals, forming a set of consecutive Fridays. This small example shows five consecutive Fridays spread across December 2021 and January 2022. In general, data files might contain dozens, hundreds or thousands of lines, but never more than 10,000.

The “All Ordinaries” index (see https://www2.asx.com.au) represents the overall market capital- ization of the 200 largest public companies in Australia and reflects overall economic conditions and aggregate investor sentiment indicated via the day-to-day share price movements of those 200 compa- nies. It is the measure referred to in the news when they report “investors were happy as the share market lifted today” or that “there was desperate selling as the share market slumped today”.

Stage 1 Control of Reading and Printing (marks up to 8/20)

The first version of your program should read the entire input dataset into parallel arrays (or, if you are adventurous, an array of struct), counting the data rows as they are read. The heading line should be discarded, and is not required for any of the subsequent processing steps.  The required output of this stage for file asx-5.tsv is:

mac:  ./ass1-soln  < asx-5.tsv

S1, week  ending  17/12/2021,     asx = 7304.0

S1, week  ending  14/01/2022,     asx = 7393.9

S1, min weekly gain  on  14/01/2022 =   -0.80%

S1, max weekly gain  on  24/12/2021 =     1.59%

S1,  change  over         4 week period =     1.23%

where the first two lines reflect the first and last rows from the input (so that you can be sure that you read it all in correctly); where the next two lines provide the minimum and maximum one-week percentage gains from any Friday to the next Friday; and where the last line provides the overall percentage gain for the whole input sequence. The percentage gain between a value x1 and a later value x2 is computed as 100 × (x2  - x1 )/x1 , and can be positive or negative. Note that a file containing n rows of data spans a period of n - 1 weeks and contains n - 1 weekly percentage gain values. You may assume in your programs that the ASX All Ordinaries index will never be zero (that is, x1  > 0 and x2  > 0), and that the data file contains at most 10,000 rows (nearly 200 years of Fridays).

Input must be read from stdin via “<” input redirection at the shell level. You must not make use of the file manipulation functions described in Chapter 11. No prompts are to be written.

To obtain full marks you need to exactly reproduce the required output lines.  Other examples can be found linked from the “Assignment 1” LMS page. You can assume that the input provided to your program will always be correct as described, and that you do not need to perform any data validation.

You may do your programming in Grok, in which case you will need to execute your program via the ‘Terminal” button using test files also stored in Grok, see the handout “Running Programs in a Shell Within Grok”, linked from the “Assignment 1” LMS page. You should also read the instructions in the left-hand pane of the Grok “Assignment 1” project if you wish to use Grok; those instructions introduce the automated testing and checking options (via diff) that have been built in to that project.

Or you may find it more convenient to use a separate programming environment on your computer, and download the skeleton program, test files, and expected output files to it.  Information about both these options is available on the LMS.

Stage 2 Selective Processing (marks up to 16/20)

Ok, now for some computation.  An ambitious friend has a theory that some months are better than others for making stock market gains. To test that theory they ask you to calculate the average weekly percentage gain in the data, broken down by the month that each Friday falls into.

For example, the test file asx-5.tsv contains three “December” Fridays, two of which can be used as part of a “December” average (the first Friday in the data is not the end point of a weekly gain); plus two “January” Fridays. The required Stage 2 output for asx-5.tsv is exactly:

S2,  January      :       2 Fridays,  average gain =  -0.34%,  ci95 +-  0.90% S2, December    :       2 Fridays,  average gain =   0.96%,  ci95 +-  1.24% S2,  Overall      :       4 Fridays,  average gain =   0.31%,  ci95 +-  0.96%

where for a set of n values xi  (that is, the set of weekly change percentages corresponding to all of the Fridays that fall in that given month right across all of the years within the input data) the mean (average) value is calculated as = xi/n; the standard deviation σ is computed as

σ = _ (xi - )2 /(n - 1); and the 95% confidence interval1  for the population mean, ± c, is computed via c = 1.96 σ/,n. You should only compute and print these values for months that appear in the input file – just January and December for asx-5.tsv, for example.  There are several other input/output examples linked from the LMS Assignment 1 page.

Stage 3 Plotting The Trend (marks up to 20/20)

Your friend is disappointed by the lack of clear evidence from the month-by-month analysis, even on a large dataset (the file asx-1272.tsv contains nearly 25 years of data), and for most months the confi- dence intervals are greater than the average weekly gains. So you decide to also generate a year-by-year graph showing the overall trend of the ASX over time, to reassure them that in the long-term in ASX index increases. Here is the required Stage 3 output for the file asx-300.tsv:

S3,  2000  | 3142.9--3275.6  |

S3,  2001  |  2884.5--3425.2  |

S3,  2002  |  2883.0--3428.1  |

S3,  2003  |  2715.0--3301.4  |

S3,  2004  | 3283.6--4053.1  |

S3,  2005  | 3939.8--4708.8  |

S3,  2006  | 4736.4--5285.5  |

**

****

****

****

*****

*****

****

For each year, the two numbers are the minimum and maximum recorded value of the All Ordinaries index for that year, using the Friday closing values from each week. Each “character” of the graph then corresponds to a band of 200 index points, with a character position getting a “*” if it lies on or between the minimum and maximum for that year. For example, in the last output row the range 4736.4 to 5285.5 corresponds to character positions 24 to 27 (since [4736.4/200] = 24 and [5285.5/200] = 27), and hence there are 23 leading blanks after the second “|” character, then 27 - 24 + 1 = 4 asterisks (and no trailing blanks). It would make sense for you to employ a range of simple test files with just a few lines each while you are getting this part of your program operational.

Complete output examples are linked from the “Assignment 1” LMS page. And whatever you do, don’t overlook the final output line, it is also required!

Stage 007 Becoming A Billionaire (0 marks)

Of course, what your friend really wants is a mechanism that when given a history of ASX values through until this Friday, successfully predicts what next Friday’s closing value will be. If you can find a rule that will do that accurately, let me know, and we’ll open a day-trading account together. But make sure you submit a perfect Stage 3 program before you start trying to invent clever linear prediction rules!

Refinements to the Specication

There are bound to be areas where this specification needs clarification or even correction, and you should refer to the “Assignment 1” Ed Discussion page regularly and check for possible updates to these instructions. There is also a range of information linked from the “Assignment 1” LMS page that you need to be aware of.

Submissions that are made after that deadline will incur penalty marks at the rate of two marks per day or part day late.  Students seeking extensions for medical or other “outside my control” reasons should email [email protected] as soon as possible after those circumstances arise. If you attend a GP or other health care service as a result of illness, be sure to take a Health Professional Report (HPR) form with you (get it from the Special Consideration section of the Student Portal), you

will need this form to be filled out if your illness develops in to something that later requires a Special Consideration application to be lodged. You should scan the HPR form and send it with any non-Special Consideration assignment extension requests.

Submission: Your .c file must be uploaded via the LMS Assignment page. Don’tforget to include, sign, and date the Authorship Declaration that is required at the top of your program.

Testing: You can also carry out pre-submission testing via a system known as submit, available at http: //submit-web.eng.unimelb.edu.au. The submit system uses the same computer/compiler that will be employed for post-submission testing (a Unix computer called dimefox which is very unforgiving of uninitialized variables and out-of-bounds array accesses). Note that submit may become congested and non-responsive in the final day or hours before the deadline. Even though it is called “submit”, this testing service does not register your assignment. You must upload your final program to the LMS via the Assignment page to actually submit it.

Marking Rubric: A rubric explaining the marking expectations is linked from the assignment’s LMS page, and you should study that rubric very closely.  Feedback, marks, and a sample solution will be made available approximately two weeks after submissions close.

Academic Honesty: You may discuss your work during your workshop, and with others in the class, but what gets typed into your program must be individual work, not copied from anyone else, and not developed jointly with anyone else. So, do not give hard copy or soft copy of your work to anyone else; do not “lend” your “Uni backup” memory stick to others for any reason at all; and do not ask others to give you their programs “just so that I can take a look and get some ideas, I won’t copy, honest”. The best way to help your friends in this regard is to say a very firm “no” if they ask to see your program, pointing out that your “no”, and their acceptance of that decision, are the only way to preserve your friendship. See

https://academicintegrity.unimelb.edu.au for more information. Note also that solicitation of solutions via posts to “tutoring” sites or online forums, whether or not there is payment involved, and whether or or not you actually employ any solutions that may result, is also serious misconduct. In the past students have had their enrolment terminated for such behavior.