HW4 Stock Market Trading In this assignment you will write a python… HW4 Stock Market TradingIn this assignment you will write a python program which:Load the daily stock prices for Apple Corporation (stock ticker AAPL) data from yahoo finance, from Jan 2nd 2020 through Dec 31st 2020. note: you will not include Jan 1st 2020 since its a holiday (New Years day)Run a mean reversion trading strategy on the data.Output the results of the strategy including the profits (see sample output below).What is the ‘Mean Reversion’Mean reversion is the theory suggesting that prices and returns eventually move back toward the mean or average. This mean or average can be the historical average of the price or return, or another relevant average such as the growth in the economy or the average return(Links to an external site.) of an industry.In other words, when the price goes too low, (i.e. 95% of the 5-day average) you buy it, believing the price will increase and return to the average. Likewise, if the price goes too high (i.e. 105% of the 5-day average price) you sell it, believing the price will decrease and return to the average. This view believes the average price is more correct than the current price, and that the current price will come back to the average.You will download one year’s worth of stock market prices for Apple Corporation (stock ticker AAPL) data from yahoo finance, from Jan 2nd 2020 through Dec 31st 2020.To download the prices in a spreadsheet go to:finance.yahoo.com -> search “AAPL” -> Historical data -> enter Time Period: start date 01/02/2020, end date 01/01/2021 (one day higher than 12/31/2020) -> Apply -> click Download (right under Apply)This will save a AAPL.csv file on your local computer.The csv file will have the columns: Date, Open, High, Low, Close, Adj Close, Volume.You only want the “Adj Close” column. Copy all the prices in the “Adj Close” column. Create a folder in C9 called “hw4”. Create a file in the hw4 folder called AAPL.txt. Paste the prices into the AAPL.txt file. There should be one price per line and nothing else.Now you can open your file, and read the lines, from your Python program, like this:# Note: your file path below needs to match the full file path of the file your created in c9# Some of your paths will be /home/ubuntu/environment# You can check that in cloud9 by looking next to the top level folder with the same# name as your environmentfile = open(“/home/ec2-user/environment/hw4/AAPL.txt”)lines = file.readlines()for line in lines:price = float(line) price = round(price, 2) # to round the price to 2 decimalsprint(price)Coding Requirements-Loop through all the prices, calculating a 5 day moving average each time.-Each iteration of the loop should update the current_price (the newest line), and the 5 day moving average (the average of the previous 5 days).-Add an if statement which checks to see if the current price is below the 5 day moving average * .95. If it is, “buy” the stock, meaning keep track of the price you bought at. Update a variable called “buy” with the buy price.-Add an elif statement along with the if statement which checks to see if the current price is above the 5 day moving average * 1.05. If it is, “sell” the stock, meaning calculate the profit of that trade: sell – buy. You want to buy low and sell high, so sell – buy is hopefully positive.-Add an else statement along with the if else if which does not buy or sell.# the basic logic, explained above, will look like this# this is not the complete logic, but you are allowed to copy/paste and start with thisCurrent_price = #the next price in the listAvg_price = #average price for the 5 previous daysif current_price < average * 0.95:#buy#update buy variable#update first_buy variable if this is the first time you buyelif current_price > average * 1.05:#sell#calculate profit of this individual trade#keep a running total of all profitelse:# do nothing this iteration- Keep track of the first price you buy.- Keep track of the profit each time you sell. Print out the profit for each trade. Keep a running total of profit from all trades.- After the loop is complete, calculate the final_profit_percentage and print it to the console:final_profit_percentage = ( total_profit / first_buy ) * 100Sample Output (for AAPL)AAPL Mean Reversion Strategy Output:buying at: 73.85selling at: 74.98trade profit: 1.13buying at: 65.92selling at: 64.0trade profit: -1.92buying at: 66.46selling at: 85.42trade profit: 18.96buying at: 120.29selling at: 123.79trade profit: 3.5buying at: 108.33selling at: 118.45trade profit: 10.12—————————total profit: 31.79first buy: 73.85final percentage profit: 43.05 %Computer ScienceEngineering & TechnologyPython Programming MIS 3500

Order your essay today and save 20% with the discount code ESSAYHELP