import numpy as np
import pandas as pd
from clr import AddReference

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data import *
from datetime import timedelta
from System.Collections.Generic import List
from QuantConnect.Data.UniverseSelection import *
class QualityMomentumModel(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2010, 1, 1) # Set Start Date
self.SetEndDate(2015, 1, 1)
self.SetCash(1000) # Set Strategy Cash
momentumlookbackdays = 126 #Momentum lookback
momentumskipdays = 10
overalllookback = 136
self.spy = self.AddEquity("SPY", Resolution.Minute) #add SPY to use for trends
#list of bond etfs for when markets down.
self.BONDS = ['TLT', 'IEF']
# Add bonds

self.stocks_to_hold = []
self.trend_up = 0
self.UniverseSettings.Resolution = Resolution.Minute #update the universe every minute
#adding a universe of stocks

#schedule function for making trades
self.Schedule.On(self.DateRules.MonthStart("SPY"), self.TimeRules.AfterMarketOpen("SPY", 30), Action(
self.Schedule.On(self.DateRules.MonthStart("SPY"), self.TimeRules.BeforeMarketClose("SPY", 30), Action(

#15 Day moving average of SPY
self.spy_ma_fast = self.SMA("SPY", 10)
#100 Day moving average of SPY
self.spy_ma_slow = self.SMA("SPY", 100)

if self.spy_ma_fast >= self.spy_ma_slow:
self.trend_up = 1

self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)

def CoarseSelectionFunction(self, coarse):
#drop any securities that dont have fundamental data and cost less than $5
selected = [x for x in coarse if (x.HasFundamentalData)
and (float(x.Price) > 5)]

filtered = sorted(selected, key=lambda x: x.DollarVolume, reverse=True)
return [x.Symbol for x in filtered[:2000]]

def FineSelectionFunction(self, fine):
#filter with fundamentals
self.quality = sorted(fine,
key = lambda f: f.OperationRatios.ROIC.SixMonths, reverse=True)

self.high_quality = sorted(self.quality,
key = lambda f: f.OperationRatios.LongTermDebtEquityRatio.OneYear + f.ValuationRatios.CashReturn + f.ValuationRatios.FCFYield, reverse=True)

self.momentum = sorted(self.high_quality,
key = lambda f: f.ValuationRatios.CashReturn.overalllookback - f.ValuationRatios.CashReturn.momentumlookbackdays, reverse=True)

self.TQ = [x.Symbol for x in self.momentum[:5]] #search for top 5 equities with the highest ROIC

return self.TopTQ[:5]#take the 5 with the highest ROIC

def OnData(self, data):

def trade(self):

self.stocks_to_hold = []
for i in self.TopTQ:

if self.trend_up == 1:
for i in self.Portfolio.Values:
if (i.Invested) and (i not in self.BONDS and self.stocks_to_hold):

for i in self.stocks_to_hold:
self.SetHoldings(i, 0.7)
for i in self.BONDS:
self.SetHoldings(i, 0.3)

In this algo, I want to use the difference in the returns for each equity to determine momentum. In self.momentum, I want to use custom lengths. But I get the error, 

'float' object has no attribute 'overalllookback'
at FineSelectionFunction in 75

Is there some way to set a custom length for fundamental factors, rather than "OneYear" or "SixMonths"?