# region imports
from AlgorithmImports import *
# endregion
class DemoAC(QCAlgorithm):
def initialize(self):
# Locally Lean installs free sample data, to download more data please visit https://www.quantconnect.com/docs/v2/lean-cli/datasets/downloading-data
self.set_start_date(2023, 10, 7) # Set Start Date
self.set_end_date(2024, 11, 11) # Set End Date
self.set_cash(100000) # Set Strategy Cash
self.add_equity("SPY", Resolution.DAILY)
self.set_warm_up(14)
def on_data(self, data: Slice):
if self.is_warming_up:
return
if not self.portfolio.invested:
self.set_holdings("SPY", 1)
self.debug("Purchased Stock")
it is simple script but Quantconnect not processing order, if I change start date to 2017-01-01 it works but not with the latest one.
Mia Alissi
The issue you're facing might be due to the fact that the start date you've set for your algorithm is in the future (2023, 10, 7). The LEAN engine, which powers QuantConnect, uses historical data to backtest your algorithms. If the start date is set in the future, the engine won't have any data to work with, hence no trades will be executed.
When you set the start date to 2017-01-01, it works because there is historical data available for that period. If you want to test your algorithm with more recent data, you should set the start date to a day in the past for which data is available.
Here is the corrected code:
Please note that the start and end dates have been changed to a period for which data is likely available. You may need to adjust these dates based on the actual data availability.
For more information on how to use the LEAN engine, you can refer to the QuantConnect Documentation.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Krish Nandan das
start_date: 2023-01-01
end_date: 2024-01-01
I'm getting data for this period if you see the log. but can not execute trade on this specific date. (in my first discussion or question, by mistake I have written 2024-11-1 it should be 2024-1-1).
Mia Alissi
Based on the information provided, it's possible that the issue is related to the availability of data at the specific date you're trying to execute a trade. While you might be getting data for the period between 2023-01-01 and 2024-01-01, it's important to note that the data processing in the cloud is roughly 36 hours behind live, as mentioned in the forum discussion.
This means that if you're trying to execute a trade on a very recent date, the necessary data might not be available yet. If this is the case, you might need to adjust your start and end dates to a slightly earlier period.
If you're still facing issues, it would be helpful to have more details about the error message you're receiving or the behavior you're observing. This will help in diagnosing the issue more accurately.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Krish Nandan das
ok understand my problem, data is only available up to 2021-03
that might be issue.
P.S I'm using lean local CLI.
is there any option to get latest data ?
Mia Alissi
Yes, you can get the latest data by using the
ApiDataProvider
in LEAN. This data provider automatically downloads the required data files when your backtest requests them. After it downloads a data file, it stores it in your local data directory so that in future runs, it won't have to download it again.Here are the steps to use the
ApiDataProvider
to automatically download the data you need:lean backtest "<projectName>" --download-data
to run a local backtest for the project in ./ and update the Lean configuration to use theApiDataProvider
.For example:
This command will run a local backtest for the project in ./My Project and update the Lean configuration to use the
ApiDataProvider
.Please note that you cannot download data with a subscription. However, you can design in Visual Studio and backtest in the cloud with the Visual Studio plugin.
For more information, you can refer to the QuantConnect Documentation.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Krish Nandan das
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!