Question 1135297: Let's directly calculate the 95% confidence intervals of our parameters. The formula for a given parameter is:
πΆπΌ=(π½βπ§β
π πβ―β―β,π½+π§β
π πβ―β―β)
Where, π½ is the coefficient, π§ is the critical value(t-statistic required to obtain a probability less than the alpha significance level), and ππΈπ,π is the Standard Error Matrix.
start = '2014-01-01'
end = '2015-01-01'
asset = get_pricing('KO', fields='price', start_date=start, end_date=end)
benchmark = get_pricing('PEP', fields='price', start_date=start, end_date=end)
X = asset.pct_change()[1:]
Y = benchmark.pct_change()[1:]
result = sm.OLS(Y,X).fit()
# Convert X to Matrix (adding columns of one)
X = np.vstack((X, np.ones( X.size ) ))
X = np.matrix( X )
# Matrix Multiplication and inverse calculation
C = np.linalg.inv( X * X.T )
C *= result.mse_resid
SE = np.sqrt(C) # Calucaltion of Standart Error.
# Critical Values of the t-statistic
N = result.nobs
P = result.df_model
dof = N - P - 1
z = scipy.stats.t(dof).ppf(0.975)
i = 0
## Your code goes here
# Fetch values of Beta and parameters of SE from the matrix
beta = ## Your code goes here
c = ## Your code goes here
print ## Your code goes here
## Instead of running the code above and calculate the CI step by step,
## you can get the CI automatically from OLS table.
Answer by ikleyn(53937) (Show Source):
You can put this solution on YOUR website! .
Nonsense.
Not an appropriate post/problem/request for this forum.
Do not spend your time for nothing posting such requests - they make no sense.
Have a nice day / afternoon / evening / night / morning etc.
|
|
|