python编程代写,python代写,python homework代写
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 smarket which takes no arguments and return no values. Your function smarket 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 $ 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 is restricted to buying and selling only the following two stocks: Apple (AAPL) and Twitter (TWTR). An attempt to buy or sell any stock other than those three is not valid and should result in your program printing an error message before displaying the next prompt.
1 Historical stock prices
Your program will use historical stock prices of APPL and TWTR 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 three files: APPL.csv and TWTR.csv. These three files contain stock price data for APPL and TWTR, 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/2018 and
6/30/2020. Each file is in ”CSV” format, which stands for ”comma-separated value”. The
contents of the file are table 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. Your program should accept the following commands related to historical price data:
2 Finding Trends
You need to write a function which identifies when to buy and sell a stock based on stock market trends. There are two trends which you need to identify.
1. A buy trend 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.
2. A 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.
Your program should allow the user to enter the FindTrend command which takes 3
arguments: the name of the stock, the start date, and the end date. The FindTrend command should examine the sequence of dates between the start and end dates and find identify the dates to buy and sell the stock according to the buy trends and sell trends.
3 Command Summary
This is a summary of all of the commands that your program should accept.
• ReadPrices: This command should read the historical price data from the two files.The command takes 2 arguments, the pathname of the APPL data file and the pathname of the TWTR data file.
• Prices: This command should display the stock prices of both stocks on a given date. This command takes 1 argument, the date.
• MaxProfit: This command should calculate the maximum possible profit for a single share of a given stock. This profit should be considered over the entire time period described by the historical data, between 7/2/2018 and 6/30/2020. In other words, if you buy your stock when the stock price is minimum and sell it when the stock price is at its max, what will be the profit. Note that the selling date must be later than the buying date. This command takes 1 argument, name of the stock.
• FindTrend: This command should examine the sequence of dates between the start and end dates and find identify the dates to buy and sell the stock according to the buy trends and sell trends. This command takes 3 arguments: the name of the stock, the start date, and the end date.
• quit: This command ends the program.
