All problems
Holiday Dummy Regression
Problem
Fit a regression of returns on a holiday dummy with an intercept and return the dummy coefficient: sum((d - mean_d) * (r - mean_r)) / sum((d - mean_d)^2).
Return 0.0 if the lists are empty, differ in length, or the dummy has zero variance. The coefficient is the mean return difference between holiday and non-holiday periods.
Hint
With a balanced dummy this equals the difference of group means.
Test cases
case 1
in: [[0.01,0.02,0.03,0.04],[0,1,0,1]]
expected: 0.010000000000000002
case 2
in: [[0.05,0.06],[1,1]]
expected: 0
case 3
in: [[0.01,0.02,0.03],[0,0,0]]
expected: 0
case 4
in: [[0.02,-0.01,0.04,0.01],[1,0,1,0]]
expected: 0.030000000000000002
Starter codePython
def holiday_dummy_regression(returns, holiday_flags):
# Your code here
pass4 test cases · run your code against them in the editor