当前位置:网站首页>R language spline curve piecewise linear regression model piecewise regression estimation of individual stock beta value analysis of yield data

R language spline curve piecewise linear regression model piecewise regression estimation of individual stock beta value analysis of yield data

2022-06-12 00:05:00 Extension end tecdat

Link to the original text :http://tecdat.cn/?p=25675 

One   Stock _beta_ Value usually means its relationship with the market , When the market changes 1% when , What percentage change do we expect in the stock .

market , It's a somewhat vague concept , As usual , We use standard & Poor's 500 Approximate calculation of the index . The above relationship ( hereinafter referred to as β) It is detrimental to many aspects of trading and risk management . What has been determined is , Volatility has different dynamics for rising and falling markets . We have to use regression to estimate beta anyway , So for investors who want to fit this asymmetry , Piecewise linear regression is appropriate .

The idea is simple , We divide the data set into two ( Or more ) part , And separately 、 Block by block or  _ piecewise _ Estimate each part . This simple idea can be implemented with complex symbols and code .

To illustrate , I use Microsoft Stock market yield data (MSFT).

I have estimated different rates of return β value , The positive sun is above zero , The negative day is below zero , So zero is our breakthrough point .( This breakthrough is known in academic terms as " junction ", Why " junction " Well ? Because it connects the two parts .) The following figure shows the results .
 

getSymbols




for (i in 1:l){

dat0 = getSymbols

rt\[,i\] = dt\[,4\]/dt\[,1\] - 1

}

lal = lm

plot abline

Maybe β The value is always the same , Until the extreme negative value , Only when the market drops sharply , Relationships change . This belongs to the category of structural change . I think about the grid of points along the axis , And build a model , There is a breakpoint at each point , There is a slope before the breakpoint , There is a slope after the breakpoint . I find the minimum value of the sum of square errors of the whole sample , So I add the squared errors of the two models . The figure below shows the result .

plot(ret\[,1\]~ret\[,2\]
segments
grid1
grid2 

##  Note that there (ret\[,2\]<grid2\[i\]), It's an index function 


for (i in 1:length(gid2) ) {
rneg <-lm
rpos <-lm
d\[i\]<- summary
}
plot
text
points

Grid search on the optimal model

ok , The data is not zero , But almost zero , Bad luck , All this work , What do I ask you ? ok , In order to use the correct  _ Beta _ , All you have to do now is decide whether it is a bear market or a bull market ...... It should be easy . Thank you for reading , The code is as follows .

data display , Node is not zero , But almost zero , In order to use the correct β value , All you have to do now is decide , Is this a bear market or a bull market , Thank you for reading . 


The most popular insights

1.R Language based ARMA-GARCH-VaR Empirical research on model fitting and prediction

2.R Language time-varying parameters VAR Random models

3.R Language estimates vary with time VAR An empirical study of time series models

4.R Language based ARMA-GARCH Process of VAR Fitting and Forecasting

5.GARCH(1,1),MA And historical simulation VaR Compare

6.R Language uses vector autoregression (VAR) Impulse response to economic data

7.R Language to achieve automatic vector regression VAR Model

8.R Language random search variable selection SSVS Estimate Bayesian vector autoregression (BVAR) Model

9.R Language VAR Different types of impulse response analysis of models

原网站

版权声明
本文为[Extension end tecdat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011536338513.html