Hi,
I am workinig on a code that does some initial stock filtering wthin the Initialize function by triggering an standalone class. I am unable to find a way to:
1. Run debug messages from the code. ( I was able to retrieve variables from the class so I know it was created, but the constructor debug message was never triggered)
2. Get histroical prices within the partial class function. Is this not possible within QC or am I doing it in the wrong way?
Very thankful if anyone has some inputs.
namespace QuantConnect {
public partial class PairSelection : QCAlgorithm, IAlgorithm
{
private string[] tickerSymbols;
public PairSelection(string[] tickers){
this.tickerSymbols = tickers;
Debug("Triggered the PairSelection constructor");
}
public List<Stocks> selectPairs()
{
Debug("Triggered the selectPairs function");
for(int m = 0; m<tickerSymbols.GetLength(); m++){
AddEquity(tickerSymbols[m], Resolution.Daily);
var histEq = History(tickerSymbols[m], TimeSpan.FromDays(252), Resolution.Daily);
// Do some other things
}
}
}
}
JayJayD
Have you tried passing the QCAlgorithm as argument?
Something like:
public class CoolAlgorithm : QCAlgorithm { public override void Initialize() { SetStartDate(2013, 10, 07); //Set Start Date SetEndDate(2013, 10, 11); //Set End Date SetCash(100000); } public override void OnData(Slice data) { MyStaticClass.MyStaticMethod(this); } } public static class MyStaticClass { public static void MyStaticMethod(QCAlgorithm algorithm, Slice data) { // Do your magic here } }
Jan Sedlak
I tried paste the class direcly in the Intialize function and then the debug and data function works. I can try this option as well. Would you trigger the debug funtion by calling algorithm.Debug("Debug message")?
JayJayD
> Would you trigger the debug funtion by calling algorithm.Debug("Debug message")?
Yes, and you'll also have access to all the algorithms objects like Portfolio, Securities, Transactions, etc!Jan Sedlak
Sounds good. Thanks for the tip!
Jan Sedlak
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!