Overall Statistics |
Total Orders 8 Average Win 26.56% Average Loss -20.52% Compounding Annual Return -0.184% Drawdown 58.600% Expectancy 0.147 Start Equity 100000 End Equity 96948.01 Net Profit -3.052% Sharpe Ratio -0.148 Sortino Ratio -0.09 Probabilistic Sharpe Ratio 0.000% Loss Rate 50% Win Rate 50% Profit-Loss Ratio 1.29 Alpha -0.047 Beta 0.552 Annual Standard Deviation 0.109 Annual Variance 0.012 Information Ratio -0.735 Tracking Error 0.099 Treynor Ratio -0.029 Total Fees $35.47 Estimated Strategy Capacity $580000000.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(2003, 1, 1) self.set_end_date(2019, 10, 11) self.set_cash(100000) self.spy = self.add_equity("SPY", Resolution.DAILY).symbol # Requesting data 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: 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 1 if peak_to_trough == 1 and not self.portfolio.invested: self.set_holdings(self.spy, 1) # Liquidate holdings if peak to trough value is 0 elif peak_to_trough == 0 and self.portfolio.invested: self.liquidate(self.spy)