Skip to content

Commit

Permalink
Remove semicolon in python algrotihms
Browse files Browse the repository at this point in the history
  • Loading branch information
jingwu74 committed Jul 6, 2018
1 parent 889fd92 commit 084cd29
Show file tree
Hide file tree
Showing 28 changed files with 51 additions and 51 deletions.
6 changes: 3 additions & 3 deletions Algorithm.Framework/Alphas/MacdAlphaModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self,
self.resolution = resolution
self.insightPeriod = Time.Multiply(Extensions.ToTimeSpan(resolution), fastPeriod)
self.bounceThresholdPercent = 0.01
self.symbolData = {};
self.symbolData = {}

resolutionString = Extensions.GetEnumString(resolution, Resolution)
movingAverageTypeString = Extensions.GetEnumString(movingAverageType, MovingAverageType)
Expand Down Expand Up @@ -75,7 +75,7 @@ def Update(self, algorithm, data):

# ignore signal for same direction as previous signal
if direction == sd.PreviousDirection:
continue;
continue

insight = Insight.Price(sd.Security.Symbol, self.insightPeriod, direction)
sd.PreviousDirection = insight.Direction
Expand All @@ -97,7 +97,7 @@ def OnSecuritiesChanged(self, algorithm, changes):
data = self.symbolData.pop(removed.Symbol, None)
if data is not None:
# clean up our consolidator
algorithm.SubscriptionManager.RemoveConsolidator(removed.Symbol, data.Consolidator);
algorithm.SubscriptionManager.RemoveConsolidator(removed.Symbol, data.Consolidator)

class SymbolData:
def __init__(self, algorithm, security, fastPeriod, slowPeriod, signalPeriod, movingAverageType, resolution):
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.Framework/Alphas/PairsTradingAlphaModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def __init__(self, asset1, asset2, threshold = 1):
self.asset2Price = None
self.ratio = None
self.mean = None
self.upperThreshold = None;
self.lowerThreshold = None;
self.upperThreshold = None
self.lowerThreshold = None

self.Name = '{}({},{},{})'.format(self.__class__.__name__, asset1, asset2, Extensions.Normalize(threshold))

Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/BasicTemplateOptionsFrameworkAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def OnSecuritiesChanged(self, changes):

def SelectOptionChainSymbols(self, utcTime):
newYorkTime = Extensions.ConvertFromUtc(utcTime, TimeZones.NewYork)
ticker = "TWX" if newYorkTime.date() < date(2014, 6, 6) else "AAPL";
ticker = "TWX" if newYorkTime.date() < date(2014, 6, 6) else "AAPL"
return [ Symbol.Create(ticker, SecurityType.Option, Market.USA, f"?{ticker}") ]

class EarliestExpiringWeeklyAtTheMoneyPutOptionUniverseSelectionModel(OptionUniverseSelectionModel):
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/BubbleAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def OnData(self, data):
# Cape Ratio is missing from orignial data
# Most recent cape data is most likely to be missing
elif self._currCape == 0:
self.Debug("Exiting due to no CAPE!");
self.Debug("Exiting due to no CAPE!")
self.Quit("CAPE ratio not supplied in data, exiting.")

except:
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/CoarseFineFundamentalComboAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def OnData(self, data):
for security in self._changes.AddedSecurities:
self.SetHoldings(security.Symbol, 0.2)

self._changes = None;
self._changes = None


# this event fires whenever we have changes to our universe
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/CoarseFundamentalTop5Algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def OnData(self, data):
for security in self._changes.AddedSecurities:
self.SetHoldings(security.Symbol, 0.2)

self._changes = None;
self._changes = None


# this event fires whenever we have changes to our universe
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.Python/CustomBenchmarkAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def Initialize(self):
# Find more symbols here: http://quantconnect.com/data
self.AddEquity("SPY", Resolution.Second)

self.SetBenchmark("SPY");
self.SetBenchmark("SPY")

def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
if not self.Portfolio.Invested:
self.SetHoldings("SPY", 1)
self.Debug("Purchased Stock");
self.Debug("Purchased Stock")
4 changes: 2 additions & 2 deletions Algorithm.Python/CustomChartingAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def OnData(self, slice):

if self.Time > self.resample:
self.resample = self.Time + self.resamplePeriod
self.Plot("Average Cross", "FastMA", self.fastMA);
self.Plot("Average Cross", "SlowMA", self.slowMA);
self.Plot("Average Cross", "FastMA", self.fastMA)
self.Plot("Average Cross", "SlowMA", self.slowMA)

