Fill This Form To Receive Instant Help
Homework answers / question archive / Assignment 9 Weekly trading linear models Trend change Analysis of pi In this assignment, we will apply F-test to detect whether there is a (statistically) significant change in the pricing behavior of your stock within some time interval
Assignment 9
In this assignment, we will apply F-test to detect whether there is a (statistically) significant change in the pricing behavior of your stock within some time interval. F-tests are often used to test equivalence of models that have been fitted to data using the least squares (such as linear regression). Some examples include
We will focus on the last item. For each time period T (e.g. month), we want to check if there is a (statistically) significant change in pricing pattern for your stock.
We proceed as follows. Assume that the time period con- tains n days and let P1, . . . , Pn denote the (adjusted closing) prices for days i = 1, . . . , n. We construct a simple linear re- gression model for the price Pi = α · i + β. This model has two unknown parameters: slope α and intercept β. Therefore, for this model, the number of degrees of freedom d=2. In general, if we have a linear regression on m variables, we would need to compute m slope coefficients and intercept - in this case d = m + 1. Let SSE(T ) denote the sum of the squared resid- uals (”loss” function) for the regression line that ”fits” prices P1,...,Pn.
Next, we look for a day 1 < k < n where we suspect there is a change in linear trend. To find such a day, we divide our period T into two time periods: T1 containing days 1, . . . , k and T2 containing days k + 1, . . . , n. Within each period, we construct two regressions and compute the corresponding loss functions SSE(T1) and SSE(T2). We look for k that minimizes the total loss from using two regressions SSE(T1)+SSE(T2). Note that for each regression, the number of degrees of freedom is d1 = 2 and d2 = 2.
Once we computed our ”break” day candidate k, we construct the following F statistics. To simplify the notation, let us define L = SSE(T), L1 = SSE(T1) and L2 = SSE(T2). For a single line, we have parameters to estimate, namely slope and intercept. For a single model, we need d = 2 parameters and for the 2-segment model we need the d1 + d2 = 4 parameters where d1 = d(L1) = 2 and d2 = d(L2) = 2 parameters to estimate. If there are n data points, we compute the following F statistics:
Under the null hypethesis that two regression lines do not pro- vide a significantly better fit than one regression line, F will have an (Fisher) F -distribution with (2, n − 4) degrees of free- dom. The null hypethesis is rejected if the F is greater than some critical value (e.g. 0.05)
In Python you can compute the F -distribution as follows
from scipy.stats import f as fisher_f
p_value = fisher_f.cdf(f_statistics , 2, n-4)
Questions:
Questions:
Please download the answer file using this link
https://drive.google.com/file/d/1B9KdVjMnts--GZdo2oE2Ez0Jtr-6GbJi/view?usp=sharing