| Overall Statistics |
|
Total Orders 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Start Equity 100000 End Equity 100000 Net Profit 0% Sharpe Ratio 0 Sortino Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset Portfolio Turnover 0% Drawdown Recovery 0 |
from AlgorithmImports import *
class ScheduledPriceAlgorithm(QCAlgorithm):
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(2025, 5, 1) # Set Start Date
self.SetEndDate(2025, 5, 2) # Set End Date
self.SetCash(100000) # Set Strategy Cash
# A list of stocks we want to track
self.symbols = ["FRGT", "KIDZ" , "VENA"]
for symbol in self.symbols:
self.AddEquity(symbol, Resolution.Minute)
# Store the prices
self.close_prices = {}
self.open_prices = {}
# Schedule an event to trigger at market close on May 1, 2025
self.Schedule.On(self.DateRules.On(2025, 5, 1), \
self.TimeRules.At(15, 59), \
self.GetClosingPrices)
# Schedule an event to trigger at market open on May 2, 2025
self.Schedule.On(self.DateRules.On(2025, 5, 2), \
self.TimeRules.At(9, 31), \
self.GetOpeningPrices)
def GetClosingPrices(self):
"""
This method is scheduled to run at 3:59 PM on 2025-05-01.
It retrieves the closing price for each symbol for that day.
"""
self.Log(f"Fetching closing prices for {self.Time.strftime('%Y-%m-%d')}")
for symbol in self.symbols:
history = self.History(self.Symbol(symbol), 1, Resolution.Daily)
if not history.empty:
close_price = history.loc[symbol]['close'][0]
self.close_prices[symbol] = close_price
self.Log(f"Close price for {symbol}: {close_price}")
else:
self.Log(f"No history data for {symbol} on {self.Time.strftime('%Y-%m-%d')}")
def GetOpeningPrices(self):
"""
This method is scheduled to run at 9:31 AM on 2025-05-02.
It retrieves the opening price for each symbol for that day.
"""
self.Log(f"Fetching opening prices for {self.Time.strftime('%Y-%m-%d')}")
for symbol in self.symbols:
history = self.History(self.Symbol(symbol), 1, Resolution.Daily)
if not history.empty:
open_price = history.loc[symbol]['open'][0]
self.open_prices[symbol] = open_price
self.Log(f"Open price for {symbol}: {open_price}")
else:
self.Log(f"No history data for {symbol} on {self.Time.strftime('%Y-%m-%d')}")
# Once we have both sets of prices, we can log them out or perform other actions
self.LogResults()
def LogResults(self):
"""
Logs the final collected prices.
"""
self.Log("--- Final Results ---")
self.Log("Closing Prices on 2025-05-01:")
for symbol, price in self.close_prices.items():
self.Log(f"{symbol}: {price}")
self.Log("Opening Prices on 2025-05-02:")
for symbol, price in self.open_prices.items():
self.Log(f"{symbol}: {price}")
self.Log("--------------------")
def OnData(self, data):
"""
OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
"""
pass