Stock Market Assignment Solutions Sheet

Part 1:

***************************
**************************
**************************
**************************
**************************
****************************
*****************************
***************************
**************************
**************************
**************************
**************************
***************************
**************************
**************************

Part 2:

    1      26.375
    2      25.500
    3      25.125
    4      25.000
    5      25.250     buy
    6      27.125
    7      28.250
    8      26.000     sell
    9      25.500
   10      25.000
   11      25.125     buy
   12      25.250
   13      26.375
   14      25.500     sell
   15      25.500
final result for stock1000.txt:
 1000     103.500

Part 3:

period   price     cash       shares    value
-----------------------------------------------
   1    26.375   10000.00       0.00   10000.00
   2    25.500   10000.00       0.00   10000.00
   3    25.125   10000.00       0.00   10000.00
   4    25.000   10000.00       0.00   10000.00
   5    25.250       0.00     396.04   10000.00
   6    27.125       0.00     396.04   10742.57
   7    28.250       0.00     396.04   11188.12
   8    26.000   10297.03       0.00   10297.03
   9    25.500   10297.03       0.00   10297.03
  10    25.000   10297.03       0.00   10297.03
  11    25.125       0.00     409.83   10297.03
  12    25.250       0.00     409.83   10348.26
  13    26.375       0.00     409.83   10809.32
  14    25.500   10450.72       0.00   10450.72
  15    25.500   10450.72       0.00   10450.72
final result for stock1000.txt:
1000   103.500       0.00     109.46   11329.18

Part 4:

period   price     cash       shares    value
-----------------------------------------------
   3    25.125   10000.00       0.00   10000.00
   4    25.000   10000.00       0.00   10000.00
   5    25.250   10000.00       0.00   10000.00
   6    27.125   10000.00       0.00   10000.00
   7    28.250   10000.00       0.00   10000.00
   8    26.000   10000.00       0.00   10000.00
   9    25.500   10000.00       0.00   10000.00
  10    25.000   10000.00       0.00   10000.00
  11    25.125   10000.00       0.00   10000.00
  12    25.250   10000.00       0.00   10000.00
  13    26.375       0.00     379.15   10000.00
  14    25.500       0.00     379.15    9668.25
  15    25.500       0.00     379.15    9668.25
final result for stock1000.txt
1000   103.500    9851.00       0.00    9851.00

Part 5 (for stock1000.txt):

1000   103.500   11165.94       0.00   11165.94



  • You can also test your code on more sample data.
  • Dilbert's rule applies only after 3 consecutive strict increases or decreases - if the price remains the same, Dilbert's rule will not apply for at least 3 more periods.