| Overall Statistics |
|
Total Trades 5 Average Win 7.96% Average Loss -11.27% Compounding Annual Return -1.575% Drawdown 38.400% Expectancy -0.147 Net Profit -28.655% Sharpe Ratio -0.206 Probabilistic Sharpe Ratio 0.000% Loss Rate 50% Win Rate 50% Profit-Loss Ratio 0.71 Alpha 0 Beta -0.16 Annual Standard Deviation 0.047 Annual Variance 0.002 Information Ratio -0.385 Tracking Error 0.191 Treynor Ratio 0.061 Total Fees $12.33 Estimated Strategy Capacity $130000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
from AlgorithmImports import *
class USTreasuryDataAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2000, 3, 1)
self.SetEndDate(2021, 6, 1)
self.SetCash(100000)
self.spy_symbol = self.AddEquity("SPY", Resolution.Hour).Symbol
# Requesting data
self.yield_curve_symbol = self.AddData(USTreasuryYieldCurveRate, "USTYCR").Symbol
# Historical data
history = self.History(USTreasuryYieldCurveRate, self.yield_curve_symbol, 60, Resolution.Daily)
self.Debug(f"We got {len(history)} items from our history request")
self.last_inversion = datetime.min
def OnData(self, data):
if not data.ContainsKey(self.yield_curve_symbol):
return
rates = data[self.yield_curve_symbol]
# Check for null before using the values
if not (rates.TenYear is not None and rates.TwoYear is not None):
return
# Only advance if a year has gone by
if (self.Time - self.last_inversion < timedelta(days=365)):
return
# if there is a yield curve inversion after not having one for a year, short sell SPY for two years
if (not self.Portfolio.Invested and rates.TwoYear > rates.TenYear):
self.Debug(f"{self.Time} - Yield curve inversion! Shorting the market for two years")
self.SetHoldings(self.spy_symbol, -0.5)
self.last_inversion = self.Time
return
# If two years have passed, liquidate our position in SPY
if (self.Time - self.last_inversion >= timedelta(days=365 * 2)):
self.Liquidate(self.spy_symbol)