Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 10.584 Tracking Error 0.011 Treynor Ratio 0 Total Fees $0.00 |
import numpy as np import pandas as pd import math class DataConsolidationAlgorithm(QCAlgorithm): def Initialize(self): self.UniverseSettings.Resolution = Resolution.Daily self.SetCash(100000) self.SetStartDate(2015, 6, 1) self.SetEndDate(2015, 6, 2) self.AddUniverse(self.MyCoarseFilterFunction) #self.AddEquity("AAPL", Resolution.Minute).SetFeeModel(CustomFeeModel()) def OnData(self, data): self.df1 = pd.DataFrame(columns=['Symbol', 'Previous', 'Current', 'Return']) for elem in self.symbols: self.df = self.History(self.Symbol(elem), timedelta(2)) try: pr = self.df.iloc[1]['close'] cu = self.df.iloc[0]['close'] ret = cu/pr-1 except: pr = 0 cu = 0 ret = 0 self.df1 = self.df1.append({'Symbol': elem, 'Previous': pr, 'Current': cu, 'Return': ret}, ignore_index=True) self.df1['Return'] = pd.to_numeric(self.df1['Return']) self.df1 = self.df1.nsmallest(20, 'Return') #self.Debug(self.df1.to_string()) #self.Debug(str(self.Time)) self.Liquidate() for i in range(0,19): if self.df1.iloc[i]['Current'] != 0: alloc = math.floor((self.Portfolio.TotalPortfolioValue / 20) / self.df1.iloc[i]['Current']) #self.MarketOnCloseOrder(self.df1.iloc[i]['Symbol'], alloc) self.MarketOrder(self.df1.iloc[i]['Symbol'], alloc) pass def MyCoarseFilterFunction(self, coarse): sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True) filtered = [ x.Symbol for x in sortedByDollarVolume if x.Price > 10 and x.DollarVolume > 10000000 ] self.symbols = filtered[:500] return filtered[:500] #Create DeGiro Fee Model class CustomFeeModel(FeeModel): def GetOrderFee(self, parameters): # custom fee math fee = parameters.Security.Price * parameters.Order.AbsoluteQuantity * 0.0004 return OrderFee(CashAmount(fee, "USD")) # self.Liquidate()