1) Explanation of important variables in the python code (with comment out function). 2) Use Jupiter notebook of python 3) Please clearly mention questions (a) or (b) or (1) or (2) in python code not...

1 answer below »
Regression (heteroskedastic test) and PCA.


1) Explanation of important variables in the python code (with comment out function). 2) Use Jupiter notebook of python 3) Please clearly mention questions (a) or (b) or (1) or (2) in python code not to be confused. Guidance) Performance analysis of hedge fund returns using linear regression. Download and import the following data into your Jypyter notebook: /////// sample coding for your reference in case that you are not familiar with the dataset. /// import pandas_datareader.data as reader import pandas as pd import datetime as dt import statsmodels.api as sm import os import numpy as np import yfinance as yf from datetime import datetime #Load Stock price df = yf.download("QMNIX", start= datetime(2015,1,1), end = datetime(2021,9,1),interval='1mo') df end = dt.datetime(2021, 9,1 ) start = dt.datetime(2015, 1,1 ) funds= ['QMNIX'] fundsret = reader.get_data_yahoo(funds,start,end,interval='m')['Adj Close'].pct_change() fundsret.shape factors = reader.DataReader('F-F_Research_Data_5_Factors_2x3','famafrench',start,end)[0] factors.shape factors = factors[1:] factors.head() factors.shape fundsret = fundsret[2:] fundsret.head() fundsret.shape fundsret.index=factors.index fundsret merge = pd.merge(fundsret,factors,on='Date',how='left') merge.head() merge[['Mkt-RF','SMB','HML','RMW','CMA']]=merge[['Mkt-RF','SMB','HML','RMW','CMA']]/100 merge //////////////// • Monthly data of the Fama-French 5 Factor model from Ken French’s data library. (In the sample code above, it is already done. Please use it. ) • Monthly returns from Yahoo Finance for the AQR Equity Market Neutral Fund Class I (Ticker: QMNIX). Make sure you get the series that is adjusted for both dividends and splits (i.e. the series marked “Adj Close**” on Yahoo Finance). Note that Yahoo Finance will provide you with prices. Hence you will have to compute returns yourself. Question 1) Using the LinRegStatsmodels() Predictor Class, implement the performance analysis of the AQR hedge fund based on the Fama-French 5 Factor model by using heteroskedastic standard errors for all your statistics (heteroskedastic test). Question 2) PCA of Constant Maturity Treasury Rates
Answered 1 days AfterOct 15, 2021

Answer To: 1) Explanation of important variables in the python code (with comment out function). 2) Use Jupiter...

