Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PEF MRNA ICS 31 Summer Session 10-WK 2021 Assignment-4 You will write a program to model a series of stock market transactions over time. Your
PEF
MRNA
ICS 31 Summer Session 10-WK 2021 Assignment-4 You will write a program to model a series of stock market transactions over time. Your program will allow a user to examine stock prices and find trends using real historical price data. Your program will be a function called stockMarket which takes no arguments and returns no values. Your function Stock Market will allow the user to enter commands related to stock market transactions and queries. Your function should print out a prompt to indicate that the user can enter a command. Your prompt should be a s character. At the prompt the user will type a command followed by a set of arguments for the command. Your function will perform whatever action is indicated by the command, and then your program will print a $ character on a new line in order to let the user know that he/she can type a new command. The program will continuously ask for commands, and execute them unless the user enters the quit command, which will then terminate your program. The program will be used for buying and selling only the following two stocks of Covid-19 Vaccines: Moderna Inc (MRNA) and Pfizer Inc (PFE). An attempt to buy or sell any stock other than these is not valid and should result in your program printing an error message before displaying the next prompt. Historical stock prices Your program will use historical stock prices of MRNA and PFE as the stock prices used for buy and sell transactions. In addition to downloading this assignment from Canvas, you will need to download the following files. MRNA.csv and PFE.csv (please note these datasets are only for the purpose of this assignment and are not based on real stock prices of MRNA and PFE). your program printing an error message before displaying the next prompt. Historical stock prices Your program will use historical stock prices of MRNA and PFE as the stock prices used for buy and sell transactions. In addition to downloading this assignment from Canvas, you will need to download the following files: MRNA.csv and PFE.csv (please note these datasets are only for the purpose of this assignment and are not based on real stock prices of MRNA and PFE). These two files contain stock price data for MRNA and PFE respectively. When your program is executing historical price data will need to be read from these three files before any transactions can be made Each file contains stock price information on each trading day between 7/2/2019 and 6/30/2021. Each file is in "CSV" format, which stands for "comma-separated value". The contents of the file are tables with a series of columns. The first line contains the titles of each column and every line after the first contains the data on each column. The column data on each line is Each file contains stock price information on each trading day between 7/2/2019 and 6/30/2021. Each file is in "CSV" format, which stands for "comma-separated value". The contents of the file are tables with a series of columns. The first line contains the titles of each column and every line after the first contains the data on each column. The column data on each line is separated by a comma. The data that we are interested in on each line is the date (first column) and the closing price (fifth column). Your program will need to read the closing price on each day and store it so that it can be used as the stock price for buy and sell transactions. You will notice that the files do not include information for all days such as weekends and holidays, so there are gaps in the data. Trends There are different trends that people follow and analyse to find the best time to buy or sell a stock. For this assignment, you need to identify "evening star" and "morning star" trendlines to suggest the best dates to buy or sell a stock Evening Star Moming star Image from beantixtrader.com Morning Star (buy trend). indicates that you should buy a stock when its price decreases for 2 consecutivaatime periode and then increases For Evening Star Image from beanfixtrader.com Moming Star (buy trendy: indicates that you should buy a stock when its price decreases for 3 consecutive time periods and then increases. For example, if the price is 150 on Monday, 140 on Tuesday, 130 on Wednesday, 120 on Thursday, and 125 on Friday, then Friday is the day to buy. Evening Star (sell trend); indicates that you should sell a stock when its price increases for 3 consecutive time periods and then decreases. For example, if the price is 130 on Monday, 140 on Tuesday, 150 on Wednesday, 160 on Thursday, and 155 on Friday, then Friday is the day to sell! Commands O ReadFiles: This command should read the historical price data from the two files. The command takes 2 arguments, the pathname of the MRNA data file and the pathname of the PFE data file. PricesOnDate: This command should display the stock prices of both stocks on a given date. This command takes 1 argument, the date. MaxPossible. This command calculates the maximum possible profit/loss for a single share of a given stock in a given time span. In other words, if you buy your stock when the stock price is minimum/maximum and sell it when the stock price is minimum/maximum within the given time span, what will the profit/loss be. Note that the selling date must be later than the buying date. This command takes 4 arguments: profit/loss flag, name of the stock, start date, and end date. FindTrend: This command should examine the sequence of dates between the start and end dates and identify the dates to buy and sell the stock according to the Moming Star and Evening Start trends. This command takes 3 arguments: the name of the stock, the start date, and the end date. If none of the trendlines appear within the given period of time the program does not mark any of the dates for buying/selling and only prints out the price for each date within the period. quit: This command ends the program. . . - Example Output The following output is an example of how your program should respond to the commands. The text in bold is the user-typed input. Example Output The following output is an example of how your program should respond to the commands. The text in bold is the user-typed input. >>> StockMarket() $ ReadFiles PFECSY MRNA, CSV $ PricesOnDate 2019-07-02 PEE: 197419 MENA: 44.9411 $ PricesOnDate 2020-05-08 PFE: 202.90 MRNA: 38.58 $ MaxPossible profit PFE 2019-09-11 2019-10-15 14.41 $ MaxPossible loss MRNA 2020-04-16 2020-08-23 PFE: 202.90 MRNA: 39.53 $ MaxPossible profit PFE 2019-09-11 2019-10-15 h 14.41 $ MaxPossible loss MRNA 2020-04-16 2020-08-23 2.75999 $ FindTrend PFE 2019-07-02 2019-07-12 2019-07-02 187.18 2019-07-03 103.92 2019-07-05 185.40 2019-07-06 187.97 2019-07-09 1 190.581 2019-07-10 | 190.05 se 2019-07-11 I 187.88 2019-07-12 | 191.03 $ FindTrend MRNA 2009-01-01 2020-05-01 $ FindTrend PFE 2020-05-07 2020-05-23 2020-05-07 | 202.86 2020-05-08 | 202.90 2020-05-09 1 200.72 10OIS Tek to find comm HR le Xcut Paste C Copy - Format Painter Calibri - 11 - A A = = = BIU--- A.QE E Merge and Wrap Center- Text General - % 000 000 1800 Forma . Conditional 1 Cell SI Formatting A1 @fx Date H 1 K + A B D E F G 1 Date Open High Low Close Adj Close Volume 2 7/2/2019 43.060001 45 42.75 44.98 44.98 16703600 37/3/2019 45.360001 45.48 43.799999 43.889999 43.889999 14237500 4 7/5/2019 44.07 45.110001 43.549999 45.060001 45.060001 16172000 5 7/6/2019 44.91 46.75 44.610001 46.650002 46.650002 23740700 6 7/9/2019 46.740002 46.900002 42.080002 44.139999 44.139999 107582400 7 7/10/2019 44.200001 45.259998 43.630001 43.75 43.75 38467400 8 7/11/2019 42.630001 44.099998 42.220001 13.869999 43.869999 35100100 9 7/12/2019 44.799999 45.34 44.360001 45.259998 45.259998 27078500 10 7/13/2019 45.279999 45.32 43.93 44.490002 44.490002 16426700 11 7/16/2019 44.299999 44.73 43.91 44.259998 44.259998 13012800 12 7/17/2019 43.59 45.259998 43.150002 44.709999 44.709999 20122300 13 7/18/2019 44.189999 44.75 42.740002 43.34 43.34 26536800 14 7/19/2019 43.27 43.869999 43.110001 43.439999 43.139999 13366800 15 7/20/2019 43.5 44.130001 43.23 43.419998 43.419998 10437700 16 7/23/2019 43.450001 43.849998 42.400002 43.310001 43.310001 15251200 17 7/24/2019 43.77 43.799999 41.59 42.169998 12.169998 22433900 18 7/25/2019 42.349998 44.389999 42.349998 44.220001 44.220001 25140700 197/26/2019 42.869999 43.41 42.139999 42.939999 42.939999 30018700 20 7/27/2019 37.25 37.470001 33.900002 34.119999 34.119999 122752800 21 7/30/2019 34.169998 34.259998 31.07 31.379999 31.379999 77852400 22 7/31/2019 31.950001 32.48 31.07 31.870001 31.870001 64392200 23 8/1/2019 32.25 32.59 31.459999 31.91 31.91 33231700 24 8/2/2019 31.58 32.869999 31.34 32.82 32.82 27088000 25 8/3/2019 32.580002 32.990002 31.799999 31.959999 31.959999 26317000 26 8/6/2019 31.82 33.040001 31.450001 32.98 32.98 27512400 27 8/7/2019 33.099998 33.610001 32.549999 32.669998 32.669998 24635600 nlnl PRINT * Painter Center Text Formatting A1 Q fx Date H 1 J K A B D E G 1 Date Open High Low Close Adj Close Volume 2 7/2/2019 183.82001 187.3 183.42 187.17999 182.19901 17731300 3 7/3/2019 187.78999 187.95 183.53999 183.92 179.02577 13954800 4 7/5/2019 185.26 186.41 184.28 185.39999 180.46637 16604200 5 7/6/2019 185.42 188.42999 185.2 187.97 182.96797 17485200 6 7/9/2019 189.5 190.67999 189.3 190.58 185.50855 19756600 7 7/10/2019 190.71001 191.28 190.17999 190.35001 185.2847 15939100 8 7/11/2019 188.5 189.78 187.61 187.88001 182.88039 18831500 9 7/12/2019 189.53 191.41 189.31 191.03 185.94656 18041100 10 7/13/2019 191.08 191.84 190.89999 191.33 186.23857 12513900 11 7/16/2019 191.52 192.64999 190.42 190.91 185.82977 15043100 12 7/17/2019 189.75 191.87 189.2 191.45 186.35538 15534500 13 7/18/2019 191.78 191.8 189.92999 190.39999 185.33331 16393400 14 7/19/2019 189.69 192.55 189.69 191.88001 186.77396 20286800 15 7/20/2019 191.78 192.42999 190.17 191.44 186.34569 20676200 16 7/23/2019 190.67999 191.96001 189.56 191.61 186.51111 15989400 17 7/24/2019 192.45 193.66 192.05 193 187.86415 18697900 18 7/25/2019 193.06 194.85001 192.42999 194.82001 189.63571 16709900 19 7/26/2019 194.61 195.96001 193.61 194.21001 189.04195 19076000 20 7/27/2019 194.99001 195.19 190.10001 190.98 185.8979 24024000 21 7/30/2019 191.89999 192.2 189.07001 189.91 184.85637 21029500 22 7/31/2019 190.3 192.14 189.34 190.28999 185.22624 39373000 23 8/1/2019 199.13001 201.76 197.31 201.5 196.13796 67935700 24 8/2/2019 200.58 208.38001 200.35001 207.39 201.87122 62404000 25 8/3/2019 207.03 208.74001 205.48 207.99001 202.45523 33447400 26 8/6/2019 208 209.25 207.07001 209.07001 203.5065 25425400 27 8/7/2019 209.32001 209.5 206.76 207.11 201,59865 25587400 nr nr PFE.csv + 10 4 07 an ran ICS 31 Summer Session 10-WK 2021 Assignment-4 You will write a program to model a series of stock market transactions over time. Your program will allow a user to examine stock prices and find trends using real historical price data. Your program will be a function called stockMarket which takes no arguments and returns no values. Your function Stock Market will allow the user to enter commands related to stock market transactions and queries. Your function should print out a prompt to indicate that the user can enter a command. Your prompt should be a s character. At the prompt the user will type a command followed by a set of arguments for the command. Your function will perform whatever action is indicated by the command, and then your program will print a $ character on a new line in order to let the user know that he/she can type a new command. The program will continuously ask for commands, and execute them unless the user enters the quit command, which will then terminate your program. The program will be used for buying and selling only the following two stocks of Covid-19 Vaccines: Moderna Inc (MRNA) and Pfizer Inc (PFE). An attempt to buy or sell any stock other than these is not valid and should result in your program printing an error message before displaying the next prompt. Historical stock prices Your program will use historical stock prices of MRNA and PFE as the stock prices used for buy and sell transactions. In addition to downloading this assignment from Canvas, you will need to download the following files. MRNA.csv and PFE.csv (please note these datasets are only for the purpose of this assignment and are not based on real stock prices of MRNA and PFE). your program printing an error message before displaying the next prompt. Historical stock prices Your program will use historical stock prices of MRNA and PFE as the stock prices used for buy and sell transactions. In addition to downloading this assignment from Canvas, you will need to download the following files: MRNA.csv and PFE.csv (please note these datasets are only for the purpose of this assignment and are not based on real stock prices of MRNA and PFE). These two files contain stock price data for MRNA and PFE respectively. When your program is executing historical price data will need to be read from these three files before any transactions can be made Each file contains stock price information on each trading day between 7/2/2019 and 6/30/2021. Each file is in "CSV" format, which stands for "comma-separated value". The contents of the file are tables with a series of columns. The first line contains the titles of each column and every line after the first contains the data on each column. The column data on each line is Each file contains stock price information on each trading day between 7/2/2019 and 6/30/2021. Each file is in "CSV" format, which stands for "comma-separated value". The contents of the file are tables with a series of columns. The first line contains the titles of each column and every line after the first contains the data on each column. The column data on each line is separated by a comma. The data that we are interested in on each line is the date (first column) and the closing price (fifth column). Your program will need to read the closing price on each day and store it so that it can be used as the stock price for buy and sell transactions. You will notice that the files do not include information for all days such as weekends and holidays, so there are gaps in the data. Trends There are different trends that people follow and analyse to find the best time to buy or sell a stock. For this assignment, you need to identify "evening star" and "morning star" trendlines to suggest the best dates to buy or sell a stock Evening Star Moming star Image from beantixtrader.com Morning Star (buy trend). indicates that you should buy a stock when its price decreases for 2 consecutivaatime periode and then increases For Evening Star Image from beanfixtrader.com Moming Star (buy trendy: indicates that you should buy a stock when its price decreases for 3 consecutive time periods and then increases. For example, if the price is 150 on Monday, 140 on Tuesday, 130 on Wednesday, 120 on Thursday, and 125 on Friday, then Friday is the day to buy. Evening Star (sell trend); indicates that you should sell a stock when its price increases for 3 consecutive time periods and then decreases. For example, if the price is 130 on Monday, 140 on Tuesday, 150 on Wednesday, 160 on Thursday, and 155 on Friday, then Friday is the day to sell! Commands O ReadFiles: This command should read the historical price data from the two files. The command takes 2 arguments, the pathname of the MRNA data file and the pathname of the PFE data file. PricesOnDate: This command should display the stock prices of both stocks on a given date. This command takes 1 argument, the date. MaxPossible. This command calculates the maximum possible profit/loss for a single share of a given stock in a given time span. In other words, if you buy your stock when the stock price is minimum/maximum and sell it when the stock price is minimum/maximum within the given time span, what will the profit/loss be. Note that the selling date must be later than the buying date. This command takes 4 arguments: profit/loss flag, name of the stock, start date, and end date. FindTrend: This command should examine the sequence of dates between the start and end dates and identify the dates to buy and sell the stock according to the Moming Star and Evening Start trends. This command takes 3 arguments: the name of the stock, the start date, and the end date. If none of the trendlines appear within the given period of time the program does not mark any of the dates for buying/selling and only prints out the price for each date within the period. quit: This command ends the program. . . - Example Output The following output is an example of how your program should respond to the commands. The text in bold is the user-typed input. Example Output The following output is an example of how your program should respond to the commands. The text in bold is the user-typed input. >>> StockMarket() $ ReadFiles PFECSY MRNA, CSV $ PricesOnDate 2019-07-02 PEE: 197419 MENA: 44.9411 $ PricesOnDate 2020-05-08 PFE: 202.90 MRNA: 38.58 $ MaxPossible profit PFE 2019-09-11 2019-10-15 14.41 $ MaxPossible loss MRNA 2020-04-16 2020-08-23 PFE: 202.90 MRNA: 39.53 $ MaxPossible profit PFE 2019-09-11 2019-10-15 h 14.41 $ MaxPossible loss MRNA 2020-04-16 2020-08-23 2.75999 $ FindTrend PFE 2019-07-02 2019-07-12 2019-07-02 187.18 2019-07-03 103.92 2019-07-05 185.40 2019-07-06 187.97 2019-07-09 1 190.581 2019-07-10 | 190.05 se 2019-07-11 I 187.88 2019-07-12 | 191.03 $ FindTrend MRNA 2009-01-01 2020-05-01 $ FindTrend PFE 2020-05-07 2020-05-23 2020-05-07 | 202.86 2020-05-08 | 202.90 2020-05-09 1 200.72 10OIS Tek to find comm HR le Xcut Paste C Copy - Format Painter Calibri - 11 - A A = = = BIU--- A.QE E Merge and Wrap Center- Text General - % 000 000 1800 Forma . Conditional 1 Cell SI Formatting A1 @fx Date H 1 K + A B D E F G 1 Date Open High Low Close Adj Close Volume 2 7/2/2019 43.060001 45 42.75 44.98 44.98 16703600 37/3/2019 45.360001 45.48 43.799999 43.889999 43.889999 14237500 4 7/5/2019 44.07 45.110001 43.549999 45.060001 45.060001 16172000 5 7/6/2019 44.91 46.75 44.610001 46.650002 46.650002 23740700 6 7/9/2019 46.740002 46.900002 42.080002 44.139999 44.139999 107582400 7 7/10/2019 44.200001 45.259998 43.630001 43.75 43.75 38467400 8 7/11/2019 42.630001 44.099998 42.220001 13.869999 43.869999 35100100 9 7/12/2019 44.799999 45.34 44.360001 45.259998 45.259998 27078500 10 7/13/2019 45.279999 45.32 43.93 44.490002 44.490002 16426700 11 7/16/2019 44.299999 44.73 43.91 44.259998 44.259998 13012800 12 7/17/2019 43.59 45.259998 43.150002 44.709999 44.709999 20122300 13 7/18/2019 44.189999 44.75 42.740002 43.34 43.34 26536800 14 7/19/2019 43.27 43.869999 43.110001 43.439999 43.139999 13366800 15 7/20/2019 43.5 44.130001 43.23 43.419998 43.419998 10437700 16 7/23/2019 43.450001 43.849998 42.400002 43.310001 43.310001 15251200 17 7/24/2019 43.77 43.799999 41.59 42.169998 12.169998 22433900 18 7/25/2019 42.349998 44.389999 42.349998 44.220001 44.220001 25140700 197/26/2019 42.869999 43.41 42.139999 42.939999 42.939999 30018700 20 7/27/2019 37.25 37.470001 33.900002 34.119999 34.119999 122752800 21 7/30/2019 34.169998 34.259998 31.07 31.379999 31.379999 77852400 22 7/31/2019 31.950001 32.48 31.07 31.870001 31.870001 64392200 23 8/1/2019 32.25 32.59 31.459999 31.91 31.91 33231700 24 8/2/2019 31.58 32.869999 31.34 32.82 32.82 27088000 25 8/3/2019 32.580002 32.990002 31.799999 31.959999 31.959999 26317000 26 8/6/2019 31.82 33.040001 31.450001 32.98 32.98 27512400 27 8/7/2019 33.099998 33.610001 32.549999 32.669998 32.669998 24635600 nlnl PRINT * Painter Center Text Formatting A1 Q fx Date H 1 J K A B D E G 1 Date Open High Low Close Adj Close Volume 2 7/2/2019 183.82001 187.3 183.42 187.17999 182.19901 17731300 3 7/3/2019 187.78999 187.95 183.53999 183.92 179.02577 13954800 4 7/5/2019 185.26 186.41 184.28 185.39999 180.46637 16604200 5 7/6/2019 185.42 188.42999 185.2 187.97 182.96797 17485200 6 7/9/2019 189.5 190.67999 189.3 190.58 185.50855 19756600 7 7/10/2019 190.71001 191.28 190.17999 190.35001 185.2847 15939100 8 7/11/2019 188.5 189.78 187.61 187.88001 182.88039 18831500 9 7/12/2019 189.53 191.41 189.31 191.03 185.94656 18041100 10 7/13/2019 191.08 191.84 190.89999 191.33 186.23857 12513900 11 7/16/2019 191.52 192.64999 190.42 190.91 185.82977 15043100 12 7/17/2019 189.75 191.87 189.2 191.45 186.35538 15534500 13 7/18/2019 191.78 191.8 189.92999 190.39999 185.33331 16393400 14 7/19/2019 189.69 192.55 189.69 191.88001 186.77396 20286800 15 7/20/2019 191.78 192.42999 190.17 191.44 186.34569 20676200 16 7/23/2019 190.67999 191.96001 189.56 191.61 186.51111 15989400 17 7/24/2019 192.45 193.66 192.05 193 187.86415 18697900 18 7/25/2019 193.06 194.85001 192.42999 194.82001 189.63571 16709900 19 7/26/2019 194.61 195.96001 193.61 194.21001 189.04195 19076000 20 7/27/2019 194.99001 195.19 190.10001 190.98 185.8979 24024000 21 7/30/2019 191.89999 192.2 189.07001 189.91 184.85637 21029500 22 7/31/2019 190.3 192.14 189.34 190.28999 185.22624 39373000 23 8/1/2019 199.13001 201.76 197.31 201.5 196.13796 67935700 24 8/2/2019 200.58 208.38001 200.35001 207.39 201.87122 62404000 25 8/3/2019 207.03 208.74001 205.48 207.99001 202.45523 33447400 26 8/6/2019 208 209.25 207.07001 209.07001 203.5065 25425400 27 8/7/2019 209.32001 209.5 206.76 207.11 201,59865 25587400 nr nr PFE.csv + 10 4 07 an ranStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started