| Overall Statistics |
|
Total Orders 11 Average Win 31.21% Average Loss 0% Compounding Annual Return 7.318% Drawdown 31.100% Expectancy 0 Start Equity 100000 End Equity 545010.48 Net Profit 445.010% Sharpe Ratio 0.32 Sortino Ratio 0.262 Probabilistic Sharpe Ratio 0.172% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.016 Beta 0.476 Annual Standard Deviation 0.111 Annual Variance 0.012 Information Ratio -0.039 Tracking Error 0.116 Treynor Ratio 0.075 Total Fees $93.78 Estimated Strategy Capacity $1700000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X Portfolio Turnover 0.13% |
from AlgorithmImports import *
from QuantConnect.DataSource import *
class FredAlternativeDataAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2000, 1, 1)
self.set_end_date(2023, 12, 31)
self.set_cash(100000)
self.spy = self.add_equity("SPY", Resolution.DAILY).symbol
# Requesting FED US peak-to-trough OECD recession indicators for trade signal generation
self.fred_peak_to_trough = self.add_data(Fred, Fred.OECDRecessionIndicators.UNITED_STATES_FROM_PEAK_THROUGH_THE_TROUGH, Resolution.DAILY).symbol
# Historical data
history = self.history(self.fred_peak_to_trough, 60, Resolution.DAILY)
self.debug(f"We got {len(history)} items from our history request")
def on_data(self, slice: Slice) -> None:
# Trade with updated FED peak-to-trough indicator
if slice.contains_key(self.fred_peak_to_trough) and slice.contains_key(self.spy):
peak_to_trough = slice.Get(Fred, self.fred_peak_to_trough).value
# Buy SPY if peak to trough value is 0, which is the expansionary period
if peak_to_trough == 0 and not self.portfolio.invested:
self.set_holdings(self.spy, 1)
# Liquidate holdings if peak to trough value is 1, which is recessionary period
elif peak_to_trough == 1 and self.portfolio.invested:
self.liquidate(self.spy)