Overall Statistics
Total Orders
126
Average Win
1.03%
Average Loss
-1.13%
Compounding Annual Return
1.010%
Drawdown
20.400%
Expectancy
0.334
Start Equity
1000000
End Equity
1259293.31
Net Profit
25.929%
Sharpe Ratio
-0.443
Sortino Ratio
-0.122
Probabilistic Sharpe Ratio
0.000%
Loss Rate
30%
Win Rate
70%
Profit-Loss Ratio
0.91
Alpha
-0.021
Beta
0.063
Annual Standard Deviation
0.038
Annual Variance
0.001
Information Ratio
-0.548
Tracking Error
0.147
Treynor Ratio
-0.269
Total Fees
$7364.73
Estimated Strategy Capacity
$310000.00
Lowest Capacity Asset
ONEQ SSGXMYZDG6ZP
Portfolio Turnover
0.50%
Drawdown Recovery
2206
BRIEF = """
IMPLEMENTATION BRIEF - Jalbert, "Is There an April Effect in Stock Returns?" (SSRN 4843739)

WHAT THE PAPER FINDS
The paper is an event study, not a trading-strategy paper. It shows that daily log returns of nine stock indexes
(DJIA, SPX, DJT, DJU, NASDAQ Composite, DAX, Nikkei 225, HSI, CAC 40) are several times higher inside a 16-trading-day
"event window" around the US income-tax filing deadline (Tax-day) than outside it, 1965-2019. The author attributes
this to retirement-account (IRA) inflows before the April 15 deadline and suggests investors "increase their equity
holdings around tax-day to capture these higher returns".

IMPLIED STRATEGY (what I will build)
- Universe: a single US broad-market equity index ETF, SPY (S&P 500), standing in for the paper's SPX index series.
  No dynamic universe, no filters.
- Signal: purely calendar-based.
  Tax-day T(y) = April 15 of year y if the NYSE is open that day, otherwise the next NYSE trading day
  (the paper's rule: "If April 15th falls on a weekend or holiday, Tax-day equals the following trading day").
  Tax-day Relative counts NYSE trading days: -1 is the trading day before T, +1 the trading day after.
  Event window = Tax-day Relative in [-10, +5] (10 trading days before T, T itself, 5 trading days after T = 16 days).
- Portfolio construction: long-only, 100% of equity in SPY during the event window, 100% cash otherwise.
  The paper's daily return for day t is ln(L_t / L_{t-1}) x 100, i.e. close-to-close; so to earn exactly the
  window's 16 daily returns the position is opened AT THE CLOSE of trading day -11 and closed AT THE CLOSE of
  trading day +5.
- Execution: SPY subscribed at minute resolution. A scheduled event at before_market_close(SPY, 16) on every trading
  day checks the calendar: on day -11 it submits a market-on-close BUY sized with calculate_order_quantity(SPY, 1.0);
  on day +5 it submits a market-on-close SELL of the full position. All other days: no orders.
  Default QC fee/slippage/fill models.
- Rebalance timing / holding period: one round trip per year, 16 trading days held. No other trading.
- Estimation scheme: none - the paper's parameters (window -10..+5, deadline April 15) are fixed ex ante; there is
  no fitting, training or validation.
- Trading-day arithmetic: QC exchange-hours calendar (is_date_open, get_previous_trading_day, get_next_trading_day)
  on SPY's exchange. No hard-coded holiday lists or dates.

DATASETS
- US Equity Security Master + US Equities (QuantConnect Cloud), SPY, minute resolution, default ADJUSTED normalization.
  History starts 1998, fully covers the window.
- Starting cash: 1,000,000 USD (single position, weight 1.0 -> fees negligible).

BACKTEST WINDOW
- set_start_date(2021, 9, 1), set_end_date(2026, 9, 1). Covers five event windows: April 2022, 2023, 2024, 2025, 2026.
  No warm-up needed (calendar-only signal). The paper's own sample is 1965-2019 and it excluded 2020 and 2021 because
  the deadline moved (July 15 2020, May 17 2021); both are outside our window anyway.

DECISIONS
1. Tradable instrument. The paper studies index levels (nine indexes) and trades nothing. Chosen: SPY as the
   investable proxy for SPX (the paper's US broad-market index). Rejected: DIA (DJIA - the paper's headline row,
   but a 30-stock price-weighted index); an equal-weight basket of ETFs for all nine indexes (no ETF tracks DJU, DAX,
   Nikkei 225, HSI or CAC 40 exactly - MSCI country ETFs would be proxies I should not pick on my own); a basket of
   the five US indexes (same DJU problem). Client may switch the ticker or ask for a basket.
2. Tax-day definition. Paper: "Tax-day equals the due date for income tax returns, usually April 15th. If April 15th
   falls on a weekend or holiday, Tax-day equals the following trading day." Chosen: April 15 if the NYSE is open,
   else the next NYSE trading day (mechanical rule). The paper applied this mechanical rule itself: it lists 2017
   among years where DAX/CAC/HSI "did not trade on April 15" (Apr 15 2017 was a Saturday, Apr 17 Easter Monday), i.e.
   it used Apr 17 2017, not the IRS due date of Apr 18 2017. Rejected: the actual IRS due date, which since 2007 is
   also pushed by the Washington DC Emancipation Day holiday (Apr 16) - this differs from the mechanical rule in
   2023 (IRS Apr 18 vs mechanical Apr 17) and would need a hard-coded date list. In 2022 both give Apr 18
   (Apr 15 2022 was Good Friday); 2024, 2025, 2026 both give Apr 15.
3. Window edges and entry/exit timing. Paper: window = "the 10 trading days prior to the tax filing deadline, the
   tax filing deadline and the 5 trading days following", with returns defined close-to-close. Chosen: buy at the
   close of trading day -11 (market-on-close), sell at the close of trading day +5 (market-on-close), so the
   position earns exactly the 16 daily returns the paper measures. Rejected: buying at the open of day -10 (drops the
   overnight return from close -11 to open -10 which the paper counts) and selling at the open of day +6 (adds an
   overnight return the paper does not count).
4. Position size. The paper is silent (it only says "increase equity holdings"). Chosen: 100% long SPY in the
   window, 100% cash outside. Long-only, so the 1x-gross cap for long-short books does not apply. Rejected:
   leveraged exposure; a permanent index holding with an overweight in the window (that would be a market-holding
   strategy, not the April effect).
5. Cash outside the window. The paper is silent. Chosen: uninvested cash (QC default, no interest). Rejected: T-bill
   ETF parking - not in the paper.
6. Return convention. The paper uses log returns x 100 purely for its statistics; the traded strategy needs no
   return computation, so no choice is embedded in the code. The equity curve reflects simple compounded returns.
7. Sample adaptation. The paper's sample is 1965-2019; the backtest uses the standard five-year window 2021-09-01 to
   2026-09-01 (five April events). The method is unchanged.
8. Data resolution. The paper uses daily index levels. Chosen: minute-resolution SPY so that the market-on-close order
   can be submitted 16 minutes before the close (required by the platform for an official-close fill). The signal
   itself is date-based, so resolution does not change the method.

REQUESTS
NONE

CLIENT DECISIONS (approved brief with these changes - binding, do not reopen):
A. Instrument (Decision 1): equal-weight basket of DIA (DJIA), SPY (SPX), ONEQ (NASDAQ Composite) - one third each
   inside the window, cash outside. DJT, DJU and the four foreign indexes have no exact tracker: report as data gap,
   do not proxy.
B. Backtest window (Decision 7): longest window the three ETFs allow. Find first data date for DIA, SPY, ONEQ in the
   research notebook; start on the first date all three have data; end 2026-09-01.
C. Years 2020 and 2021: hold no position (deadline was July 15 2020 and May 17 2021, as the paper excludes them).
   State this in the final report.
D. Everything else approved: mechanical Tax-day rule, MOC entry day -11, MOC exit day +5.
"""
# region imports
from AlgorithmImports import *
# endregion


