From c2eccb3190aa3d306f9f07234e59ab28942daf59 Mon Sep 17 00:00:00 2001 From: Alexandre Catarino Date: Wed, 13 May 2026 16:24:31 +0100 Subject: [PATCH 1/2] Fix type annotations in Python project templates - Annotate `_fundamental: list[Symbol]` in the QuiverQuantCongress chained-universe template so mypy can infer the element type. - Use the pythonnet generic-indexer form `cache.get_data[TradeBar]()` in the custom-models template so the return type carries through. --- .../main.py | 2 +- project-templates/python/custom-models/main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project-templates/python/alternative-data-chain-universe-quiverquantcongressuniverse/main.py b/project-templates/python/alternative-data-chain-universe-quiverquantcongressuniverse/main.py index 0cf28b8786..ab8f41b25f 100644 --- a/project-templates/python/alternative-data-chain-universe-quiverquantcongressuniverse/main.py +++ b/project-templates/python/alternative-data-chain-universe-quiverquantcongressuniverse/main.py @@ -5,7 +5,7 @@ class QuiverQuantCongressChainedUniverseAlgorithm(QCAlgorithm): - _fundamental = [] + _fundamental: list[Symbol] = [] def initialize(self) -> None: self.set_start_date(2024, 9, 1) diff --git a/project-templates/python/custom-models/main.py b/project-templates/python/custom-models/main.py index 68a6fe1e54..9c06d16053 100644 --- a/project-templates/python/custom-models/main.py +++ b/project-templates/python/custom-models/main.py @@ -123,7 +123,7 @@ def _set_order_event_to_filled(self, fill: OrderEvent, fill_price: float, fill_q return fill def _get_trade_bar(self, asset: Security, order_direction: OrderDirection) -> TradeBar: - trade_bar = asset.cache.get_data(TradeBar) + trade_bar = asset.cache.get_data[TradeBar]() if trade_bar: return trade_bar # Tick-resolution data doesn't have TradeBar, use the asset price From 221e96ca95c1ec545e51d692daf68d7d467dd81e Mon Sep 17 00:00:00 2001 From: Alexandre Catarino Date: Wed, 13 May 2026 16:33:16 +0100 Subject: [PATCH 2/2] Add type annotations to ai template Annotate `_get_features_and_labels`, the inner `loss_mse`, and `on_data` so the file passes the strict-mypy syntax check. --- project-templates/python/ai/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/project-templates/python/ai/main.py b/project-templates/python/ai/main.py index 0e7a9cfe70..cfc4fe067e 100644 --- a/project-templates/python/ai/main.py +++ b/project-templates/python/ai/main.py @@ -39,7 +39,7 @@ def initialize(self) -> None: # Recalibrate the model weekly to ensure its accuracy on the updated domain. self.train(self.date_rules.week_start(), self.time_rules.at(8, 0), self._my_training_method) - def _get_features_and_labels(self, lookback=5): + def _get_features_and_labels(self, lookback: int = 5) -> tuple[np.ndarray, np.ndarray]: lookback_series = [] # Train and predict on N-period differencing data which is more normalized and stationary. data = pd.Series([bar.close for bar in self._spy.session][::-1]) @@ -55,7 +55,7 @@ def _my_training_method(self) -> None: # Prepare the processed training data. features, labels = self._get_features_and_labels() # Define the loss function using MSE for this example. - def loss_mse(target_y, predicted_y): + def loss_mse(target_y: np.ndarray, predicted_y: tf.Tensor) -> tf.Tensor: return tf.reduce_mean(tf.square(target_y - predicted_y)) # Train the model with Adam optimizer. optimizer = tf.keras.optimizers.Adam(learning_rate=self._learning_rate) @@ -65,7 +65,7 @@ def loss_mse(target_y, predicted_y): jac = t.gradient(loss, self._model.trainable_weights) optimizer.apply_gradients(zip(jac, self._model.trainable_weights)) - def on_data(self, data) -> None: + def on_data(self, data: Slice) -> None: if data.bars: # Get prediction using the updated features. new_features = self._get_features_and_labels()[0]