Overall Statistics |
Total Trades 198 Average Win 0.95% Average Loss -0.85% Compounding Annual Return -1.357% Drawdown 10.100% Expectancy -0.091 Net Profit -7.255% Sharpe Ratio -0.399 Probabilistic Sharpe Ratio 0.016% Loss Rate 57% Win Rate 43% Profit-Loss Ratio 1.12 Alpha -0.011 Beta 0.003 Annual Standard Deviation 0.027 Annual Variance 0.001 Information Ratio -0.921 Tracking Error 0.17 Treynor Ratio -4.278 Total Fees $792.62 Estimated Strategy Capacity $13000000.00 Lowest Capacity Asset IVE RV0PWMLXVHPH |
import pandas as pd class HyperActiveGreenHyena(QCAlgorithm): def Initialize(self): self.SetStartDate(2015, 12, 7) self.SetCash(100000) self.AddEquity("SPY", Resolution.Daily) self.value_symbol=self.AddEquity('IVE',Resolution.Daily).Symbol self.growth_symbol=self.AddEquity('IVW',Resolution.Daily).Symbol self.lookback=60 self.value_bb=self.BB(self.value_symbol,self.lookback,2) self.growth_bb=self.BB(self.growth_symbol,self.lookback,2) self.SetWarmUp(timedelta(self.lookback*2)) self.ratio_df=pd.DataFrame(columns=['value','growth','ratio']) def OnData(self, data): ''' OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Arguments: data: Slice object keyed by symbol containing the stock data ''' if (data.Bars.ContainsKey(self.value_symbol)) & (data.Bars.ContainsKey(self.growth_symbol)): new_df=pd.DataFrame({'value':data.Bars[self.value_symbol].Close, 'growth':data.Bars[self.growth_symbol].Close, 'ratio':data.Bars[self.value_symbol].Close/data.Bars[self.growth_symbol].Close}, index=[self.Time.date()]) self.ratio_df=pd.concat([self.ratio_df.loc[:,['value','growth','ratio']],new_df],axis=0) self.ratio_df['ma']=self.ratio_df['ratio'].rolling(self.lookback).mean() self.Log('last value number is {}'.format(self.ratio_df['value'][-1])) self.Log('last growth number is {}'.format(self.ratio_df['growth'][-1])) self.Log('last ratio is {}'.format(self.ratio_df['ratio'][-1])) self.Log('last ma is {}'.format(self.ratio_df['ma'][-1])) if (self.ratio_df['ratio'][-1])>(self.ratio_df['ma'][-1]): if not self.Portfolio.Invested: self.SetHoldings(self.value_symbol, 0.45) self.SetHoldings(self.growth_symbol, -0.45) elif (self.ratio_df['ratio'][-1])<(self.ratio_df['ma'][-1]): if self.Portfolio.Invested: self.Liquidate()