How benchmark vectors establish the "master calendar" for perfect alignment
Date | spytr |
---|---|
2024-01-01 | 0.012 |
2024-01-02 | -0.008 |
... | ... |
2024-01-08 | 0.007 |
2024-01-09 | 0.021 |
2024-01-10 | -0.005 |
... | ... |
2024-01-22 | 0.011 |
📅 15 total dates, need last 10 for lookback
Date | gvkey | tr |
---|---|---|
2024-01-08 | 001001 | 0.015 |
2024-01-08 | 001002 | 0.009 |
2024-01-08 | 001003 | 0.021 |
2024-01-08 | 001004 | 0.031 |
2024-01-08 | 001005 | 0.041 |
... | ... | ... |
🔍 Thousands of rows, 5 stocks in example
gvkey | wgt |
---|---|
001001 | 0.40 |
001002 | 0.35 |
001003 | 0.25 |
⚡ Only 3 stocks selected from data_tr
Input: data_bench, rebal_date=2024-01-22, lookback_days=10
lookback_dates = last 10 trading days before 2024-01-22
Index | Date | SPY Return |
---|---|---|
[0] | 2024-01-08 | 0.007 |
[1] | 2024-01-09 | 0.021 |
[2] | 2024-01-10 | -0.005 |
[3] | 2024-01-11 | 0.009 |
[4] | 2024-01-12 | 0.018 |
[5] | 2024-01-16 | -0.003 |
[6] | 2024-01-17 | 0.014 |
[7] | 2024-01-18 | -0.009 |
[8] | 2024-01-19 | 0.006 |
[9] | 2024-01-22 | 0.011 |
✨ Output:
RetBM_vector = [0.007, 0.021, -0.005, 0.009, 0.018, -0.003, 0.014, -0.009, 0.006, 0.011]
lookback_dates = ['2024-01-08', '2024-01-09', ..., '2024-01-22']
Input: data_tr, baseline, required_dates (from vector!)
1. Filter universe: baseline selects only 3 stocks from 5 available
2. Initialize matrix: (10 dates × 3 stocks) filled with zeros
3. Fill column by column using EXACT same dates:
Date | 001001 (AAPL) | 001002 (MSFT) | 001003 (GOOGL) |
---|---|---|---|
2024-01-08 | 0.015 | 0.009 | 0.021 |
2024-01-09 | -0.012 | 0.018 | 0.005 |
2024-01-10 | 0.008 | -0.003 | 0.000 |
2024-01-11 | 0.022 | 0.014 | 0.017 |
2024-01-12 | -0.007 | 0.025 | -0.011 |
2024-01-16 | 0.011 | -0.008 | 0.009 |
2024-01-17 | 0.019 | 0.012 | 0.023 |
2024-01-18 | -0.004 | 0.007 | 0.000 |
2024-01-19 | 0.013 | -0.002 | 0.004 |
2024-01-22 | 0.006 | 0.016 | 0.012 |
🔴 Key Observations: