Overall Statistics |
Total Trades 3 Average Win 12.22% Average Loss 0% Compounding Annual Return 729333.583% Drawdown 2.900% Expectancy 0 Net Profit 15.745% Sharpe Ratio 9.92 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 2.37 Beta 0.341 Annual Standard Deviation 0.549 Annual Variance 0.301 Information Ratio -4.776 Tracking Error 0.749 Treynor Ratio 15.978 Total Fees $0.30 |
//Copyright HardingSoftware.com, granted to the public domain. //Use entirely at your own risk. namespace QuantConnect.Algorithm.CSharp { public class M : QCAlgorithm { string ticker = "IMGN"; int holdCount= 5; int count=0; decimal lowerRatio=0.985m; decimal upperRatio=1.025m; OrderTicket orderTicket; decimal leverage=.999m; decimal increment=0.01m; public override void Initialize() { SetStartDate(2019, 7, 20); //Set Start Date // SetEndDate(2019, 8, 8); //Set End Date SetCash(8500); //Set Strategy Cash AddEquity(ticker, Resolution.Hour); SetBenchmark(ticker); Securities[ticker].FeeModel = new ConstantFeeModel(0.1m); } public override void OnData(Slice data) { count++; if (count<holdCount) { return; } count=0; if (data[ticker]==null || data.ContainsKey(ticker)==false) { return; } decimal price=data[ticker].Close; if (!Portfolio.Invested) { if (orderTicket!=null) { orderTicket.Cancel(); } //int quantity=(int)(leverage*Portfolio.Cash/price); int quantity=(int)(leverage*7000m/price); decimal buyPrice=FloorToIncrement(lowerRatio*price,increment); orderTicket = LimitOrder(ticker, quantity, buyPrice); } else { if (orderTicket!=null) { orderTicket.Cancel(); } int quantity=(int)Portfolio[ticker].Quantity; decimal sellPrice=CeilingToIncrement(upperRatio*price,increment); orderTicket = LimitOrder(ticker, -quantity, sellPrice); } } public decimal RoundToIncrement(decimal roundMe, decimal increment) { return (decimal)(Math.Round(roundMe/increment)*increment); } public decimal FloorToIncrement(decimal roundMe, decimal increment) { return (decimal)(Math.Floor(roundMe/increment)*increment); } public decimal CeilingToIncrement(decimal roundMe, decimal increment) { return (decimal)(Math.Ceiling(roundMe/increment)*increment); } } }