CS计算机代考程序代写 python case study The University for business

The University for business
and the professions

Coursework MOCK Test

Term 3 Elective Module

Module Code Module Title
SMM283 Introduction to Python

Date Time

Division of Marks: 100 marks

Instructions to students: Use Python IDLE (2.7 or above) only to code the

Python solution as a Python file (StudentID.py),
alongside any by-product file(s). Save frequently the
file(s) in a StudentID named folder, and upload the
last version of the saved file(s) to Moodle at the end
of the test.

This paper contains a case study with four subparts (a, b, c) and
comprises four pages including the title page

Number of answer books to be provided: N/A
Calculators are permitted: N/A
Dictionaries are NOT permitted
Additional materials or tables to be provided: None
Exam paper can be removed from the exam room: No

2

CASE STUDY:

You have just received a positive response from UBS on a recent graduate ‘Financial

Analyst’ role you had applied for and you are invited to a job interview. The job
specification includes, among other things, knowledge of Python at introductory level,
but with the prospect of further training within the organization. If successful you will
work in a recently re-organized asset pricing department and if you were to be
successful, you’d work as part of a team dealing with financial analysis and asset
pricing that also involves computational work. Your prospective employer has
prepared a three part trial-test for you as part of the interview, entirely based on
introductory Python programming.

You are tested in good modular programming skills and practice by designing
several functional-cohesive modules to the specification provided. The interviewer
has supplied you with the general instructions in pseudo-code format of a program
master control function called main and you’d need to convert them to Python code
and together with the user-defined functions, demonstrate that you truly understand
not only modular design, but that you show awareness of module cohesion, module
coupling and general good programming practice;

REQUIRED:

Create and test Python functions based on the specifications in sections (a), (b), and
(c).

(a)

A user-defined function called pmt that computes the payment for a loan based on

constant payments and a constant interest rate. The pmt can be used with either

periodic, constant payments (such as a mortgage or other loan), or a future value that
could be some investment goal. The mathematical formula for the pmt is

and the Python function prototype should be:

def pmt(rate, nper, pv, fv, type):

It receives the following:

(1) rate, interest rate per period and must be positive.

(2) nper, total number of payment periods in an annuity and must be positive.

(3) pv, present value, or the total amount that a series of future payments is worth

now; also known as the principal, if pv is zero, you must include a positive fv.
(4) fv, future value, or a cash balance you want to attain after the last payment is

pmt ==
(1 +r* type)(1 +r)nper −1

pv*r*(1 +r)nper − fv

3

made. If fv is zero, you must include a positive pv value.

(5) type, the number must be 0 or 1 and indicates when payments are due (ordinary

annuity or an annuity due).

Validate the function parameters’ data using loops and any appropriate build-in
function, thus making sure that only numeric data is passed in the function.

(30 marks)

(b)

A user-defined function called nfv that computes the difference between future value

(at time t) of an investment’s forecasted uneven cash flow with a constant discount
rate and an initial cost outflow. Assume the cash stream is evenly spaced and occur
at the end of each time period. The mathematical formula for the nfv is

and the Python function prototype should be:

def nfv(rate, nper, cost, cf = []):

It receives the following:

(1) rate, the rate of discount over the length of one period. Must be positive.

(2) nper, total number of cash flow periods. Must be positive.

(3) cost, initial investment cost.
(4) cf, an array or list of cash payments anticipated, timed at the end of each time

period.

Validate the function parameters’ data using loops and any appropriate build-in
functions, thus making sure that only numeric data is passed in the function and that
the memory address passed-in is a valid one.

(30 marks)
(c)

Test the functions by coding a program control master user-defined function main
based on the following instructions:

1. define variables rate, nper, pv, fv, cost, cf (array or list)

2. Prompt the user for data and initialize the variables by reading from the keyboard
and validate the input properly, allowing only the appropriate numerical values in
and in the correct data type with proper exception handling.

3. Initialize the array or list
4. Call the functions.
5. Print the results in a formatted matter.

NFV = cf *
nper

( 1 +r) (nper−i) −c*( 1 +r) nper i
i=1

4

Validate the data using loops and any appropriate build-in function, thus making sure
that only numeric data is read in the program and that exceptions are addressed in
an effective manner.

You are expected to produce the file “StudentID.py”. The program must run in order
to be marked.

(40 marks)

END OF EXAMINATION