Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: chapter 15, regression, the calculation of return #9

Closed
js20181010 opened this issue Mar 2, 2021 · 4 comments
Closed

question: chapter 15, regression, the calculation of return #9

js20181010 opened this issue Mar 2, 2021 · 4 comments

Comments

@js20181010
Copy link

chapter 15, regression section, in the book, it is:
In [28]: data['strat_ols_1'] = data['pos_ols_1'] * data['returns']
In [29]: data['strat_ols_2'] = data['pos_ols_2'] * data['returns']

should we use shift(1) as same as in section "Vectorized Backtesting" (cell 15)?
In [28]: data['strat_ols_1'] = data['pos_ols_1'].shift(1) * data['returns']
In [29]: data['strat_ols_2'] = data['pos_ols_2'].shift(1) * data['returns']

(cell 15 is : In [15]: data['Strategy'] = data['Position'].shift(1) * data['Returns'] )

@yhilpisch
Copy link
Owner

No, a shift is not necessary in this instance since the regression is based on historical data (lags) only.

This is slightly different to the SMA example which uses the same day closing price to calculate the SMA and derive the signal.

@js20181010
Copy link
Author

js20181010 commented Mar 4, 2021

Thank you for your swift reply.
agree, the regression is based on lags only. <-- this is very clear.

my questionable point is the meaning of returns & subsequently the position
returns (label) is derived from EOD stock data. (my understanding it is a stock's close price) :
day n returns = log(day n close / day n-1 close)
day n returns is only available by end of the day.
the position (pos_ols_1) is derived from returns, it means pos_ols_1 is only available by end of the day as well.

 if using below for trading strategy return calculation with shift(1)
     data['strat_ols_1'] = data['pos_ols_1'].shift(1) * data['returns']
     it means: use position of "day n-1" to trade on "day n", then calculate "day n" strat_ols return
 
 however, if using below to calculate the strategy return for "day n", it seems its meaning is not clear:
     data['strat_ols_1'] = data['pos_ols_1'] * data['returns']

how about your thoughts?

@yhilpisch
Copy link
Owner

yhilpisch commented Mar 5, 2021 via email

@js20181010
Copy link
Author

js20181010 commented Mar 5, 2021

Thanks for your detail explanation.
It has cleared my doubt.

the prediction of day n is based on data of day n-1, n-2. --> the prediction for day n is available by end of day n-1.
so we could make trade decision for day n on "eve" of day n-1 according to this prediction.

thank you very much once more to clear my misunderstanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants