Computer Science I for non-majors by James Tam

Return to the course web page

CPSC 217: Assignment 2

Due: Due Monday October 21 at 4 PM.

New Concepts to be applied for the assignment

Introduction to investing1

 

The essence of investing is risk vs. potential reward. Risk is the amount of fluctuation  (in this case downwards) that can occur in a particular investment. Putting money into a term bank deposit insured by a stable government entails very little risk. Investing your money into the assets of a corporation  entails greater risk: losses may occur or the entire investment itself may be lost. Prices may quickly go up or down (sometimes by wide variations). [Example purely for illustrative purposes (try comparing results before and after the announcement of 'exciting' events in the world news: Current indices of some major stock exchanges]

Why do people willing put their money into riskier investments? The low risk investments have a very low return on your investment (e.g., in a depressed economy the interest you make in a savings account is less than the rate of inflation e.g., 1.3 - 1.9% interest a year (max) on some accounts vs. an inflation rate around 2 - 3%2). While it is not guaranteed that 'riskier' investments will result in a larger return they generally have the potential for larger gains. It's up to the would-be investor to balance out the desire for maximum returns vs. his or her aversion to risk.

1 Note this introduction is meant only to provide background information needed to create your simulation. No guarantees are provided about your ability to making big $$$!
2 Raw data comes from the actual interest and inflation rates from 2013.

Assignment description

Write a program that allows the user to invest in one of three investment products, each with a different level of risk. The goal is to reap maximum returns at the end of the year (and in the long term earn maximum returns for the 10 year simulation span). The starting cash is $100. To simplify things all cash must be invested wholly in a product for an entire year - no 'diversifying' or splitting amounts between multiple products is possible. To implement the random nature for each of the three products you can use the pre-created code in the 'random' library module.

Product I, Fly-By-Night Investments (Stock code: SCAMU): high risk, high potential returns

Product II, Blue Chips INC. (Stock code: BCI): moderate risk, good potential yearly returns

The losses/gains are average performance of an investment over a year.

3 To reduce the complexity when generating the probability of a gain or a loss the program only has to generate integer value percentages  e.g., 1%, 2%, 3% etc. and not the real number values in between these integers. So when generating the chance of loss or gain for BCI then the program would just generate a value from 1 - 100%. In a similar fashion the range of percentages for the average increase or decrease of an investment during a year will also consist only of whole number percentages.

Product III, Slow-And-Steady Corp. (Stock code: BORE), mature industry stock: no risk but low returns

As mentioned losses or gains will be calculated yearly, year end monies carried over as the starting money for the next year.

Chronology:

When the simulation starts the user's investment portfolio starts at the default of $100, zero years have passed. The user will be shown a menu of investment products (as well as brief description of each).

If a selection doesn't match option 1 - 3, then the program will continue prompting the user until a value within this range has been entered.

At the end of each year the following financial report should display the year and current risk level (high, medium or low) on one line and on the line below it a summary of the performance for year:

  Format:
<Year/Time units passed>     <Investment risk level>    
<Amount of money at the start of the year> <Dollars earned or lost during the year> <Amount of money at the end of the year>
   
  Example:

The program will run for a ten years at which point it will display a summary for the tenth year as well as displaying performance spanning the entire ten year period.

  Format:
<Amount of money at the start of the simulation>
<Dollars earned or lost during the 10 years
<Amount of money at the end of the simulation>
<Percentage return over 10 years, rounded to 1 fractional digit>
<Average yearly percentage return, rounded to 1 fractional digit >4
   
  Example (notice that THE FORMATTING AT THE END OF TEN YEARS IS DIFFERENT from the yearly report in order to make it stand out):

4 You will see this sort of number in actual investment products. It may be calculated in different ways. For this assignment this value is calculated by dividing the 10 year gain/loss by ten.

Sample runs of my solution:

They can be found under the A2 directory: /home/courses/217/assignments/assignment2

Among other things you can see the program output in one complete continuous run (giving you an idea of the above parts connect together).

Submitting your work:

  1. Source code Python program/'dot-py' file(s) must be electronically submitted according to [submission submission requirements].
  2. You cannot work in groups for this class. Copying/viewing other student's work will be regarded as academic misconduct (cheating). For additional details about what is and is not okay for this class please refer to the following [misconduct link].
  3. Before you submit your assignment here is a checklist of items to be used in marking: [checklist link]

External libraries that can be used (unless explicitly listed don't assume you can use an external library)

  1. Libraries that allow for text-based (console) input and output.
  2. Random number generators