Overall Statistics |
Total Trades 127 Average Win 8.31% Average Loss -1.95% Compounding Annual Return 10.200% Drawdown 25.000% Expectancy 0.923 Net Profit 248.613% Sharpe Ratio 0.648 Loss Rate 63% Win Rate 37% Profit-Loss Ratio 4.27 Alpha 0.053 Beta 0.461 Annual Standard Deviation 0.137 Annual Variance 0.019 Information Ratio 0.07 Tracking Error 0.145 Treynor Ratio 0.193 Total Fees $137.15 |
namespace QuantConnect { public class BasicTemplateAlgorithm : QCAlgorithm { public string symbol = "SPY"; SimpleMovingAverage Slow; RollingWindow<bool> Cross; public override void Initialize() { SetStartDate(2005, 1, 1); SetEndDate(DateTime.Now); SetCash(10000); AddSecurity(SecurityType.Equity, symbol, Resolution.Daily); Slow = SMA(symbol, 100); Cross = new RollingWindow<bool>(5); } public void OnData(TradeBars data) { if (!Slow.IsReady) return; var currentPrice = data[symbol].Price; var cross = currentPrice > Slow; Cross.Add(cross); if(!Cross.IsReady) return; if(!Portfolio[symbol].IsLong && Cross[0] && !Cross[1]) { SetHoldings(symbol, 1.5m, false, "Long " + symbol); } if(!Portfolio[symbol].IsShort && !Cross[0] && Cross[1]) { SetHoldings(symbol, 0, false, "Short " + symbol); } } } }