Merge PythonSlice into Slice (#8707)
- To simplify stub generation, merge PythonSlice into Slice, following existing pattern too, see QCAlgorithm.Python.cs - Minor sintax fixes in example python algorithms
This commit is contained in:
@@ -36,8 +36,8 @@ class ConsolidateHourBarsIntoDailyBarsRegressionAlgorithm(QCAlgorithm):
|
||||
# bars and the values of this one
|
||||
self._rsi_timedelta = RelativeStrengthIndex("Second", 15, MovingAverageType.WILDERS)
|
||||
self._values = {}
|
||||
self.count = 0;
|
||||
self._indicators_compared = False;
|
||||
self.count = 0
|
||||
self._indicators_compared = False
|
||||
|
||||
def on_data(self, data: Slice):
|
||||
if self.is_warming_up:
|
||||
|
||||
@@ -32,8 +32,8 @@ class ConsolidateRegressionAlgorithm(QCAlgorithm):
|
||||
self.start_date,
|
||||
self.end_date,
|
||||
self._future.exchange.time_zone,
|
||||
False)));
|
||||
self._expected_consolidation_counts = [];
|
||||
False)))
|
||||
self._expected_consolidation_counts = []
|
||||
|
||||
self.consolidate(symbol, Calendar.MONTHLY, lambda bar: self.update_monthly_consolidator(bar, -1)) # shouldn't consolidate
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class CustomDataUniverseRegressionAlgorithm(QCAlgorithm):
|
||||
self.set_end_date(2014, 3, 31)
|
||||
|
||||
self.current_underlying_symbols = set()
|
||||
self.universe_settings.resolution = Resolution.DAILY;
|
||||
self.universe_settings.resolution = Resolution.DAILY
|
||||
self.add_universe(CoarseFundamental, "custom-data-universe", self.selection)
|
||||
|
||||
self._selection_time = [datetime(2014, 3, 24), datetime(2014, 3, 25), datetime(2014, 3, 26),
|
||||
@@ -57,7 +57,7 @@ class CustomDataUniverseRegressionAlgorithm(QCAlgorithm):
|
||||
if len(custom_data) > 0:
|
||||
for symbol in sorted(self.current_underlying_symbols, key=lambda x: x.id.symbol):
|
||||
if not self.securities[symbol].has_data:
|
||||
continue;
|
||||
continue
|
||||
self.set_holdings(symbol, 1 / len(self.current_underlying_symbols))
|
||||
|
||||
if len([x for x in custom_data.keys() if x.underlying == symbol]) == 0:
|
||||
|
||||
@@ -24,7 +24,7 @@ class CustomDataUniverseScheduledRegressionAlgorithm(QCAlgorithm):
|
||||
|
||||
self.current_underlying_symbols = []
|
||||
self._selection_time = [datetime(2014, 3, 25), datetime(2014, 3, 27), datetime(2014, 3, 29)]
|
||||
self.universe_settings.resolution = Resolution.DAILY;
|
||||
self.universe_settings.resolution = Resolution.DAILY
|
||||
self.universe_settings.schedule.on(self.date_rules.on(self._selection_time))
|
||||
self.add_universe(CoarseFundamental, "custom-data-universe", self.universe_settings, self.selection)
|
||||
|
||||
|
||||
@@ -48,12 +48,12 @@ from requests import post
|
||||
class CustomSignalExport:
|
||||
def send(self, parameters: SignalExportTargetParameters) -> bool:
|
||||
targets = [PortfolioTarget.percent(parameters.algorithm, x.symbol, x.quantity)
|
||||
for x in parameters.targets] ;
|
||||
for x in parameters.targets]
|
||||
data = [ {'symbol' : x.symbol.value, 'quantity': x.quantity} for x in targets ]
|
||||
response = post("http://localhost:5000/", json = data)
|
||||
result = response.json()
|
||||
success = result.get('success', False)
|
||||
parameters.algorithm.log(f"Send #{len(parameters.targets)} targets. Success: {success}");
|
||||
parameters.algorithm.log(f"Send #{len(parameters.targets)} targets. Success: {success}")
|
||||
return success
|
||||
|
||||
def dispose(self):
|
||||
|
||||
@@ -47,7 +47,7 @@ class RangeIndicator(PythonIndicator):
|
||||
self.name = name
|
||||
self.time = datetime.min
|
||||
self.value = 0
|
||||
self.is_ready = False;
|
||||
self.is_ready = False
|
||||
|
||||
@property
|
||||
def is_ready(self):
|
||||
@@ -72,7 +72,7 @@ class RangeIndicator2(PythonIndicator):
|
||||
self.name = name
|
||||
self.time = datetime.min
|
||||
self.value = 0
|
||||
self._is_ready = False;
|
||||
self._is_ready = False
|
||||
|
||||
@property
|
||||
def is_ready(self):
|
||||
|
||||
@@ -31,7 +31,7 @@ class IndicatorHistoryAlgorithm(QCAlgorithm):
|
||||
# Let's keep BB values for a 20 day period
|
||||
self.bollinger_bands.window.size = 20
|
||||
# Also keep the same period of data for the middle band
|
||||
self.bollinger_bands.middle_band.window.size = 20;
|
||||
self.bollinger_bands.middle_band.window.size = 20
|
||||
|
||||
def on_data(self, slice: Slice):
|
||||
# Let's wait for our indicator to fully initialize and have a full window of history data
|
||||
|
||||
@@ -85,4 +85,4 @@ class OneTimeAlphaModel(AlphaModel):
|
||||
|
||||
@staticmethod
|
||||
def generate_insight_tag(symbol: Symbol) -> str:
|
||||
return f"Insight generated for {symbol}";
|
||||
return f"Insight generated for {symbol}"
|
||||
|
||||
@@ -78,4 +78,4 @@ class LongAndShortButterflyPutStrategiesAlgorithm(OptionStrategyFactoryMethodsBa
|
||||
|
||||
def liquidate_strategy(self) -> None:
|
||||
# We should be able to close the position using the inverse strategy (a short butterfly put)
|
||||
self.buy(self._short_butterfly_put, 2);
|
||||
self.buy(self._short_butterfly_put, 2)
|
||||
|
||||
@@ -22,7 +22,7 @@ class NoUniverseSelectorRegressionAlgorithm(QCAlgorithm):
|
||||
self.set_start_date(2014, 3, 24)
|
||||
self.set_end_date(2014, 3, 31)
|
||||
|
||||
self.universe_settings.resolution = Resolution.DAILY;
|
||||
self.universe_settings.resolution = Resolution.DAILY
|
||||
self.add_universe(CoarseFundamental)
|
||||
self.changes = None
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class NullBuyingPowerOptionBullCallSpreadAlgorithm(QCAlgorithm):
|
||||
self.set_cash(200000)
|
||||
|
||||
self.set_security_initializer(lambda security: security.set_margin_model(SecurityMarginModel.NULL))
|
||||
self.portfolio.set_positions(SecurityPositionGroupModel.NULL);
|
||||
self.portfolio.set_positions(SecurityPositionGroupModel.NULL)
|
||||
|
||||
equity = self.add_equity("GOOG")
|
||||
option = self.add_option(equity.symbol)
|
||||
|
||||
@@ -41,7 +41,7 @@ class OptionChainApisConsistencyRegressionAlgorithm(QCAlgorithm):
|
||||
|
||||
if len(option_chain_from_algorithm_api) != len(option_chain_from_provider_api):
|
||||
raise AssertionError(f"Expected {len(option_chain_from_provider_api)} options in chain from provider API, "
|
||||
f"but got {len(option_chain_from_algorithm_api)}");
|
||||
f"but got {len(option_chain_from_algorithm_api)}")
|
||||
|
||||
for i in range(len(option_chain_from_algorithm_api)):
|
||||
symbol1 = option_chain_from_algorithm_api[i]
|
||||
|
||||
@@ -30,8 +30,8 @@ class OptionChainConsistencyRegressionAlgorithm(QCAlgorithm):
|
||||
self.set_start_date(2015,12,24)
|
||||
self.set_end_date(2015,12,24)
|
||||
|
||||
self.equity = self.add_equity(self.underlying_ticker);
|
||||
self.option = self.add_option(self.underlying_ticker);
|
||||
self.equity = self.add_equity(self.underlying_ticker)
|
||||
self.option = self.add_option(self.underlying_ticker)
|
||||
|
||||
# set our strike/expiry filter for this option chain
|
||||
self.option.set_filter(self.universe_func)
|
||||
|
||||
@@ -24,11 +24,11 @@ class RangeConsolidatorAlgorithm(QCAlgorithm):
|
||||
return 100
|
||||
|
||||
def initialize(self) -> None:
|
||||
self.set_start_and_end_dates();
|
||||
self.set_start_and_end_dates()
|
||||
self.add_equity("SPY", self.get_resolution())
|
||||
range_consolidator = self.create_range_consolidator()
|
||||
range_consolidator.data_consolidated += self.on_data_consolidated
|
||||
self._first_data_consolidated = None;
|
||||
self._first_data_consolidated = None
|
||||
|
||||
self.subscription_manager.add_consolidator("SPY", range_consolidator)
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class ShortableProviderOrdersRejectedRegressionAlgorithm(QCAlgorithm):
|
||||
|
||||
response = order_ticket.update_quantity(-999) # should be allowed, we are reducing the quantity we want to short
|
||||
if not response.is_success:
|
||||
raise ValueError("Order update should of succeeded!");
|
||||
raise ValueError("Order update should of succeeded!")
|
||||
|
||||
self.initialized = True
|
||||
return
|
||||
|
||||
@@ -24,7 +24,7 @@ class StochasticIndicatorWarmsUpProperlyRegressionAlgorithm(QCAlgorithm):
|
||||
self.set_end_date(2020, 2, 1)
|
||||
self.set_cash(100000)
|
||||
|
||||
self.data_points_received = False;
|
||||
self.data_points_received = False
|
||||
self.spy = self.add_equity("SPY", Resolution.HOUR).symbol
|
||||
|
||||
self.daily_consolidator = TradeBarConsolidator(timedelta(days=1))
|
||||
|
||||
Reference in New Issue
Block a user