-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Reproduce the bug:
import numpy as np
import statsmodels.api as sm
from qlib.data._libs.rolling import rolling_rsquare, rolling_resi, rolling_slope, rolling_mean
from qlib.data._libs.expanding import expanding_rsquare, expanding_resi, expanding_slope, expanding_mean
x = np.random.randn(100)
print('test rolling')
# window size = 20
assert np.isclose(x[-20:].mean(), rolling_mean(x, 20)[-1])
model = sm.OLS(x[-20:], sm.add_constant(np.arange(20))).fit()
assert np.isclose(model.params[1], rolling_slope(x, 20)[-1])
assert np.isclose(model.resid[-1], rolling_resi(x, 20)[-1])
assert np.isclose(model.rsquared, rolling_rsquare(x, 20)[-1])
print('test expanding')
model = sm.OLS(x, sm.add_constant(np.arange(len(x)))).fit()
assert np.isclose(model.params[1], expanding_slope(x)[-1])
assert np.isclose(model.resid[-1], expanding_resi(x)[-1])
assert np.isclose(model.rsquared, expanding_rsquare(x)[-1]) # the bug one
print(expanding_rsquare(x)) # all nanIt can be fixed by changing this line
qlib/qlib/data/_libs/expanding.pyx
Line 120 in 9895106
| self.x2_sum += size |
self.x2_sum += size * sizeyou-n-g, cslwqxx and bxdd
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working