| Overall Statistics |
|
Total Orders 1477 Average Win 0.56% Average Loss -0.90% Compounding Annual Return -13.246% Drawdown 56.300% Expectancy -0.035 Start Equity 100000 End Equity 49108.91 Net Profit -50.891% Sharpe Ratio -0.596 Sortino Ratio -0.464 Probabilistic Sharpe Ratio 0.003% Loss Rate 41% Win Rate 59% Profit-Loss Ratio 0.62 Alpha -0.097 Beta -0.099 Annual Standard Deviation 0.177 Annual Variance 0.031 Information Ratio -0.742 Tracking Error 0.261 Treynor Ratio 1.07 Total Fees $881.61 Estimated Strategy Capacity $0 Lowest Capacity Asset SOXS UKTSIYPJHFMT Portfolio Turnover 1.42% |
using QuantConnect;
using QuantConnect.Algorithm;
using QuantConnect.Data;
using QuantConnect.Indicators;
using QuantConnect.Orders;
using System;
using System.Collections.Generic;
using System.Linq;
namespace QuantConnect.Algorithm.CSharp
{
public class SummrFlagshipModel : QCAlgorithm
{
private Dictionary<string, RelativeStrengthIndex> _rsiIndicators;
private List<string> _symbols;
private DateTime _nextRebalanceTime;
public override void Initialize()
{
// Set backtest start and end date
SetStartDate(2020, 1, 1);
SetEndDate(2024, 12, 31);
// Set starting cash
SetCash(100000);
// Define symbols to trade
_symbols = new List<string> { "SPY", "BIL", "IBTK", "SHY", "SOXL", "SQQQ", "SBND", "HIBL", "TECL", "SOXS" };
// Add equity symbols and initialize RSI indicators
_rsiIndicators = new Dictionary<string, RelativeStrengthIndex>();
int rsiPeriod;
foreach (var symbol in _symbols)
{
AddEquity(symbol, Resolution.Daily);
// Set RSI periods based on symbol
switch (symbol)
{
case "SPY":
rsiPeriod = 6;
break;
case "BIL":
rsiPeriod = 5;
break;
case "IBTK":
rsiPeriod = 7;
break;
case "SBND":
rsiPeriod = 10;
break;
case "HIBL":
rsiPeriod = 10;
break;
default:
rsiPeriod = 7; // Default period
break;
}
_rsiIndicators[symbol] = RSI(symbol, rsiPeriod, MovingAverageType.Wilders, Resolution.Daily);
}
// Initialize rebalance time to 30 minutes after market open
//_nextRebalanceTime = DateTime.MinValue;
// Schedule rebalance 30 minutes after market open
Schedule.On(DateRules.EveryDay(), TimeRules.AfterMarketOpen("SPY", 30), () =>
{
Rebalance();
});
}
public void Rebalance()
{
// Ensure RSI indicators are ready
if (!_rsiIndicators.All(x => x.Value.IsReady)) return;
// Retrieve RSI values
var rsiSPY = _rsiIndicators["SPY"].Current.Value;
var rsiBIL = _rsiIndicators["BIL"].Current.Value;
var rsiIBTK = _rsiIndicators["IBTK"].Current.Value;
var rsiSBND = _rsiIndicators["SBND"].Current.Value;
var rsiHIBL = _rsiIndicators["HIBL"].Current.Value;
// Implement strategy logic
if (rsiBIL < rsiIBTK)
{
if (rsiSPY > 75)
{
// Allocate to SHY (bonds)
SetHoldings("SHY", 1.0);
}
else
{
// Allocate to SOXL (bullish semiconductors)
SetHoldings("SOXL", 1.0);
}
}
else
{
if (rsiSBND < rsiHIBL)
{
// Allocate to SOXS (bearish semiconductors) or SQQQ (short QQQ)
SetHoldings("SOXS", 0.5);
SetHoldings("SQQQ", 0.5);
}
else
{
// Allocate to SOXL (bullish semiconductors) or TECL (bullish tech)
SetHoldings("SOXL", 0.5);
SetHoldings("TECL", 0.5);
}
}
}
}
}