Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Python project assignment using numbers, strings, for loops, if else, def, lists, math and randomness, simulation, and plots

Python project assignment using numbers, strings, for loops, if else, def, lists, math and randomness, simulation, and plots

Computer Science

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.

  1. Markdown practices [2 pts]
    1. [ review] How to create and revise a markdown cell?

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

    1. [ new] Other structural writing in a markdown cell
  1. Insert an unorder list: You can use dashes (-), asterisks, or plus signs (+) to indicate each bullet point; enter it line by line.

 

Point 1

Point 1.1

 

Point 1.1.1

Point 2

Point 3

  1. Insert equations: if you know LaTeX, we follow the same rule here; if you don't know LaTeX, we don't test it in this class. For those who are interested: for example, variance of X is composed as $\frac{\sum^N_i

?? (??−?(?))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 $.

  1. Insert image:

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

  1. Insert codes:

print "Hello World"

    1. Useful internet links

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]

  1. How certain are we about a return statistics-ofinterest? [20 pts]

* Statistical concept: Randomness, simulation 

** Finance concept: Return statistics

    1. Notations :

?:  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.

  1. ?

    =

    (

    ?

    (

    ?

    )

    ?

    ?

    ?

    ?

    )

    2

    ?

    =

    ?

    (

    ?

    (

    ?

    )

    ?

    ?

    ?

    ?

    )

    2

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    If it is mean: ?? ? = ?? ??
  2. If it is variance: ?? ?
  3. If it is standard deviation: ??           ?
    1. A type of bootstrapping that we will use :

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:

 

 

    1. The Question

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

  1. S&P GSCI Commodity Returns
  2. S&P GSCI Gold Returns
  3. MSCI USA Stock Market Returns 
  4. MSCI Emerging Market Returns 
  5. MSCI Euro Area Market Returns 
  6. US 10-Year Government Bond Returns

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

)

print

(

data

.

head

())

print

(

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 ]

  1. "Disaster" days in the US stock market [18 pts]

* 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/2963?/1129/3613/12/31 ∗ 100% is 0.55%. The sample spans the past 57  years (N=14871 trading days ).

Analysis:

  1. Use the first 100 days of returns in the sample as the baseline distribution, and calculate how extreme the return on the 101th day in the sample is compared to the last 100 days of returns. Then, let's move onto the 102nd day and use the last 100 days of returns (now from the 2nd return to the 101th return) as the baseline distribution. Repeat this step until the end of the sample using such rolling windows of the most recent 100 daily returns as baseline distributions to evaluate today's return, and obtain Prob(xtoday's return) on each day.

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.

  1. Define disaster days if Prob(xtoday's return)1 %. How many days in our whole dample do you identify as disaster days? Or what is the fraction? Notice that there are 14771 days with valid fraction/disaster probability values (Hint2 above), although the full sample has 14871 days.
  2. Finally, what is the fraction of disaster days within each year? Can you also produce a time series plot?

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

)

print

(

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 ]

Print system time

 

In

 [ ]:

import

 

time

time

.

ctime

()

 

 

Finally, click on the disk icon to save your notebook, and then choose "close and halt" from the File menu.

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.

Option 1

Low Cost Option
Download this past answer in few clicks

18.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE