question archive Python project assignment using numbers, strings, for loops, if else, def, lists, math and randomness, simulation, and plots
Subject:Computer SciencePrice:19.99 Bought23
Python project assignment using numbers, strings, for loops, if else, def, lists, math and randomness, simulation, and plots. Data is given for the project questions. Please no tuple. Directions are pretty clear and can be found in the files. I code using Jupyter notebook, not sure if this helps, this is an Intro-level python class.
1. This is an individual, open-book, take-home project. 2. Coding grading guideline: You will receive partial points if you provide your logic steps in comments. 3. Disucssion grading guideline: Your discussions should be in markdown formats, not in comment formats. In your discussions, you should compose several paragraphs that (a) state your analysis procedures and statistical results and (b) discuss result interpretations and further thoughts. The writing should be clear and formal.
place your mouse to the left of a cell (not inside the cell) single click on it; the color bar should turn from green to blue enter "m" (m=markdown) on your keyboard; you should see that "In [ ]:" disappeared type in things in the cell now
enter "shift+enter" to compile the markdown cell
You can also go back and edit the markdown cell you just compiled:
double clicks on it
OR, enter "y" and then "m" on your keyboard
Point 1 |
Point 1.1
Point 1.1.1
Point 2
Point 3
∑?? (??−?(?))2
(x_i - E(X))^2}{N}$ (this is what you write in a markdown cell), ? (this is what you get after shift-enter). The math equations must start with a dollar sign $ and close with a dollar sign $.
create an empty markdown cell, place your mouse inside the cell find "Edit" along the task bar find the last item "Insert Image" chose your file to insert shift-enter
print "Hello World"
https://www.markdownguide.org/basic-syntax/ (https://www.markdownguide.org/basic-syntax/) http://agea.github.io/tutorial.md/ (http://agea.github.io/tutorial.md/) https://help.github.com/en/articles/basic-writing-and-formatting-syntax (https://help.github.com/en/articles/basic-writing-and-formatting-syntax) https://guides.github.com/features/mastering-markdown/ (https://guides.github.com/features/masteringmarkdown/) https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet (https://github.com/adam-p/markdownhere/wiki/Markdown-Cheatsheet)
In [ ]: # Please create a new markdown cell below and reproduce the following paragraph. [2pts]
[YOUR REPLICATION HERE]
* Statistical concept: Randomness, simulation
** Finance concept: Return statistics
?: number of actual observations given a time series of asset returns; e.g., in unit of months
?: an original sample of asset returns, ? = (?1, . . . , ??); for instance, it includes returns on October 2020 , November 2020, December 2020 etc.
?? ?: the sample statistics of interest, where ? can represent mean, standard deviation, variance.
? |
= |
( |
− |
? |
( |
? |
) |
∑ |
? |
? |
? |
? |
) |
2 |
? |
= |
? |
( |
− |
? |
( |
? |
) |
∑ |
? |
? |
? |
? |
) |
2 |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
√ |
Round 1: In the first round, suppose we randomly withdraw a subsample of the origional sample ? (sampling without replacement), and call it ??????=1 ("1" stands for first round). Given the subsample ??????=1, you can calculate some statistics ? of interset, call it ?? ?????=1 (1=first round).
Round 2: Next, you put ??????=1 back in, and randomly withdraw another subsample from ?; call the new subsample ??????=2. Given ??????=2, you can calculate the same statistics using the subsample, call it
?? ?????=2.
Future rounds: Repeat for ? rounds. You should obtain ? numbers of statistics from these many rounds of boostrapping. In scientific studies, we refer to this procedure as "bootstrapping the original sample for ? times".
The figure below illustrates the procedure:
Researchers use bootstrapping methodologies to understand how certain we are about ?? ? (the sample statistics using the original sample as noted under 1.1). In this question, you will bootstrap 6 asset returns, one-by-one, to infer how certain we are about each asset's volatility (return volatility=return standard deviation).
Asset returns: QUESTION1DATA.csv
All asset returns are expressed in current US dollars (source: DataStream; MSCI; Bloomberg). These are monthly returns (not in percentage points); that is, for instance, "0.026561915" in Cell B2 means that changes
?1988/01− ?1987/12 in the world commodity price from December 1987 to January 1988 ?1987/12 ∗ 100% is 2.66%. The data is balanced from January 1988 to December 2020 (N=396 months).
Parameters:
Each bootstrapping subsample has 300 observations; We bootstrap for 10000 rounds.
Discussion suggestions:
Here are some questions to think about and eventually help you organize your discussions:
What is the sample standard deviation? (You should not use numpy or other canned functions) What is the mean of all bootstrapped standard deviations? And how does it compare to the sample standard deviation?
Can you compare the (un)certainty across the 6 asset volatilities?
When you change some parameters in the boostrapping procedure, do you see different results? Why? Your own topic
Editorial suggestion:
Please make your answers and procedures easy to read and follow |
print+format, markdowns, plots... these are all helpful tools. |
Setup: Import QUESTION1DATA.csv, and print first 5 rows including the header (see 1.4.3 and HW5 for references)
In |
[ ]: |
In |
[ ]: |
import |
|
pandas |
import |
|
math |
import |
|
random |
|
data |
|
= |
|
pandas |
. |
read_csv |
( |
'QUESTION1DATA.csv' |
, |
header |
= |
0 |
, |
parse_dates |
= |
True |
) |
|
( |
data |
. |
head |
()) |
|
( |
len |
( |
data |
[ |
'DATE' |
])) |
portlist |
|
= |
[ |
'COMMODITY' |
, |
'GOLD' |
, |
'STOCK_US' |
, |
'STOCK_EM' |
, |
'STOCK_EUROPE' |
, |
'GOVBOND_US' |
] |
Your answers below
In |
[ ]: |
In |
[ ]: |
In |
[ ]: |
# Step 1: Conduct bootstrapping procedure [10pts] |
# Step 2: Obtain standard deviation of bootstrapped standard deviations [3pts] |
# Step 3: Your discussions in the markdown cell below. [7pts] |
# You can include written paragraphs, figures, tables, equations etc. as you wish to furthe |
[ YOUR DISCUSSION HERE ]
* Statistical concept: Probability and extreme values, rolling sample
** Finance concept: Risk evaluation, Value at Risk
In this question, we are interested in learning how often disaster-type events appeared in the US stock market over the last 57 years, and what year(s) was(were) associated with the most-often disaster days. Below is how we are going to conduct the analysis.
Asset returns: QUESTION2DATA.csv
Column 4 reports the daily changes in the S&P 500 index (source: DataStream). These are daily returns (not in percentage points); that is, for instance, "0.005465209" in Cell E2 means that daily change in the S&P 500
index from 12/31/1963 to 1/2/1964 (1/1 holiday) ? 1964?/11/29− 63?/1129/3613/12/31 ∗ 100% is 0.55%. The sample spans the past 57 years (N=14871 trading days ).
Analysis:
Hint1: In Task 1 in 1.4.1, we have calculated the probability of getting a number that is less than X, given a distribution; in analogy, here, the distribution is always formed by the recent 100 daily returns; X is the return on the 101th day.
Hint2: The first day we can evaluate its risk is the 101th day.
Notice that the number of trading days can vary from year to year.
Discussion suggestions:
Here are some questions to think about and eventually help you organize your discussions:
How to interpret a higher fraction? (higher means more or fewer disaster days?) How does it evolve during the sample period from 1964 to 2020?
Which year(s) have the lowest or highest fraction? Why? What are potential economic events related to that year?
What do you see during 2020? How does this fraction compared to other years? Why?
What happens if you use a less restrictive threshold for disaster days? (rather than 1%, what if you use 2.5 %? )
Your own topic
Editorial suggestion:
Please make your answers and procedures easy to read and follow |
print+format, markdowns, plots... these are all helpful tools. |
Setup: Import QUESTION2DATA.csv, and print first 5 rows including the header (see 1.4.3 and HW5 for references)
In |
[ ]: |
In |
[ ]: |
% |
matplotlib |
|
inline |
import |
|
math |
import |
|
random |
import |
|
matplotlib |
. |
pyplot |
|
as |
|
plt |
import |
|
pandas |
|
data |
|
= |
|
pandas |
. |
read_csv |
( |
'QUESTION2DATA.csv' |
, |
header |
= |
0 |
, |
parse_dates |
= |
True |
) |
|
( |
data |
. |
head |
()) |
RET |
|
= |
|
list |
( |
data |
[ |
'RET_SP500' |
]) |
DATE |
|
= |
|
list |
( |
data |
[ |
'DATE' |
]) |
YEAR |
|
= |
|
list |
( |
data |
[ |
'YEAR' |
]) |
Your answers below
In [ ]: # Step 1: use rolling windows and calculate how extreme today's return is compared to the r
# That is, obtain Prob(x<=today's return), where x is from a distribution formed by the re
In [ ]: # Step 2: Define disaster days if Prob(x<=today's return)<=1%.
# How many days in our whole sample do you identify as disaster days? Can you report it in
In [ ]: # Step 3: What is the fraction of disaster days within each year? Can you also produce a t # Name it Question2_fraction_YOURBCNAME.png [4pts]
In [ ]: # Step 4: Your discussions in the markdown cell below. [4pts]
# You can include written paragraphs, figures, tables, equations etc. as you wish to furthe
[ YOUR DISCUSSION HERE ]
In |
[ ]: |
import |
|
time |
time |
. |
ctime |
() |
|
You can now upload a Jupyter Notebook (.ipynb) copy of your notebook to Canvas. In my case, I would upload "Project2021-xuaeh.ipynb" and "Question2_fraction_xuaeh.png" from Question 2 above.
Purchased 23 times