Overall Statistics |
Total Trades 74 Average Win 2.87% Average Loss -1.98% Compounding Annual Return -19.371% Drawdown 22.100% Expectancy -0.073 Net Profit -6.832% Sharpe Ratio -0.394 Loss Rate 62% Win Rate 38% Profit-Loss Ratio 1.45 Alpha -0.124 Beta -0.033 Annual Standard Deviation 0.32 Annual Variance 0.103 Information Ratio -0.51 Tracking Error 0.356 Treynor Ratio 3.873 Total Fees $74.00 |
namespace QuantConnect { using QuantConnect.Data.Market; using QuantConnect.Orders; using QuantConnect.Orders.Slippage; public class EstimatedSlippageModel : ISlippageModel { private double SlippageSpread { get; set; } public EstimatedSlippageModel(double slippageSpread) { this.SlippageSpread = slippageSpread; } /// <summary> /// Slippage Model. Return a decimal cash slippage approximation on the order. /// </summary> public decimal GetSlippageApproximation(QuantConnect.Securities.Security security, Order order) { var data = security.GetLastData() as BaseData; return Convert.ToDecimal((double)data.Value * this.SlippageSpread); } } }
namespace QuantConnect { using QuantConnect.Data.Market; using QuantConnect.Orders; using QuantConnect.Orders.Slippage; using QuantConnect.Securities; public class MySecurityTransactionModel : SecurityTransactionModel { private ISlippageModel SlippageModel { get; set; } public MySecurityTransactionModel(ISlippageModel slippageModel) { this.SlippageModel = slippageModel; } public override decimal GetSlippageApproximation(QuantConnect.Securities.Security security, Order order) { return this.SlippageModel.GetSlippageApproximation(security, order); } public override decimal GetOrderFee(QuantConnect.Securities.Security security, Order order) { return 1m; } } }
//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>(); Dictionary<string,decimal> tickerProfits = new Dictionary<string,decimal>(); // 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(2016, 5, 1); SetCash(30000); //volatile etf's //string tickersString="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="GASX"; //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); tickerProfits.Add(ticker, 0m); var averageSlippageSpread = 0.0083d; // Slippage percentage for GASX: http://www.etf.com/GASX this.Securities[ticker].Model = new MySecurityTransactionModel(new EstimatedSlippageModel(averageSlippageSpread)); } 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) { var beforeProfit = Portfolio.TotalProfit; Liquidate(stock.Symbol); var orderProfit = Portfolio.TotalProfit - beforeProfit; //Log(string.Format("Sold: {0}, Profit: {1}", stock.Symbol, orderProfit)); tickerProfits[stock.Symbol] += orderProfit; //Order(stock.Symbol, -Portfolio[stock.Symbol].Quantity); } } } } lastData = data; } public override void OnEndOfAlgorithm() { Console.WriteLine("TotalProfit: {0}", Portfolio.TotalProfit); foreach(var ticker in tickerProfits) { Log(string.Format("Ticker: {0}, Total Profit: {1:n2}", ticker.Key, ticker.Value)); } } } 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; } } }