Problem with accessing data after splitapply and regress

조회 수: 1 (최근 30일)
Luca
Luca 2021년 4월 15일
편집: Luca 2021년 4월 15일
Hi,
I have two stocks with daily stock returns and the marketreturns also daily. I ran a regression seperatly for each year and each stock with the splitapply() function. My goal is to get the residuals for each day of observation and stock. I uploaded the set I'm using.
Data description:
ID = Stock id
dates= the day of observation
years = the years (for group)
RET = stock returns
MRET = market returns
The model looks like this :
RET = Beta0 + Beta1 * MRET
I tried it with fitlm.
[group6, years, ID]= findgroups(subset1.years, subset1.ID);
[group7, dates]= findgroups(subset1.years);
[lm2] = splitapply(@(x,y){fitlm(x,y)}, subset1.MRET, subset1.RET,group6)
Which gives me 59*1 cell array where all the information are stored in. Unfortunatly this was a little bit a dead end for me. I don't know how to access the residuals all at ones and assgin them to the right date and ID.
I Also tried.
A = [ones(size(subset1.MRET)), subset1.MRET];
b = subset1.RET;
[m5] = splitapply(@(x,y) {regress(y,x)},A,b,group6);
But here i'm also not able to get the residuals. The output is again cell array where each cell contains the beta0 and beta1.
My new idea is to get a table which looks like this.
ID years Beta0 Beta1
10001 1986 b0 b1
10001 1987 b0 b1
.
.
.
10002 1986 b0 b1
.
.
.
Then I would be able to calculate the residuals my self.
Does anyone know how to get the residuals directly and create a table with ID, dates and residuals.
Or how I can create the table with the betas
Thank you in advance
Luca

답변 (0개)

카테고리

Help CenterFile Exchange에서 Financial Data에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by