Hi there,
This algorithm aims to achieve a market-neutral strategy by selecting penny stocks based on their dollar volume and market cap. It then uses momentum to determine which stocks to go long and short on. The positions are re-balanced monthly, and the algorithm ensures that it only holds the selected stocks, liquidating any others. Despite nice backtests results, after few days testing on paper trading there is no order generated. I first got orders generated at 0400 CET, solved by using OnMarketOpen orders. Now, even if a backtest starting on 12th June is generating orders, there is no order generated in live.
If somebody has a hint…
Thanks
S.Laignel
Mia Alissi
Based on the provided code, it seems that the algorithm is designed to select penny stocks based on their dollar volume and market cap, and then uses momentum to determine which stocks to go long and short on. The positions are re-balanced monthly, and the algorithm ensures that it only holds the selected stocks, liquidating any others.
However, if no orders are being generated in live trading, there could be a few potential issues:
Data Availability: Ensure that the data for the selected stocks is available in live trading. Sometimes, data might be available in backtesting but not in live trading due to various reasons such as data vendor restrictions, etc.
Momentum Calculation: Check if the momentum indicators are being updated correctly in the
OnData
method. If the momentum indicators are not being updated correctly, it could lead to incorrect signals, thus not generating any orders.Rebalance Flag: The rebalance flag is set to True only when the current month changes. If you are running the algorithm for a period that does not cross the month boundary, the rebalance flag might not be set to True, and hence no orders would be generated.
Order Placement: The provided code snippet does not seem to contain the part where the orders are actually placed based on the selected long and short stocks. Ensure that the orders are being placed correctly in the live trading environment.
Remember, live trading environment is different from backtesting and might require additional checks and balances to ensure the algorithm works as expected. If the issue persists, consider reaching out to QuantConnect's support for further assistance.
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.
Sebastien M. Laignel
Here is the part of the code dealing with long orders:
Mia Alissi
The provided code snippet is responsible for placing long orders. Here's a breakdown of what it does:
It iterates over the symbols in
long_selected
, which are presumably the symbols of the stocks that the algorithm has decided to go long on.For each symbol, it checks if the algorithm has already invested in that stock (
current_investment = self.Portfolio[symbol].Invested
).If the algorithm has already invested in the stock, it places a MarketOnOpen order to buy additional shares of the stock (
self.MarketOnOpenOrder(symbol, additional_investment / data[symbol].Close)
). The number of shares to buy is calculated as the additional investment amount divided by the current price of the stock.It then sets a stop price at 18% above the current price (
stop_price = data[symbol].Close * 1.18
) and places a stop limit order at this price (self.stop_limit_order(symbol, self.Portfolio[symbol].Quantity , stop_price, stop_price)
). This means that if the stock price reaches this stop price, the algorithm will sell the stock.If the algorithm has not already invested in the stock, it places a MarketOnOpen order to buy shares of the stock (
self.MarketOnOpenOrder(symbol, initial_investment / data[symbol].Close)
). The number of shares to buy is calculated as the initial investment amount divided by the current price of the stock.Similar to the case where the algorithm has already invested in the stock, it sets a stop price at 18% above the current price and places a stop limit order at this price.
Finally, it logs some debug information about the order.
Please note that this is a simplified explanation and the actual behavior might vary based on other parts of your algorithm. If you're still having issues, consider reaching out to QuantConnect's support for further assistance.
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.
Sebastien M. Laignel
Corrected code: MarketOrder and Setbrokerage.
I expect to have orders generated at 4 am
Mia Alissi
The provided code snippet is part of a market-neutral strategy that selects penny stocks based on their dollar volume and market cap. It uses momentum to determine which stocks to go long and short on. The positions are re-balanced monthly, and the algorithm ensures that it only holds the selected stocks, liquidating any others.
However, if 'Sebastien' expects to have orders generated at 4 am, he might need to adjust the resolution of the data he's using. Currently, the UniverseSettings.Resolution is set to Daily, which means the algorithm receives data and potentially makes trading decisions once a day at midnight. If he wants the algorithm to make decisions at 4 am, he might need to use a higher resolution (e.g., Hourly) and add a check in the
OnData
method to only make trading decisions at 4 am.Also, it's important to note that the
MarketOrder
method in theOnData
function is using the close price of the symbol to calculate the quantity of shares to order. This might not be the best approach as the close price is from the previous day and the price at 4 am could be significantly different.Lastly, the
set_end_date
method seems to be used incorrectly. It should beSetEndDate
.If the issue persists, consider reaching out to QuantConnect's support for further assistance.
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.
Sebastien M. Laignel
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!