| Overall Statistics |
|
Total Trades 15 Average Win 2.48% Average Loss -2.55% Compounding Annual Return 1.563% Drawdown 7.800% Expectancy 0.128 Net Profit 1.567% Sharpe Ratio 0.228 Loss Rate 43% Win Rate 57% Profit-Loss Ratio 0.97 Alpha -0.011 Beta 1.494 Annual Standard Deviation 0.084 Annual Variance 0.007 Information Ratio -0.012 Tracking Error 0.084 Treynor Ratio 0.013 Total Fees $62.79 |
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data.Market import *
from QuantConnect.Data.Consolidators import *
from datetime import timedelta
### <summary>
### Demonstration of how to initialize and use the RenkoConsolidator
### </summary>
### <meta name="tag" content="renko" />
### <meta name="tag" content="indicators" />
### <meta name="tag" content="using data" />
### <meta name="tag" content="consolidating data" />
class RenkoConsolidatorAlgorithm(QCAlgorithm):
'''Demonstration of how to initialize and use the RenkoConsolidator'''
def Initialize(self):
self.SetStartDate(2012, 1, 1)
self.SetEndDate(2013, 1, 1)
self.AddEquity("SPY", Resolution.Daily)
# this is the simple constructor that will perform the
# renko logic to the Value property of the data it receives.
# break SPY into $2.5 renko bricks and send that data to our 'OnRenkoBar' method
renkoClose = RenkoConsolidator(2.5)
self.Debug(renkoClose.OutputType)
self._sma = SimpleMovingAverage(10)
self.RegisterIndicator("SPY", self._sma, renkoClose)
renkoClose.DataConsolidated += self.HandleRenkoClose
self.SubscriptionManager.AddConsolidator("SPY", renkoClose)
# this is the full constructor that can accept a value selector and a volume selector
# this allows us to perform the renko logic on values other than Close, even computed values!
# break SPY into (2*o + h + l + 3*c)/7
renko7bar = RenkoConsolidator(2.5, lambda x: (2 * x.Open + x.High + x.Low + 3 * x.Close) / 7, lambda x: x.Volume)
renko7bar.DataConsolidated += self.HandleRenko7Bar
self.SubscriptionManager.AddConsolidator("SPY", renko7bar)
# We're doing our analysis in the OnRenkoBar method, but the framework verifies that this method exists, so we define it.
def OnData(self, data):
pass
def HandleRenkoClose(self, sender, data):
'''This function is called by our renkoClose consolidator defined in Initialize()
Args:
data: The new renko bar produced by the consolidator'''
if not self._sma.IsReady:
return
else:
self.Debug(self._sma.Current)
if not self.Portfolio.Invested:
self.SetHoldings(data.Symbol, 1)
self.Log(f"CLOSE - {data.Time} - {data.Open} {data.Close}")
def HandleRenko7Bar(self, sender, data):
'''This function is called by our renko7bar consolidator defined in Initialize()
Args:
data: The new renko bar produced by the consolidator'''
if self.Portfolio.Invested:
self.Liquidate(data.Symbol)
self.Log(f"7BAR - {data.Time} - {data.Open} {data.Close}")