# On the 5th days when not invested buy:
if not self.Portfolio.Invested and self.Time.day % 13 == 0:
Expand Down
8 changes: 4 additions & 4 deletions Algorithm.Python/CustomDataNIFTYAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ def OnData(self, data):
class Nifty(PythonData):
'''NIFTY Custom Data Class'''
def GetSource(self, config, date, isLiveMode):
return SubscriptionDataSource("https://www.dropbox.com/s/rsmg44jr6wexn2h/CNXNIFTY.csv?dl=1", SubscriptionTransportMedium.RemoteFile);
return SubscriptionDataSource("https://www.dropbox.com/s/rsmg44jr6wexn2h/CNXNIFTY.csv?dl=1", SubscriptionTransportMedium.RemoteFile)


def Reader(self, config, line, date, isLiveMode):
if not (line.strip() and line[0].isdigit()): return None

# New Nifty object
index = Nifty();
index = Nifty()
index.Symbol = config.Symbol

try:
Expand Down Expand Up @@ -122,7 +122,7 @@ def Reader(self, config, line, date, isLiveMode):
if not (line.strip() and line[0].isdigit()): return None

# New USDINR object
currency = DollarRupee();
currency = DollarRupee()
currency.Symbol = config.Symbol

try:
Expand All @@ -135,7 +135,7 @@ def Reader(self, config, line, date, isLiveMode):
# Do nothing
return None

return currency;
return currency


class CorrelationPair:
Expand Down
8 changes: 4 additions & 4 deletions Algorithm.Python/CustomDataRegressionAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class Bitcoin(PythonData):

def GetSource(self, config, date, isLiveMode):
if isLiveMode:
return SubscriptionDataSource("https://www.bitstamp.net/api/ticker/", SubscriptionTransportMedium.Rest);
return SubscriptionDataSource("https://www.bitstamp.net/api/ticker/", SubscriptionTransportMedium.Rest)

#return "http://my-ftp-server.com/futures-data-" + date.ToString("Ymd") + ".zip";
#return "http://my-ftp-server.com/futures-data-" + date.ToString("Ymd") + ".zip"
# OR simply return a fixed small data file. Large files will slow down your backtest
return SubscriptionDataSource("https://www.quandl.com/api/v3/datasets/BCHARTS/BITSTAMPUSD.csv?order=asc", SubscriptionTransportMedium.RemoteFile);
return SubscriptionDataSource("https://www.quandl.com/api/v3/datasets/BCHARTS/BITSTAMPUSD.csv?order=asc", SubscriptionTransportMedium.RemoteFile)


def Reader(self, config, line, date, isLiveMode):
Expand Down Expand Up @@ -108,7 +108,7 @@ def Reader(self, config, line, date, isLiveMode):
coin["VolumeBTC"] = float(data[5])
coin["VolumeUSD"] = float(data[6])
coin["WeightedPrice"] = float(data[7])
return coin;
return coin

except ValueError:
# Do nothing, possible error in json decoding
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/CustomDataUniverseAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CustomDataUniverseAlgorithm(QCAlgorithm):
def Initialize(self):

# Data ADDED via universe selection is added with Daily resolution.
self.UniverseSettings.Resolution = Resolution.Daily;
self.UniverseSettings.Resolution = Resolution.Daily

self.SetStartDate(2015,1,5)
self.SetEndDate(2015,7,1)
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/DelistingEventsAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def OnData(self, data):

# the slice can also contain delisting data: data.Delistings in a dictionary string->Delisting

aaa = self.Securities["AAA"];
aaa = self.Securities["AAA"]
if aaa.IsDelisted and aaa.IsTradable:
raise Exception("Delisted security must NOT be tradable")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DropboxBaseDataUniverseSelectionAlgorithm(QCAlgorithm):

def Initialize(self):

self.UniverseSettings.Resolution = Resolution.Daily;
self.UniverseSettings.Resolution = Resolution.Daily

self.SetStartDate(2013,1,1)
self.SetEndDate(2013,12,31)
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/DropboxUniverseSelectionAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def Initialize(self):
self.backtestSymbolsPerDay = {}
self.current_universe = []

self.UniverseSettings.Resolution = Resolution.Daily;
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse("my-dropbox-universe", self.selector)

def selector(self, date):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def Initialize(self):
self.SetEndDate(2015,1,1)
self.SetCash(100000)

