pep8 conversions of python algos, #6 (#7944)

* pep8 conversions

* Address review. Fix PythonIndicator

* Minor CSharp algo fix

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
This commit is contained in:
Louis Szeto
2024-04-19 02:15:18 +08:00
committed by GitHub
parent 1cae47ab25
commit 5eb236834f
35 changed files with 758 additions and 746 deletions
+23 -23
View File
@@ -22,41 +22,41 @@ from AlgorithmImports import *
### <meta name="tag" content="dividend event" />
class DividendAlgorithm(QCAlgorithm):
def Initialize(self):
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.SetStartDate(1998,1,1) #Set Start Date
self.SetEndDate(2006,1,21) #Set End Date
self.SetCash(100000) #Set Strategy Cash
self.set_start_date(1998,1,1) #Set Start Date
self.set_end_date(2006,1,21) #Set End Date
self.set_cash(100000) #Set Strategy Cash
# Find more symbols here: http://quantconnect.com/data
equity = self.AddEquity("MSFT", Resolution.Daily)
equity.SetDataNormalizationMode(DataNormalizationMode.Raw)
equity = self.add_equity("MSFT", Resolution.DAILY)
equity.set_data_normalization_mode(DataNormalizationMode.RAW)
# this will use the Tradier Brokerage open order split behavior
# forward split will modify open order to maintain order value
# reverse split open orders will be cancelled
self.SetBrokerageModel(BrokerageName.TradierBrokerage)
self.set_brokerage_model(BrokerageName.TRADIER_BROKERAGE)
def OnData(self, data):
def on_data(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
bar = data["MSFT"]
if self.Transactions.OrdersCount == 0:
self.SetHoldings("MSFT", .5)
if self.transactions.orders_count == 0:
self.set_holdings("MSFT", .5)
# place some orders that won't fill, when the split comes in they'll get modified to reflect the split
quantity = self.CalculateOrderQuantity("MSFT", .25)
self.Debug(f"Purchased Stock: {bar.Price}")
self.StopMarketOrder("MSFT", -quantity, bar.Low/2)
self.LimitOrder("MSFT", -quantity, bar.High*2)
quantity = self.calculate_order_quantity("MSFT", .25)
self.debug(f"Purchased Stock: {bar.price}")
self.stop_market_order("MSFT", -quantity, bar.low/2)
self.limit_order("MSFT", -quantity, bar.high*2)
if data.Dividends.ContainsKey("MSFT"):
dividend = data.Dividends["MSFT"]
self.Log(f"{self.Time} >> DIVIDEND >> {dividend.Symbol} - {dividend.Distribution} - {self.Portfolio.Cash} - {self.Portfolio['MSFT'].Price}")
if data.dividends.contains_key("MSFT"):
dividend = data.dividends["MSFT"]
self.log(f"{self.time} >> DIVIDEND >> {dividend.symbol} - {dividend.distribution} - {self.portfolio.cash} - {self.portfolio['MSFT'].price}")
if data.Splits.ContainsKey("MSFT"):
split = data.Splits["MSFT"]
self.Log(f"{self.Time} >> SPLIT >> {split.Symbol} - {split.SplitFactor} - {self.Portfolio.Cash} - {self.Portfolio['MSFT'].Price}")
if data.splits.contains_key("MSFT"):
split = data.splits["MSFT"]
self.log(f"{self.time} >> SPLIT >> {split.symbol} - {split.split_factor} - {self.portfolio.cash} - {self.portfolio['MSFT'].price}")
def OnOrderEvent(self, orderEvent):
def on_order_event(self, order_event):
# orders get adjusted based on split events to maintain order value
order = self.Transactions.GetOrderById(orderEvent.OrderId)
self.Log(f"{self.Time} >> ORDER >> {order}")
order = self.transactions.get_order_by_id(order_event.order_id)
self.log(f"{self.time} >> ORDER >> {order}")