- Using the ff_monthly.csv data set https://github.com/alexpetralia/fama_french, use the first column as an index (this contains the year and month of the data as a string
- Create a new column ‘Mkt’ as ‘Mkt-RF’ + ‘RF’
- Create two new columns in the loaded DataFrame, ‘Month’ and ‘Year’ to contain the year and month of the dataset extracted from the index column.
- Create a new DataFrame with columns ‘Mean’ and ‘Standard Deviation’ and the full set of years from (b) above.
- Write a function which accepts (r_m,s_m) the monthy mean and standard deviation of a return series and returns a tuple (r_a,s_a), the annualised mean and standard deviation. Use the formulae: r_a = (1+r_m)^12 -1, and s_a = s_m * 12^0.5.
- Loop through each year in the data, and calculate the annualised mean and standard deviation of the new ‘Mkt’ column, storing each in the newly created DataFrame. Note that the values in the input file are % returns, and need to be divided by 100 to return decimals (i.e the value for August 2022 represents a return of -3.78%). . Print the DataFrame and output it to a csv file.
Workings so far:
import pandas as pd
ff_monthly=pd.read_csv(r"file path")
ff_monthly=pd.read_csv(r"file path",index_col=0)
Mkt=ff_monthly['Mkt-RF']+ff_monthly['RF']
ff_monthly= ff_monthly.assign(Mkt=Mkt)
df=pd.DataFrame(ff_monthly)