class AprilInflowsStrategy(QCAlgorithm):
    """
    Jalbert, "Is There an April Effect in Stock Returns?" (SSRN 4843739).
    Long an equal-weight basket of DIA, SPY and ONEQ during the 16-trading-day event window
    around the US income-tax filing deadline (Tax-day Relative -10 .. +5), cash otherwise.
    Tax-day = April 15, or the next NYSE trading day if April 15 is a weekend or holiday.
    Entry: market-on-close on trading day -11. Exit: market-on-close on trading day +5.
    2020 and 2021 are skipped (deadline was not in April), as in the paper.
    """

    def initialize(self) -> None:
        self.set_start_date(2003, 10, 1)
        self.set_end_date(2026, 9, 1)
        self.set_cash(1_000_000)

        self._symbols = [self.add_equity(t, Resolution.MINUTE).symbol for t in ["DIA", "SPY", "ONEQ"]]
        self._spy = self._symbols[1]
        self._weight = 1.0 / len(self._symbols)
        self._skip_years = {2020, 2021}

        self._window_year = None
        self._entry_date = None
        self._exit_date = None

        self.schedule.on(
            self.date_rules.every_day(self._spy),
            self.time_rules.before_market_close(self._spy, 16),
            self._before_close,
        )

    def _compute_window(self, year: int) -> None:
        self._window_year = year
        self._entry_date = None
        self._exit_date = None
        if year in self._skip_years:
            return
        hours = self.securities[self._spy].exchange.hours
        tax_day = datetime(year, 4, 15)
        if not hours.is_date_open(tax_day):
            tax_day = hours.get_next_trading_day(tax_day)
        entry = tax_day
        for _ in range(11):
            entry = hours.get_previous_trading_day(entry)
        exit_day = tax_day
        for _ in range(5):
            exit_day = hours.get_next_trading_day(exit_day)
        self._entry_date = entry.date()
        self._exit_date = exit_day.date()

    def _before_close(self) -> None:
        today = self.time.date()
        if self._window_year != today.year:
            self._compute_window(today.year)
        if today == self._entry_date:
            for symbol in self._symbols:
                qty = self.calculate_order_quantity(symbol, self._weight)
                if qty != 0:
                    self.market_on_close_order(symbol, qty)
        elif today == self._exit_date:
            for symbol in self._symbols:
                qty = self.portfolio[symbol].quantity
                if qty != 0:
                    self.market_on_close_order(symbol, -qty)
