Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions project-templates/python/ai/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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)
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class QuiverQuantCongressChainedUniverseAlgorithm(QCAlgorithm):

_fundamental = []
_fundamental: list[Symbol] = []

def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
Expand Down
2 changes: 1 addition & 1 deletion project-templates/python/custom-models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down