python 实验代写代做、代写python pandas,帮做python 编程|帮做python, 代写python 编码作业、代做python 程作业

1. In this first homework, you will analyze the total return index of the total market portfolio.
Let us get started by downloading the monthly market index data from https://www.dropbox.com/s/kbpogdpo52tbmba/TotalReturnRFMKT.csv?dl=1
? There are three variables in the data set:
? Date: the calendar month end. Notice this is not the last trading date in each month.
? RF: the index of a risk-free asset.
? MKT: the index of a market index.
? Use the pandas.read_csv() function. Type ?pandas.read_csv in the console to consult the help file.
? What do you have to do before using pandas?
In the pandas.read_csv() function, you should indicate that the data in the CSV file has a header (header argument).
Instructions
1. Create a new variable data_url that contains the URL to the CSV file.
2. Create a new variable mkt_df that contains the data frame with the Apple data.

2. Before you analyze return data, it is a good idea to have (at least) a quick look at the data. Pandas has a number of functions that help you do that:
The head() and tail() method shows you the first and the last part of an object, respectively.
The type() function shows you the type of an object.
The describe methods provides some useful summaries about the data
Instructions
1. mkt_df should be a data frame object. Show that this is true using the type function.
2. Have a look at the first and the last part of the data.
3. Show the number of observations in this dataset (we use this function in the past)
4. Show the number of variables in this dataset (we use this function in the past)
3. Getting indexing right
1. It is very important that we get the indentity of each observation right
2. The identity must be unique so there is not uncertainty when we refer to it
3. Note that Pandas created a new column (column 0) that gives the "name" to each observation
4. It uses as a name a sequence of numbers so each name is unique
5. Here we can have a more useful name, the date, which is also unique in this context (there is only one observation per day!)
6. In pandas we refer to this indentiy as the "index" of the datafram
Instructions:
1. the .iloc[name] allow you to recover a particular observation, use this method to recover the 11th date in the data set. (recall that it starts from zero)
2. use ?pandas.read_csv to find out how to tell pandas that column 0 of the orginal data set should be index
3. Show that now the first colum is the date
4. Now use the loc method to recover the return in 09/30/2008 (pay attention in the format)
4. Getting the type of the variables right
Because pandas is very flexible and can handle multiple types, it is very important to check that the type of each variable was imported correctly, otherwise we won't be able to do manipulations
Instructions
1. Check the type of each variable in mkt_df by using the method info().
2. Take the mean of 'MKT' by writing mkt_df['MKT'].mean().
3. Set the type of 'MKT' as string instead of float by using the method astype().
4. Do 2. again. Can you still get the result as before?
5. Returns
Lets focus on close-to-close returns, i.e. the return in stock between the closing price of two subsequent days
1. Compute simple returns
? we want MKT_RET[t+1] = (MKT[t+1])/MKT[t]-1
? First try MKT_RET1 = (mkt_df.MKT[1:])/mkt_df.MKT[:-1]-1
? What this is trying to do?
2. Do MKT_RET2 = mkt_df.MKT.values[1:]/mkt_df.MKT.values[:-1]-1
? Here we are directly selecting the values of the dataseries obsject
? What do you note about the type of the MKT_RET variable?
3. What are the differences between the MKT_RET1 and MKT_RET2 objects?
4. Compute the mean of both series. What you think is going on with MKT_RET1?
5. To stay within Pandas we can use the shift method after setting the index as datetime, where you use MKT.shift(1) to lag the data one period. You can also type shift(-1) to lead the data.
? Try mkt_df.MKT.shift(1) to lag MKT one month.
6. Using the dataframe mkt_df to compuate the mean, standard deviation, median, min, and max of the market return 'MKT_RET'.
7. Find the date of the minimum and the maximum market return.
8. use the .quantile(number) method to find the 5% quantile of market returns. Explain what this number means.
6. Plotting
Pandas has built plot functionality that is based on the matplotlib package we say in class
It is really easy and intutiive (here the reference: https://pandas.pydata.org/pandas-docs/stable/visualization.html)
1. Make a time-series plot of the return data (always using Return dataframe object)
? use the method .plot()
2. Make a histogram with 100 bins
? use the method .hist(bins=100)
3. Make a plot of the cumulative returns
? Follow the steps we did in class to construct the cumulative returns and then plot
4. Make a plot of the close price
? Scale the close price by the price at the initial date and compare with the cumulative return plot.
? What do you notice? Is this always true?http://www.6daixie.com/contents/3/1727.html
5. Make a plot of the square of market returns , this is a good proxy for volatility
? Import numpy as np and use np.power() to calculate the square of market returns.
6. Add a label to the y-axis decribing the varaible plotted (when not generated automatically)
? Tip: use the plot object .(Tab) to find the mehtods that can be used to change the plot
7.
Use a "for loop" and "if statements" to compute the final value of a trading strategy that starts with 1 dollars in the beggining of the sample, and invests 100% of it value in the stock market at the end of december and invests 100% at the risk-free rate end of january. What is the final value of this investment?
8.
Write a function that has as an input a month "jan", feb",mar" , and so on, as a output returns the final value of being invested in the stock market in this particular month, i.e. the general version of what you did in 7 above. Which month has the highest total returns

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codinghelp

猜你喜欢

转载自www.cnblogs.com/RRRRRRcodinghelp/p/9622189.html