Overall Statistics |
Total Trades 727 Average Win 0.49% Average Loss -0.26% Compounding Annual Return 4.340% Drawdown 6.200% Expectancy 0.060 Net Profit 5.821% Sharpe Ratio 0.468 Loss Rate 63% Win Rate 37% Profit-Loss Ratio 1.89 Alpha 0.031 Beta 0.008 Annual Standard Deviation 0.068 Annual Variance 0.005 Information Ratio -0.412 Tracking Error 0.118 Treynor Ratio 4.13 Total Fees $1454.00 |
using QuantConnect.Data.Consolidators; using QuantConnect.Data.Market; namespace QuantConnect.Algorithm.Examples { public class RenkoConsolidatorAlgorithm : QCAlgorithm { RollingWindow<decimal> _price = new RollingWindow<decimal>(2); RollingWindow<decimal> _L0 = new RollingWindow<decimal>(2); RollingWindow<decimal> _L1 = new RollingWindow<decimal>(2); RollingWindow<decimal> _L2 = new RollingWindow<decimal>(2); RollingWindow<decimal> _L3 = new RollingWindow<decimal>(2); RollingWindow<decimal> _l = new RollingWindow<decimal>(2); decimal L0; decimal L1; decimal L2; decimal L3; SimpleMovingAverage _sma; StandardDeviation _sd; string _symbol = "EURUSD"; decimal prevClose; DateTime lastTradeTime; decimal _delta; decimal _laguerre; //parameters decimal _gamma = 0.07m; int period = 50; public override void Initialize() { SetStartDate(2014, 01, 01); SetEndDate(2015, 05, 01); SetCash(25000); //add securities AddSecurity(SecurityType.Forex, _symbol, Resolution.Minute, true, 50, true); // break SPY into $2.5 renko bricks and send that data to our 'OnRenkoBar' method var renkoClose = new RenkoConsolidator(0.002m); renkoClose.DataConsolidated += (sender, consolidated) => { // call our event handler for renko data HandleRenkoClose(consolidated); }; // register the consolidator for updates SubscriptionManager.AddConsolidator(_symbol, renkoClose); _sma = new SimpleMovingAverage(period); _sd = new StandardDeviation(period); } // OnData public void OnData(TradeBars data) { } // OnData public void HandleRenkoClose(RenkoBar data) { _price.Add((data.High + data.Low)/2m); if(!_price.IsReady) return; //Lagerre calculations _L0.Add(L0); if(!_L0.IsReady) return; L0 = (1.0m - _gamma)*_price[0] + _gamma*_L0[1]; //if(_L0.Count < 2) return; _L1.Add(L1); if(!_L1.IsReady) return; L1 = -_gamma*L0 + _L0[1] + _gamma*_L1[1]; _L2.Add(L2); if (!_L2.IsReady) return; L2 = -_gamma*L1 + _L1[1] + _gamma*_L2[1]; _L3.Add(L3); if (!_L3.IsReady) return; L3 = -_gamma*L2 + _L2[1] + _gamma*_L3[1]; decimal CU = 0; decimal CD = 0; if (_L0[0] >= _L1[0]) { CU = _L0[0] - _L1[0]; } else { CD = _L1[0] - _L0[0]; } if (_L1[0] >= _L2[0]) { CU = CU + _L1[0] - _L2[0]; } else { CD = CD + _L2[0] - _L1[0]; } if(_L2[0] >= _L3[0]) { CU = CU + _L2[0] - _L3[0]; } else { CD = CD + _L3[0] - _L2[0]; } if((CU + CD) != 0) { _laguerre = (_L0[0] + 2 * _L1[0] + 2 * _L2[0] + _L3[0]) / 6m; } _l.Add(_laguerre); if(!_l.IsReady) return; Plot("Indicators", "Laguerre", _laguerre*1000); Plot("Indicators", "Price", _price[0]*1000); //_sma.Update(data.Time, (data.Close-prevClose)); //_sd.Update(data.Time, (data.Close-prevClose)); //exits if(_l[0] != 0) { //if(Portfolio[symbol].Invested && (data.Time-lastTradeTime).TotalDays > 1) if(Portfolio[_symbol].IsLong && _price[0] < _l[0]) { Liquidate(); } if(Portfolio[_symbol].IsShort && _price[0] > _l[0]) { Liquidate(); } //entries if(!Portfolio[_symbol].Invested && _price[0] > _l[0]) { SetHoldings(data.Symbol, 1); lastTradeTime = data.Time; } if(!Portfolio[_symbol].Invested && _price[0] < _l[0]) { SetHoldings(data.Symbol, -1); lastTradeTime = data.Time; } } //System.Console.WriteLine("CLOSE - {0} - {1} {2}", data.Time.ToString("o"), data.Open, data.Close); //prevClose = data.Close; } /// <summary> /// This function is called by our renko7bar onsolidator defined in Initialize() /// </summary> /// <param name="data">The new renko bar produced by the consolidator</param> public void HandleRenko7Bar(RenkoBar data) { //System.Console.WriteLine("7BAR - {0} - {1} {2}", data.Time.ToString("o"), data.Open, data.Close); } } }