fastPeriod = 100;
slowPeriod = 300;
count = 10;
fastPeriod = 100
slowPeriod = 300
count = 10

self.UniverseSettings.Leverage = 2.0
self.UniverseSettings.Resolution = Resolution.Daily
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/FractionalQuantityRegressionAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def Initialize(self):

### The default buying power model for the Crypto security type is now CashBuyingPowerModel.
### Since this test algorithm uses leverage we need to set a buying power model with margin.
security.BuyingPowerModel = SecurityMarginModel(3.3);
security.BuyingPowerModel = SecurityMarginModel(3.3)

con = QuoteBarConsolidator(timedelta(1))
self.SubscriptionManager.AddConsolidator("BTCUSD", con)
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.Python/HistoryAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ def Initialize(self):
# we can also access the return value from the multiple symbol functions to request a single
# symbol and then loop over it
singleSymbolQuandl = allQuandlData.loc["CHRIS/CME_SP1"]
self.AssertHistoryCount("allQuandlData.loc[\"CHRIS/CME_SP1\"]", singleSymbolQuandl, 250);
self.AssertHistoryCount("allQuandlData.loc[\"CHRIS/CME_SP1\"]", singleSymbolQuandl, 250)
for quandl in singleSymbolQuandl:
# do something with 'CHRIS/CME_SP1' quandl data
pass

quandlSpyLows = allQuandlData.loc["CHRIS/CME_SP1"]["low"]
self.AssertHistoryCount("allQuandlData.loc[\"CHRIS/CME_SP1\"][\"low\"]", quandlSpyLows, 250);
self.AssertHistoryCount("allQuandlData.loc[\"CHRIS/CME_SP1\"][\"low\"]", quandlSpyLows, 250)
for low in quandlSpyLows:
# do something with 'CHRIS/CME_SP1' quandl data
pass
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/MACDTrendAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def OnData(self, data):
if self.__previous.date() == self.Time.date(): return

# define a small tolerance on our checks to avoid bouncing
tolerance = 0.0025;
tolerance = 0.0025

holdings = self.Portfolio["SPY"].Quantity

Expand Down
6 changes: 3 additions & 3 deletions Algorithm.Python/MovingAverageCrossAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def Initialize(self):
self.AddEquity("SPY")

# create a 15 day exponential moving average
self.fast = self.EMA("SPY", 15, Resolution.Daily);
self.fast = self.EMA("SPY", 15, Resolution.Daily)

# create a 30 day exponential moving average
self.slow = self.EMA("SPY", 30, Resolution.Daily);
self.slow = self.EMA("SPY", 30, Resolution.Daily)

self.previous = None

Expand All @@ -68,7 +68,7 @@ def OnData(self, data):
return

# define a small tolerance on our checks to avoid bouncing
tolerance = 0.00015;
tolerance = 0.00015

holdings = self.Portfolio["SPY"].Quantity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def OnData(self, slice):
x.Right == OptionRight.Call, chain)

# sorted the contracts by their strikes, find the second strike under market price
sorted_contracts = sorted(contracts, key = lambda x: x.Strike, reverse = True)[:2];
sorted_contracts = sorted(contracts, key = lambda x: x.Strike, reverse = True)[:2]

if sorted_contracts:
self.MarketOrder(sorted_contracts[0].Symbol, 1)
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.Python/OrderTicketDemoAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def MarketOnCloseOrders(self):
qty = self.Portfolio[self.spy.Value].Quantity
qty = 100 if qty == 0 else 2*qty

newTicket = self.MarketOnCloseOrder(self.spy, qty);
newTicket = self.MarketOnCloseOrder(self.spy, qty)
self.__openMarketOnCloseOrders.append(newTicket)

if len(self.__openMarketOnCloseOrders) == 1 and self.Time.minute == 59:
Expand Down Expand Up @@ -346,7 +346,7 @@ def CheckPairOrdersForFills(self, longOrder, shortOrder):
longOrder.Cancel("Short filled")
return True

return False;
return False


def TimeIs(self, day, hour, minute):
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.Python/QCUWeatherBasedRebalancing.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class Weather(PythonData):