Sandeep Kumar answered on Oct 17 2021
120 Votes
{
"cells": [
{
"cell_type": "code",
"execution_count": 109,
"metadata": {},
"outputs": [],
"source": [
"import pandas_datareader.data as reader\n",
"import pandas as pd\n",
"import datetime as dt\n",
"import statsmodels.api as sm\n",
"import os\n",
"import numpy as np\n",
"\n",
"import yfinance as yf \n",
"from datetime import datetime\n",
"import statsmodels.formula.api as smf\n",
"from patsy import dmatrices\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 110,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[*********************100%***********************] 1 of 1 completed\n"
]
},
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
QMNIXMkt-RFSMBHMLRMWCMARF
Date
2015-020.0048920.06140.0031-0.0187-0.0112-0.01770.0
2015-03-0.023369-0.01120.0310-0.00410.0015-0.00540.0
2015-040.0428710.0059-0.03070.01830.0001-0.00640.0
2015-05-0.0009560.01360.0082-0.0113-0.0177-0.00710.0
2015-060.034450-0.01530.0289-0.00780.0043-0.01560.0
........................
2021-040.0373960.0493-0.0310-0.00930.0230-0.02790.0
2021-05-0.0614150.00290.01190.07040.02340.03100.0
2021-060.0014220.0279-0.0025-0.0776-0.0214-0.00990.0
2021-07-0.0241480.0119-0.0456-0.01750.0536-0.00550.0
2021-080.0276560.0291-0.0076-0.0007-0.0028-0.01670.0
\n",
"

79 rows × 7 columns

\n",
"
"
],
"text/plain": [
" QMNIX Mkt-RF SMB HML RMW CMA RF\n",
"Date \n",
"2015-02 0.004892 0.0614 0.0031 -0.0187 -0.0112 -0.0177 0.0\n",
"2015-03 -0.023369 -0.0112 0.0310 -0.0041 0.0015 -0.0054 0.0\n",
"2015-04 0.042871 0.0059 -0.0307 0.0183 0.0001 -0.0064 0.0\n",
"2015-05 -0.000956 0.0136 0.0082 -0.0113 -0.0177 -0.0071 0.0\n",
"2015-06 0.034450 -0.0153 0.0289 -0.0078 0.0043 -0.0156 0.0\n",
"... ... ... ... ... ... ... ...\n",
"2021-04 0.037396 0.0493 -0.0310 -0.0093 0.0230 -0.0279 0.0\n",
"2021-05 -0.061415 0.0029 0.0119 0.0704 0.0234 0.0310 0.0\n",
"2021-06 0.001422 0.0279 -0.0025 -0.0776 -0.0214 -0.0099 0.0\n",
"2021-07 -0.024148 0.0119 -0.0456 -0.0175 0.0536 -0.0055 0.0\n",
"2021-08 0.027656 0.0291 -0.0076 -0.0007 -0.0028 -0.0167 0.0\n",
"\n",
"[79 rows x 7 columns]"
]
},
"execution_count": 110,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Load Stock price\n",
"df = yf.download(\"QMNIX\", start= datetime(2015,1,1), end = datetime(2021,9,1),interval='1mo')\n",
"df\n",
"\n",
"end = dt.datetime(2021, 9,1 )\n",
"start = dt.datetime(2015, 1,1 )\n",
"funds= ['QMNIX']\n",
"fundsret = reader.get_data_yahoo(funds,start,end,interval='m')['Adj Close'].pct_change()\n",
"fundsret.shape\n",
"\n",
"factors = reader.DataReader('F-F_Research_Data_5_Factors_2x3','famafrench',start,end)[0]\n",
"factors.shape\n",
"factors = factors[1:]\n",
"factors.head()\n",
"factors.shape\n",
"\n",
"fundsret = fundsret[2:]\n",
"fundsret.head()\n",
"fundsret.shape\n",
"\n",
"fundsret.index=factors.index\n",
"fundsret \n",
"merge = pd.merge(fundsret,factors,on='Date',how='left')\n",
"merge.head()\n",
"\n",
"merge[['Mkt-RF','SMB','HML','RMW','CMA']]=merge[['Mkt-RF','SMB','HML','RMW','CMA']]/100\n",
"merge\n"
]
},
{
"cell_type": "code",
"execution_count": 111,
"metadata": {},
"outputs": [],
"source": [
"\n",
"def load_and_join():\n",
" mtum = yf.Ticker(\"QMNIX\")\n",
" stocks = [\"QMNIX\"]\n",
" start = datetime.datetime(2000,11,30)\n",
" end = datetime.datetime(2021,10,10)\n",
" \n",
" yf.pdr_override()\n",
" \n",
" df_etf = pdr.get_data_yahoo(stocks, start=start, end=end)\n",
" \n",
" df = pd.read_excel('https://images.aqr.com/-/media/AQR/Documents/Insights/Data-Sets/Century-of-Factor-Premia-Monthly.xlsx',\n",
" header =18, nrows = 1220)\n",
" \n",
" df['Date'] = pd.to_datetime(df['Date'])\n",
" \n",
" df = df.set_index('Date')\n",
" df = df[['Equity indices Momentum','Equity indices Momentum','Equity indices Carry','Equity indices Defensive']]\n",
" \n",
" df_final = df_etf.merge(df, how='left',left_index=True,right_index=True)\n",
" \n",
" return df_final\n",
"\n",
"def fill_joined_missing_fields(df):\n",
" for i in range(1,len(df)+1):\n",
" if np.isnan(df.iloc[-i,9]):\n",
" df.iloc[-i,6] = df.iloc[-i+1,6]\n",
" df.iloc[-i,7] = df.iloc[-i+1,7]\n",
" df.iloc[-i,8] = df.iloc[-i+1,8]\n",
" df.iloc[-i,9] = df.iloc[-i+1,9]\n",
" \n",
"\n",
"\n",
"'''(REVEER!)''' \n",
"def labeling_df(df):\n",
" df['50_days_average'] = df.iloc[:,3].rolling(window=50).mean()\n",
" df['200_days_average'] = df.iloc[:,3].rolling(window=200).mean()\n",
" df.loc[df['50_days_average'] >= df['200_days_average'], 'Buy/Sell'] = -1 \n",
" df.loc[df['50_days_average'] < df['200_days_average'], 'Buy/Sell'] = 1 \n",
" return df\n",
" \n",
"\n",
"def visualize_close_50_200(df):\n",
" plt.plot(df['Close'])\n",
" plt.plot(df['50_days_average'])\n",
" plt.plot(df['200_days_average'])\n",
" plt.legend(['Close','50_days_avg','200_days_avg'])\n",
" plt.title('Evolution of MTUM ETF over time')\n",
" plt.show()\n",
"\n",
"\n",
"def getWeights_FFD(d,size):\n",
" w=[1.]\n",
" for k in range(1,size):\n",
" w_=-w[-1]/k*(d-k+1)\n",
" w.append(w_)\n",
" w=np.array(w[::-1]).reshape(-1,1)\n",
" return w\n",
"\n",
"\n",
"def plotWeights(dRange,nPlots,size):\n",
" w=pd.DataFrame()\n",
" for d in np.linspace(dRange[0],dRange[1],nPlots):\n",
" w_=getWeights_FFD(d,size=size)\n",
" w_=pd.DataFrame(w_,index=range(w_.shape[0])[::-1],columns=[d])\n",
" w=w.join(w_,how='outer')\n",
" ax=w.plot()\n",
" ax.legend(loc='upper right');plt.show()\n",
" return\n",
"\n",
"\n",
"def fracDiff(series,d,thres=0.01):\n",
"\n",
" w=getWeights_FFD(d,series.shape[0])\n",
"\n",
" w_=np.cumsum(abs(w))\n",
" w_/=w_[-1]\n",
" skip=w_[w_>thres].shape[0]\n",
"\n",
" df={}\n",
" for name in series.columns:\n",
" seriesF,df_=series[[name]].fillna(method='ffill').dropna(),pd.Series()\n",
" for iloc in range(skip,seriesF.shape[0]):\n",
" loc=seriesF.index[iloc]\n",
"\n",
" df_[loc]=np.dot(w[-(iloc+1):,:].T,seriesF.loc[:loc])[0,0]\n",
" df[name]=df_.copy(deep=True)\n",
" df=pd.concat(df,axis=1)\n",
" return df\n",
"\n",
"#Funcion para buscar el mejor d\n",
"def plotMinFFD(df):\n",
" from statsmodels.tsa.stattools import adfuller\n",
" import numpy.ma as ma\n",
" out=pd.DataFrame(columns=['adfStat','pVal','lags','nObs','95% conf','corr'])\n",
" for d in np.linspace(0,1,21):\n",
" df1=np.log(df[['Close']]).resample('1D').last() # Pasar a observaciones diarias\n",
" df2=fracDiff(df1,d,thres=.01)\n",
" corr = ma.corrcoef(ma.masked_invalid(df1.loc[df2.index,'Close']), ma.masked_invalid(df2['Close']))[0,1]\n",
" df2=adfuller(df2['Close'],maxlag=1,regression='c',autolag=None)\n",
" out.loc[d]=list(df2[:4])+[df2[4]['5%']]+[corr] # Aportar valores criticos\n",
" out[['adfStat','corr']].plot(secondary_y='adfStat')\n",
" plt.axhline(out['95% conf'].mean(),linewidth=1,color='r',linestyle='dotted')\n",
" plt.show()\n",
" return out\n",
"\n",
"#Obtiene los factores de tiempo para restar importancia a las observaciones.\n",
"def getTimeDecay(tW,clfLastW):\n",
" clfW=tW.sort_index().cumsum()\n",
" if clfLastW>=0:slope=(1.-clfLastW)/clfW.iloc[-1]\n",
" else:slope=1./((clfLastW+1)*clfW.iloc[-1])\n",
" const=1.-slope*clfW.iloc[-1]\n",
" clfW=const+slope*clfW\n",
" clfW[clfW<0]=0\n",
" # print(const,slope)\n",
" return clfW"
]
},
{
"cell_type": "code",
"execution_count": 112,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
OpenHighLowCloseAdj CloseVolume
Date
2015-01-0110.0010.3710.0010.307.8302250.0
2015-02-0110.2610.2710.1510.227.7694070.0
2015-03-0110.2710.3810.1710.277.8074200.0
2015-04-0110.2510.259.9810.037.6249670.0
2015-05-0110.0910.4610.0810.467.9518600.0
.....................
2021-04-017.207.357.147.227.2200000.0
2021-05-017.297.837.297.497.4900000.0
2021-06-017.527.526.927.037.0300000.0
2021-07-017.047.106.947.047.0400000.0
2021-08-017.017.086.876.876.8700000.0
\n",
"

85 rows × 6 columns

\n",
"
"
],
"text/plain": [
" Open High Low Close Adj Close Volume\n",
"Date \n",
"2015-01-01 10.00 10.37 10.00 10.30 7.830225 0.0\n",
"2015-02-01 10.26 10.27 10.15 10.22 7.769407 0.0\n",
"2015-03-01 10.27 10.38 10.17 10.27 7.807420 0.0\n",
"2015-04-01 10.25 10.25 9.98 10.03 7.624967 0.0\n",
"2015-05-01 10.09 10.46 10.08 10.46 7.951860 0.0\n",
"... ... ... ... ... ... ...\n",
"2021-04-01 7.20 7.35 7.14 7.22 7.220000 0.0\n",
"2021-05-01 7.29 7.83 7.29 7.49 7.490000 0.0\n",
"2021-06-01 7.52 7.52 6.92 7.03 7.030000 0.0\n",
"2021-07-01 7.04 7.10 6.94 7.04 7.040000 0.0\n",
"2021-08-01 7.01 7.08 6.87 6.87 6.870000 0.0\n",
"\n",
"[85 rows x 6 columns]"
]
},
"execution_count": 112,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Part 1"
]
},
{
"cell_type": "code",
"execution_count": 113,
"metadata": {},
"outputs": [],
"source": [
"df['Log Adj Close'] = np.log(df['Adj Close'])"
]
},
{
"cell_type": "code",
"execution_count": 114,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
OpenHighLowCloseAdj CloseVolumeLog Adj Close
Date
2015-01-0110.0010.3710.0010.307.8302250.02.057991
2015-02-0110.2610.2710.1510.227.7694070.02.050194
2015-03-0110.2710.3810.1710.277.8074200.02.055075
2015-04-0110.2510.259.9810.037.6249670.02.031428
2015-05-0110.0910.4610.0810.467.9518600.02.073406
........................
2021-04-017.207.357.147.227.2200000.01.976855
2021-05-017.297.837.297.497.4900000.02.013569
2021-06-017.527.526.927.037.0300000.01.950187
2021-07-017.047.106.947.047.0400000.01.951608
2021-08-017.017.086.876.876.8700000.01.927164
\n",
"

85 rows × 7 columns

\n",
"
"
],
"text/plain": [
" Open High Low Close Adj Close Volume Log Adj Close\n",
"Date \n",
"2015-01-01 10.00 10.37 10.00 10.30 7.830225 0.0 2.057991\n",
"2015-02-01 10.26 10.27 10.15 10.22 7.769407 0.0 2.050194\n",
"2015-03-01 10.27 10.38 10.17 10.27 7.807420 0.0 2.055075\n",
"2015-04-01 10.25 10.25 9.98 10.03 7.624967 0.0 2.031428\n",
"2015-05-01 10.09 10.46 10.08 10.46 7.951860 0.0 2.073406\n",
"... ... ... ... ... ... ... ...\n",
"2021-04-01 7.20 7.35 7.14 7.22 7.220000 0.0 1.976855\n",
"2021-05-01 7.29 7.83 7.29 7.49 7.490000 0.0 2.013569\n",
"2021-06-01 7.52 7.52 6.92 7.03 7.030000 0.0 1.950187\n",
"2021-07-01 7.04 7.10 6.94 7.04 7.040000 0.0 1.951608\n",
"2021-08-01 7.01 7.08 6.87 6.87 6.870000 0.0 1.927164\n",
"\n",
"[85 rows x 7 columns]"
]
},
"execution_count": 114,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 115,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Coef. Std.Err. t P>|t| [0.025 0.975]\n",
"Intercept 0.00766 0.00625 1.22583 0.22420 -0.00479 0.02011\n",
"SMB -0.17574 0.19016 -0.92419 0.35843 -0.55474 0.20325\n",
"HML 0.21055 0.17078 1.23291 0.22157 -0.12981 0.55092\n",
"RMW -0.30751 0.28350 -1.08469 0.28163 -0.87251 0.25750\n",
"CMA -0.24563 0.28701 -0.85582 0.39490 -0.81764 0.32638\n",
"RF -0.10404 0.06324 -1.64528 0.10421 -0.23007 0.02199\n"
]
}
],
"source": [
"mdl_1 = smf.ols(formula = \"QMNIX ~ SMB + HML + RMW + CMA + RF \", data = merge)\n",
"print(np.round(mdl_1.fit().summary2().tables[1], 5))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The Goldfeld–Quandt Test"
]
},
{
"cell_type": "code",
"execution_count": 116,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0 1\n",
"0 F statistic 6.281711e+00\n",
"1 p-value 7.590857e-07\n"
]
}
],
"source": [
"import statsmodels.stats.diagnostic as sm_diagnostic\n",
"from statsmodels.compat import lzip\n",
"#\n",
"GQ_t = sm_diagnostic.het_goldfeldquandt(y = mdl_1.endog, x = mdl_1.exog, alternative = \"two-sided\", idx = 1)\n",
"print(pd.DataFrame(lzip(['F statistic', 'p-value'], GQ_t)))"
]
},
{
"cell_type": "code",
"execution_count": 117,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0 1\n",
"0 F statistic 7.028974e+00\n",
"1 p-value 1.861549e-07\n"
]
}
],
"source": [
"GQ_t = sm_diagnostic.het_goldfeldquandt(y = mdl_1.endog, x = mdl_1.exog, alternative = \"two-sided\")\n",
"print(pd.DataFrame(lzip(['F statistic', 'p-value'], GQ_t)))"
]
},
{
"cell_type": "code",
"execution_count": 118,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0 1\n",
"0 F statistic 0.932824\n",
"1 p-value 0.840336\n"
]
}
],
"source": [
"GQ_t = sm_diagnostic.het_goldfeldquandt(y = mdl_1.endog, x = mdl_1.exog, alternative = \"two-sided\", idx = 2)\n",
"print(pd.DataFrame(lzip(['F statistic', 'p-value'], GQ_t)))"
]
},
{
"cell_type": "code",
"execution_count": 119,
"metadata": {},
"outputs": [],
"source": [
"#Breusch–Pagan Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 120,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0 1\n",
"0 LM statistic 10.291051\n",
"1 p-value 0.067396\n",
"2 F-value 2.186751\n",
"3 F: p-value 0.064816\n"
]
}
],
"source": [
"BP_t = sm_diagnostic.het_breuschpagan(resid = mdl_1.fit().resid, exog_het = mdl_1.exog)\n",
"print(pd.DataFrame(lzip(['LM statistic', 'p-value', 'F-value', 'F: p-value'], BP_t)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Question 2"
]
},
{
"cell_type": "code",
"execution_count": 121,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"