In this project, we will create functions that allow us to simulate future prices of a stock based on properties of that stock.
INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS
In this project, we will create functions that allow us to simulate future prices of a stock based on properties of that stock. We will use these simulations to answer questions about the probability that the stock's price will be in a certain rate at a certain time. Before jumping into the code, we will provide a brief bit of mathematical background for the models that we will be using.
A yield rate for a stock is (roughly speaking) the percentage increase or decrease in the value of the stock over a certain period. Suppose that the price of a stock today is 100 and the stock has a yield rate of 12% over the next year. Then the price of the stock at the end of the year will be 100 ⋅ 𝑒0.12 = 112.75.
Let 𝑆0 denote the current price of a stock. Suppose that we randomly generate simulated daily yield rates for the stock over the next 𝑛 days. Denote these simulated rates as 𝑅1, 𝑅2, … , 𝑅𝑛. Let 𝑆𝑡 denote the price of the stock at the end of day 𝑡.
Then simulate value of 𝑆𝑡 is given by 𝑆𝑡 = 𝑆0𝑒𝑅1 𝑒𝑅2 ⋅ … ⋅ 𝑒𝑅𝑡, or 𝑆𝑡 = 𝑆0𝑒𝑅1+𝑅2+⋯+𝑅𝑡. For convenience, define the
cumulative yield rate on day 𝑡 to be 𝐶𝑅𝑡 = 𝑅1 + 𝑅2 + ⋯ + 𝑅𝑡. Then we can write the formula for the simulated price on day 𝑡 as 𝑆𝑡 = 𝑆0𝑒𝐶𝑅𝑡 .
Let's explain these concepts with an example:
• Assume that the current price of the stock is 120.
• Suppose that the simulated daily yields over the next 5 days (𝑅1 through 𝑅5) are given by:
daily_yields = [0.02, 0.01, -0.04, 0.03, 0.05]
• Then the cumulative daily yields (𝐶𝑅1 through 𝐶𝑅5) are given by:
cumulative_yields = [0.02, 0.03, -0.01, 0.02, 0.07]
• The simulated daily prices would be given by:
simulated_prices = [120e0.02, 120e0.03, 120e-0.01, 120e0.02, 120e0.07]
Create a new notebook named Project_03_YourLastName.ipynb and complete the instructions provided below.
Any set of instructions you see in this document with an orange bar to the left will indicate a place where you should create a markdown cell. If no instructions are provided regarding formatting, then the text should be unformatted.
Any set of instructions you see with a blue bar to the left will provide instructions for creating a single code cell. Read the instructions carefully.
Create a markdown cell with a level 1 header that reads: "DSCI 303 – Project 03". Add your name below that as a level 3 header.
Import the following packages: numpy, math, and matplotlib.pyplot. No other packages should be used in this project.
Part A: Stock Simulation Function
In this section, you will create and test a function to generate sequences of simulated daily stock prices, or runs.
Create a markdown cell that displays a level 2 header that reads: "Part A: Stock Simulation Function". Also add some text briefly describing the purpose of your code in this part.
Write a function named simulate_stock. This function will randomly generate a simulated sequence of daily stock prices (which we will call a run) based on several parameters. A description of this function is found below.
The parameters for simulate_stock are start, rate, vol, and days.
• start will represent the current price of the stock. This will be the starting price for the run.
• rate will be the expected annual yield rate for the stock.
• vol will be the annual volatility of the stock. This is a measure of how much uncertainty there is in the future price of the stock. Stock with a higher volatility will have prices that are a lot "swingier". In statistical terms, the volatility is the standard deviation of the stock's annual yield.
• days will be the number of days into the future that we would like to simulate prices.
The function should return an array that contains days + 1 elements. The first element of the returned array should be the starting price, start, while the later elements should be simulated stock prices. For example, if days = 4, then the function should return an array with 5 values, the starting price and 4 simulated prices.
The process for calculating the array of simulated prices is as follows:
1. We will assume that the daily yield rates follow a normal distribution with a mean determined by the parameter rate, and a standard deviation determined by the parameter vol. Since the parameters rate and vol relate to the annual yield, we will have to scale them down to work with daily yields. The stock market has around 252 trading days in a given year, so to scale down to daily yields, we will need to divide rate by 252 and divide vol by
√252 (these facts would be covered in a probability course).
Use np.random.normal to create an array of randomly generated daily yields. The mean (loc) should be set to rate/252 and the standard deviation (scale) should be set to vol/(252**0.5). The number of elements in this array should be equal to days. I suggest naming the array daily_yields.
2. To calculate the simulated stock price at the end of each day, we need to know the cumulative yields. Use
np.cumsum to calculate this. I suggest naming the results cumulative_yields.
3. Create an array called daily_multipliers by exponentiating each of the cumulative yields. You can accomplish this using np.exp.
4. Multiply the daily multipliers by the starting price to get the simulated daily prices for each day. Round these simulated prices to 2 decimal places.
5. The number of elements in the array that you have created should be equal to days. We wish to add the starting price to the beginning of this array. You can accomplish this using np.concatenate.
6. Return the array of days + 1 elements created in Step 5.
. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java
CS 340 Milestone One Guidelines and Rubric
Overview: For this assignment, you will implement the fundamental operations of create, read, update,
. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class
Retail Transaction Programming Project
Develop a program to emulate a purchase transaction at a retail store. This
. The following program contains five errors. Identify the errors and fix them
Secure Systems Programming
Referral Coursework: Secure
. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer
CS 340 Final Project Guidelines and Rubric
Overview The final project will encompass developing a web service using a software stack and impleme