def GetSource(self, config, date, isLive):
source = "https://dl.dropboxusercontent.com/u/44311500/KNYC.csv"
source = "https://www.wunderground.com/history/airport/{0}/{1}/1/1/CustomHistory.html?dayend=31&monthend=12&yearend={1}&format=1".format(config.Symbol, date.year);
return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile);
source = "https://www.wunderground.com/history/airport/{0}/{1}/1/1/CustomHistory.html?dayend=31&monthend=12&yearend={1}&format=1".format(config.Symbol, date.year)
return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile)


def Reader(self, config, line, date, isLive):
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.Python/QuandlFuturesDataAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def Initialize(self):
''' Initialize the data and resolution you require for your strategy '''
self.SetStartDate(2000, 1, 1)
self.SetEndDate(datetime.now().date() - timedelta(1))
self.SetCash(25000);
self.SetCash(25000)

# Symbol corresponding to the quandl code
self.crude = "SCF/CME_CL1_ON"
Expand All @@ -49,7 +49,7 @@ def OnData(self, data):
'''Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.'''
if self.Portfolio.HoldStock: return

self.SetHoldings(self.crude, 1);
self.SetHoldings(self.crude, 1)
self.Debug(str(self.Time) + str(" Purchased Crude Oil: ") + self.crude)


Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/QuandlImporterAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class QuandlImporterAlgorithm(QCAlgorithm):

def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
self.quandlCode = "SSE/YHO";
self.quandlCode = "SSE/YHO"
Quandl.SetAuthCode("JjAt5_5Ggmmoe5zUKipm")
self.SetStartDate(2014,4,1) #Set Start Date
self.SetEndDate(datetime.today() - timedelta(1)) #Set End Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ def OnSecuritiesChanged(self, changes):
weekday = self.Time.weekday()

if weekday == 0:
self.ExpectAdditions(changes, 'SPY', 'NZDUSD');
self.ExpectAdditions(changes, 'SPY', 'NZDUSD')
if weekday not in self.seenDays:
self.seenDays.append(weekday)
self.ExpectRemovals(changes, None)
else:
self.ExpectRemovals(changes, 'EURUSD', 'IBM')

if weekday == 1:
self.ExpectAdditions(changes, 'EURUSD');
self.ExpectAdditions(changes, 'EURUSD')
if weekday not in self.seenDays:
self.seenDays.append(weekday)
self.ExpectRemovals(changes, 'NZDUSD')
Expand All @@ -115,12 +115,12 @@ def ExpectAdditions(self, changes, *tickers):

for ticker in tickers:
if ticker is not None and ticker not in [s.Symbol.Value for s in changes.AddedSecurities]:
raise Exception("{}: Expected {} to be added: {}".format(self.Time, ticker, self.Time.weekday()));
raise Exception("{}: Expected {} to be added: {}".format(self.Time, ticker, self.Time.weekday()))

def ExpectRemovals(self, changes, *tickers):
if tickers is None and changes.RemovedSecurities.Count > 0:
raise Exception("{}: Expected no removals: {}".format(self.Time, self.Time.weekday()))

for ticker in tickers:
if ticker is not None and ticker not in [s.Symbol.Value for s in changes.RemovedSecurities]:
raise Exception("{}: Expected {} to be removed: {}".format(self.Time, ticker, self.Time.weekday()));
raise Exception("{}: Expected {} to be removed: {}".format(self.Time, ticker, self.Time.weekday()))
2 changes: 1 addition & 1 deletion Algorithm.Python/TimeInForceAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def Initialize(self):
# The default time in force setting for all orders is GoodTilCancelled (GTC),
# uncomment this line to set a different time in force.
# We currently only support GTC and DAY.
# self.DefaultOrderProperties.TimeInForce = TimeInForce.Day;
# self.DefaultOrderProperties.TimeInForce = TimeInForce.Day

self.symbol = self.AddEquity("SPY", Resolution.Minute).Symbol

Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/UniverseSelectionDefinitionsAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def OnData(self, data):
if not security.Invested:
self.MarketOrder(security.Symbol, 10)

self.changes = None;
self.changes = None


# this event fires whenever we have changes to our universe
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.Python/UpdateOrderRegressionAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def OnData(self, data):

if self.Time.month != self.last_month:
# we'll submit the next type of order from the queue
orderType = self.order_types_queue.Dequeue();
#Log("");
orderType = self.order_types_queue.Dequeue()
#Log("")
self.Log("\r\n--------------MONTH: {0}:: {1}\r\n".format(self.Time.strftime("%B"), orderType))
#Log("")
self.last_month = self.Time.month
Expand Down

0 comments on commit 084cd29

Please sign in to comment.