Skip to content

Add seed_initial_prices and cosmetic changes to Python templates#2383

Open
Ruuudy1 wants to merge 9 commits intoQuantConnect:masterfrom
Ruuudy1:bug-project-templates-py-rest
Open

Add seed_initial_prices and cosmetic changes to Python templates#2383
Ruuudy1 wants to merge 9 commits intoQuantConnect:masterfrom
Ruuudy1:bug-project-templates-py-rest

Conversation

@Ruuudy1
Copy link
Copy Markdown
Contributor

@Ruuudy1 Ruuudy1 commented May 8, 2026

Summary

  • Add self.settings.seed_initial_prices = True after set_cash in all 44 Python templates (skipped where no set_cash or already present)
  • Cosmetic improvements: blank line normalisation, comment capitalisation and punctuation, numeric formatting (100000100_000), on_data parameter rename (slicedata), liquidate_existing_holdings=True → positional True, time_rules.at trailing zero removed, schedule.on/train expanded to multi-line, and/or operators moved to end of line
  • Equity/Equities capitalised in comments where referring to the asset class

Test plan

  • Run python project-templates/python/run_syntax_check.py — expect 100% pass
  • Spot-check a few templates for correct seed_initial_prices placement and comment style

Comment thread project-templates/python/cfd/main.py Outdated
# Seed the price of each asset with its last known price to
# avoid trading errors.
# Seed the price of each asset with its last known price to
# Avoid trading errors.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Avoid" shouldn't be capitalized here

Comment thread project-templates/python/cfd/main.py Outdated
# Set scheduled events to hold each CFD contract during
# their regular trading hours.
# Set scheduled events to hold each CFD contract during.
# Their regular trading hours.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here

# You can also create a consolidator with a period of one day and start time of 17
# consolidator = QuoteBarConsolidator(timedelta(1), timedelta(hours=17))
# You can also create a consolidator with a period of one day and start time of 17.
# Consolidator = QuoteBarConsolidator(timedelta(1), timedelta(hours=17)).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line edit is incorrect. Keep the original comment

if is_live_mode:
# Example Line Format:
# {"high": "441.00", "last": "421.86", "timestamp": "1411606877", "bid": "421.96", "vwap": "428.58", "volume": "14120.40683975", "low": "418.83", "ask": "421.99"}
# {"high": "441.00", "last": "421.86", "timestamp": "1411606877", "bid": "421.96", "vwap": "428.58", "volume": "14120.40683975", "low": "418.83", "ask": "421.99"}.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't have a period at the end

# Example Line Format:
# Date Open High Low Close Volume (BTC) Volume (Currency) Weighted Price
# 2011-09-13 5.8 6.0 5.65 5.97 58.37138238, 346.0973893944 5.929230648356
# Date Open High Low Close Volume (BTC) Volume (Currency) Weighted Price.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove periods at the end of these comments

Comment thread project-templates/python/forex/main.py Outdated

# Trade if the current spread is the lowest bid-ask spread,
# since it is the most efficient, liquid price with lowest slippage.
# Trade if the current spread is the lowest bid-ask spread,.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

self._option.set_filter(lambda u: u.expiration(0, 0).strikes(-1, 1))
# Filter the Option universe by Delta. The last set_filter call prevails.
# self._option.set_filter(lambda u: u.delta(0.25, 0.75))
# Self._option.set_filter(lambda u: u.delta(0.25, 0.75)).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

def on_data(self, slice: Slice) -> None:
# Since we are trading 0DTE, they will expire on end of day.
# So we don't need to remove them explicitly.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert comment

self.log(message)
# See https://www.quantconnect.com/docs/v2/writing-algorithms/live-trading/notifications
# for all notification methods
# For all notification methods.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

# and place the OCO orders to sell it.
# Otherwise, we will short 75% of the portfolio value
# and place OCO orders to rebuy.
# If the price is above the EMA, we will buy 75% of the portfolio value.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants