Hi
I want to create an ML model that can generate insights and trade in backtesting.
benchmark idea
- suppose I bought equally weighted stocks on the first day of trade, used all my initial amount, and held my portfolio up to the last date of the backtest. (at last, I calculated net return based on dividends, splits, etc) it will be my benchmark.
from 2nd Day I want to run an ML model that can trade. but on the first day, I spent all my money. so I can not execute orders due to shortage of cash.
so I need help or suggestion on how can I create a benchmark that can only assume buy not real buy (remember I need dividends, split, etc) or we just simply create one fake portfolio that represents benchmark data and real one for ML.
hope I can explain my problem, Coding in python
Thank you in advance
Mia Alissi
Based on the information provided in the extracts, it seems like you want to create a benchmark that simulates buying and holding a portfolio of stocks, while also running a machine learning model for actual trading.
To create a benchmark in QuantConnect, you can use the
SetBenchmark
function. However, this function typically sets a single security (like SPY) as the benchmark. It doesn't directly support a custom portfolio as a benchmark.One possible workaround could be to create a separate algorithm that buys and holds your desired portfolio, and then use the results of this algorithm as a benchmark for your main algorithm. This separate algorithm would take into account dividends, splits, etc. However, this would require running two separate backtests and comparing the results manually.
As for the machine learning part, QuantConnect does support machine learning algorithms. You can plug in your ML model, such as Random Forest, with the appropriate hyper-parameters. The algorithm is a work-in-progress and the QuantConnect team is continuously working to improve it. You can adapt it to handle multiple symbols and use daily data consolidated from minute data.
Here is an example of how you can use the
SetBenchmark
function:And here is an example of how you can use a machine learning model in your algorithm:
Please note that these are just basic examples. You would need to adapt them to fit your specific needs and trading strategy.
For more information, you can refer to the QuantConnect documentation and the QuantConnect forum for discussions related to your query.
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
Great thanks for your reply.
Mia Alissi
You're welcome, Krish! If you have any more questions or need further clarification, feel free to ask. Happy coding!
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
Hi Mia,
I want to know if can I run two algorithms parallelly.
I want to build two portfolios, CustomTickerAlgorithm is my main algorithm where I write my Machine learning algorithm, and based on ML it will buy and sell stocks and build real real-time Portfolio.
in my FakeQCModel there will be a simple buy and hold Portfolio which can track some assumption or hypothesis.
from my main class, I want to take a value of fake portfolio for regular interval.
is it possible?
I have tried to run but it does not call Ondata of FakeQCModel, also tried to implement with Alpha model but did not work.
Mia Alissi
Based on the information provided in the extracts, it's not possible to run two algorithms in parallel within the same brokerage account. This is because QuantConnect/Lean only manages one portfolio per account. To place orders, it needs to know the portfolio state for buying power calculation. Consequently, it would need to fetch information from each account and save it in different portfolios with different states/buying power.
However, you can run multiple strategies within a single algorithm. You can call different strategies within the
OnData
method of your algorithm. Here's an example:In your case, you could have one strategy for your machine learning model and another strategy for your buy and hold portfolio. You would need to manage the cash allocation between the two strategies manually.
For more information, you can refer to the QuantConnect documentation and the QuantConnect forum for discussions related to your query.
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.
Sukhvinder Pal Singh
Thank you for your reply.
let me explain my implementation or code, I'm new here so some terminology or concept may I miss
this is what I'm doing
it runs well if I build 2 different algorithms and run both manually. but I want to merge both and my main algorithm call it self at the end of backtest, and get profit/loss from fakeQcModel Portfolio.
Ashutosh
Hello Krish Nandan das and Sukhvinder Pal Singh
This is not possible sorry.
We cannot create multiple subclasses from the QCAlgorithm class.
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!