NOTES = """
PAPER: Jalbert, "Is There an April Effect in Stock Returns?" (University of Hawaii at Hilo), SSRN 4843739. 18 pages total.

p1 Abstract: examines whether retirement-account (IRA) inflows around the April 15 US tax-filing deadline affect
US equity prices. Posits higher average daily stock returns around April 15. Results: large, significant April effects,
event-window daily returns up to 8x daily returns for rest of year. Holds for US and international stock indexes.

p1-2 Intro: taxpayers may fund IRA until April 15 following tax year. 21.67% of taxpayers filed in the two weeks
including and prior to April 15 (2019). Author expects large flow of funds into retirement accounts immediately
preceding April 15, plus post-April-15 inflow due to investment delays. Hypothesis: abnormal positive daily returns
around April 15 deadline.

p2-3 History of tax-advantaged accounts (IRAs created 1974 ERISA; effective 1975). Contribution limits table (Table 2 appendix).
p3 Literature review begins: January effect (Rozeff & Kinney 1976), window dressing etc. No strategy details yet.

p4 Literature review continued (January effect, sell-in-May, day-of-week, holiday effect, turn-of-month). No method details.

p5 DATA AND METHODOLOGY:
- Data from Stooq.com: daily index levels. Nine indexes: DJIA, SPX (S&P 500), DJT (DJ Transportation), DJU (DJ Utilities),
  NASDAQ Composite, DAX, NIKKEI 225 (NKX), Hang Seng (HSI), CAC 40.
- International indexes: if no trading on April 15, the following trading day set equal to tax-day (HSI, DAX, CAC in
  1979,1990,1995,2001,2006,2017; HSI also 1973,1974). CAC 1974 dropped.
- Sample: 1965-2019 (7 of 9 indexes); HSI from 1970-01-02, CAC from 1969-01-02.
- Three sub-periods: 1965-2019 (Keogh), 1976-2019 (IRA), 1983-2019 (ERTA 1981 boost). Robustness: start date choice immaterial.
- Tax-day variable = due date for income tax returns, usually April 15. If April 15 falls on weekend or holiday,
  Tax-day = the FOLLOWING trading day. Tax-day Relative: Tax-day = 0; prior trading days -1, -2, ...; following +1, +2...
  (Counted in TRADING days: "If Tax-day equals April 15th, then April 14th Tax-day Relative equals -1 and April 13th equals -2".)
- Filing deadline was April 15 for 1955-2019. 2020 (July 15) and 2021 (May 17) EXCLUDED from study.
p6:
- WINDOW variable: expected response window of 16 days around Tax-day: Window = 1 for observations within the
  10 TRADING DAYS BEFORE Tax-day, Tax-day itself, and the FIVE DAYS AFTER Tax-day (Tax-day Relative -10..+5). Zero otherwise.
- Daily return DR_t = LN(L_t / L_{t-1}) x 100 (Eq. 1), log return in percent, from index levels.
- RESULTS section: compare event window (EW) vs outside window (OW) mean, SD, distributions. Means Ratio MR = MEW/MOW (Eq 2);
  SD ratio SDR = SDEW/SDOW (Eq 3). t-test and Wilcoxon tests.
- Table 4 (Appendix): 1965-2019 results. DJIA MEW 0.1140 vs MOW 0.0192, MR 5.9375, significant at 1%. SPX, DJT similar.

p7: DJU/NASDAQ MR 3.49 / 2.37 but not significant. DAX, HSI, CAC significant; CAC MR 8.18; NIKKEI MR 2.01 not significant.
  EW standard deviation generally LOWER than OW (DJIA SDR 0.9216). KS tests mixed. Tables 5, 6 = 1976-2019 and 1983-2019;
  effect declines in 1983-2019 (DJIA MR 3.48).
p7-8: OLS: DRET_t = alpha + beta1 * Window + eps (Eq 4). Table 7 Panels A/B/C for the three periods. Low R2.
p8 CONCLUDING COMMENTS: event window = the ten trading days prior to the tax-filing deadline, the tax filing deadline,
  and the five trading days following the deadline. "Investors might take advantage of these findings by increasing
  their equity holdings around tax-day to capture these higher returns. Passive investors may open their IRAs and invest
  the proceeds at least two weeks prior to April 15th... Institutional investors might increase equity holdings around
  the tax window." Limitations: single window of 16 days; indexes of large firms.
  NOTE: the paper is an event-study, NOT a trading-strategy paper: no explicit portfolio construction, position sizing,
  or execution rule is given. The implied strategy: be long the equity index during the 16-trading-day window
  (Tax-day Relative -10 .. +5), flat otherwise.
p8-9 REFERENCES (no method content).
p10-11 References continued (Stooq.com data retrieved May 12 2020). p12 Table 1: history of tax-advantaged accounts
  (1962 Keogh, 1974 ERISA/IRAs, 1978 401k, 1981 ERTA, 1986 TRA, 1996 SIMPLE, 1997 Roth, 2001 EGTRRA, 2006 PPA, 2019 FCAA).
  No method content.
p13-14 Table 2: IRA/401k/SIMPLE contribution limit history (no method content). Table 3: Indexes examined
  (DJIA, SPX, DJT, DJU, NASDAQ Composite - USA; DAX Germany; Nikkei 225 Japan; HSI Hong Kong; CAC 40 France).
p14-15 Table 4 (1965-2019): 880 event-window obs for 55 years -> 16 days/year confirms window = 16 trading days
  (-10..+5). Table note: "The window equals the 10 trading days prior to the tax filing deadline, the tax filing
  deadline and the 5 trading days following the tax filing deadline." Returns DRET = ln(L_t/L_{t-1}) x 100.
  SPX: MEW 0.0902, MOW 0.0220, MR 4.10, t -2.04**. DJIA MR 5.94***, DJT 5.82***, DJU 3.49 ns, NASDAQ 2.37 ns,
  DAX 5.53**, NIKKEI 2.01 ns, HSI 2.49 (Wilcoxon *), CAC 8.18***.
p16-18 Tables 5 (1976-2019), 6 (1983-2019), 7 (OLS on Window dummy, 3 panels). All table notes repeat:
  "The Window equals the 10 trading days before the tax filing deadline, the tax filing deadline day and the 5 trading
  days following the tax filing deadline." 704 EW obs over 44 yrs, 592 over 37 yrs -> 16 trading days per year.
  Nothing else new for the method. END OF PAPER (18 pages covered).

SUMMARY OF METHOD FOR IMPLEMENTATION:
- Asset: equity index (SPX is the paper's US broad-market index; DJIA is its headline index). Paper does not trade;
  implied strategy = long the index during the event window, flat otherwise.
- Event window: trading days with Tax-day Relative in [-10, +5], where Tax-day = April 15 or, if April 15 is a weekend
  or holiday, the next trading day. Window is 16 trading days. Return day t is in window if t in [-10,+5], meaning the
  position must be held from the CLOSE of day -11 to the CLOSE of day +5 to capture the daily returns of days -10..+5.
- 2020 and 2021 excluded in paper because deadline moved (Jul 15 2020, May 17 2021). Post-2021 deadlines back to
  April 15 (2022: Apr 18 due to Emancipation Day DC holiday; 2023: Apr 18; 2024: Apr 15; 2025: Apr 15; 2026: Apr 15).
  Paper's own rule: "Tax-day = due date for income tax returns, usually April 15"; weekend/holiday -> following trading day.
  NOTE: Emancipation Day (Apr 16, DC) is not an NYSE holiday, so paper's mechanical rule (April 15 or next NYSE
  trading day) gives 2022: Apr 18 (Apr 15 2022 was Good Friday, NYSE closed) ; 2023: Apr 17 (Apr 15 Saturday) vs actual
  IRS due date Apr 18 2023; 2024: Apr 15; 2025: Apr 15; 2026: Apr 15. Paper's sample (1965-2019) deadline was Apr 15
  every year, so the mechanical rule and the IRS date coincided within the paper's sample.
"""