Overall Statistics |
Total Trades 1318 Average Win 1.43% Average Loss -0.53% Compounding Annual Return 254.732% Drawdown 12.000% Expectancy 0.388 Net Profit 254.732% Sharpe Ratio 3.041 Loss Rate 63% Win Rate 37% Profit-Loss Ratio 2.70 Alpha 1.104 Beta -0.055 Annual Standard Deviation 0.362 Annual Variance 0.131 Information Ratio 2.658 Tracking Error 0.383 Treynor Ratio -19.998 Total Fees $5341.73 |
//Copyright Warren Harding 2016. //Granted to the public domain. //Use entirely at your own risk. //Custom algorithm development: warrencharding@yahoo.com. //Do not remove this copyright notice. using System; using System.Collections.Generic; using QuantConnect.Data.Market; using QuantConnect.Orders; using QuantConnect.Orders.Fees; using QuantConnect.Orders.Fills; using QuantConnect.Orders.Slippage; using QuantConnect.Securities; namespace QuantConnect { public class Algo3 : QCAlgorithm { int MompPeriod = 30; decimal momentumCutoff = -10; decimal ratioOfLastMinuteForMaxTrade =0.05m; TradeBars lastData = null; int quantity = 0; TradeBar lastBar = null; decimal minimumPurchase = 500m; Dictionary<string,MomentumPercent> moms=new Dictionary<string,MomentumPercent>(); public override void Initialize() { //Start and End Date range for the backtest: //SetStartDate(2015, 1, 1); //SetEndDate(DateTime.Now.Date.AddDays(-1)); SetStartDate(2016, 1, 1); SetEndDate(2017, 1, 1); SetCash(10000); //volatile etf's // string tickersString="QQQ,SQQQ,TQQQ,UVXY,XIV,NUGT,DUST,JNUG,JDUST,LABU,LABD,GUSH,DRIP,TVIX,GASL,GASX,DWTI,UWTI,DGAZ,UGAZ,UBIO,ZBIO,BRZU,RUSS,SCO,UCO,RUSL,ERY,ERX,BIOL,SVXY,VXX,SILJ,BIB,BIS,VIXY,SOXL,VIIX,SOXS,BZQ,USLV,SLVP,DSLV,GDXJ,GLDX"; string tickersString="QQQ,SQQQ,TQQQ,UVXY,XIV,NUGT,DUST,JNUG,JDUST,LABU,LABD,GUSH,DRIP,TVIX,GASL,GASX,DWTI,UWTI,DGAZ,UGAZ,UBIO,ZBIO,BRZU,RUSS,SCO,UCO,RUSL,ERY,ERX,BIOL,SVXY,VXX,SILJ,BIB,BIS,VIXY,SOXL,VIIX,SOXS,BZQ,USLV,SLVP,DSLV,GDXJ,GLDX,VIXM,VXZ,XIVH,LSVX,BSWN,VMAX,VIIZ,ZIV,VMIN,IVOP,XXV,VXN,VXO,VXD,RVX,VXST,VXV,VXMT,VXEFA,VXEEM,VXFXI,VXEWZ"; //string tickersString="QQQ,SQQQ,TQQQ"; //gold //string tickersString="NUGT,DUST,JNUG,JDUST"; //68 biggest companies ranked by market cap. //string tickersString="AAPL,GOOGL,GOOG,MSFT,XOM,BRK.A,BRK.B,FB,AMZN,JNJ,GE,WFC,T,NSRGY,CHL,JPM,RHHBY,PG,RDS.B,RDS.A,WMT,VZ,PFE,BUD,KO,BABA,CVX,TCEHY,SPY,NVS,V,DIS,HD,ORCL,TM,SSNLF,PM,MRK,BAC,PEP,CMCSA,NVO,INTC,IBM,CSCO,C,PTR,HSBC,UNH,MO,TSM,BMY,GILD,AMGN,TOT,SLB,RLNIY,MCD,MDT,CVS,MA,SNY,GSK,BTI,BP,LRLCY,MMM,IDEXY"; string[] tickers = tickersString.Split(new string[1] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (string ticker in tickers) { AddSecurity(SecurityType.Equity,ticker,Resolution.Minute); } foreach (Security s in Securities.Values) { s.FeeModel=new CustomFeeModel(); moms.Add(s.Symbol,MOMP(s.Symbol,MompPeriod)); } } public void OnData(TradeBars data) { decimal maxTrade; if (lastData != null) { foreach (TradeBar bar in data.Values) { if (Portfolio.Cash < minimumPurchase) { break; } if (!Portfolio[bar.Symbol].HoldStock) { if (lastData.ContainsKey(bar.Symbol)) { maxTrade = bar.Close * bar.Volume / ratioOfLastMinuteForMaxTrade; quantity =(int)Math.Floor(Math.Min(Portfolio.Cash, maxTrade) / bar.Close); lastBar = lastData[bar.Symbol]; if (quantity * bar.Close > minimumPurchase & quantity > 0) { if (moms[bar.Symbol] < momentumCutoff & bar.Close>lastBar.Close) { Order(bar.Symbol, quantity); } } } } } TradeBar bar2; foreach (SecurityHolding stock in Portfolio.Values) { if (Portfolio[stock.Symbol].Quantity > 0 & lastData.ContainsKey(stock.Symbol) & Portfolio.ContainsKey(stock.Symbol) & data.ContainsKey(stock.Symbol)) { lastBar = lastData[stock.Symbol]; bar2 = data[stock.Symbol]; if (bar2.Close < lastBar.Close) { Order(stock.Symbol, -Portfolio[stock.Symbol].Quantity); } } } } lastData = data; } } public class CustomFeeModel : IFeeModel { public decimal GetOrderFee(Security security, Order order) { var fee = order.AbsoluteQuantity*0.01m; if (fee<5) { fee=5; } if (fee>10) { fee=10; } return fee/2m; } } }