Back

Subclassing QCAlgorithm for Convenience of Callsites

I tried subclassing the QCAlgorithm class hoping to add a few functions to make some code easier read but it looks like the way we're finding the algorithm has a bug that doesn't look in the descendants. I guess we're using reflection and not recursing on Type.BaseType, ideally we could just be checking for typeof(IAlgorithm).IsAssignableFrom(type) -- or even better, couldn't we use MEF to compose the available algorithms at runtime?

Anyways, I just spilled some thoughts when in reality the first thing I should do is ask... has anyone had success doing this already and maybe I'm doing something else incorrectly?
Update Backtest








Possibly you're right, I think it is possible to extend & inherit the QCAlgorithm base though. Did you have a constructor on the new class? It needs a constructor to distinguish from interfaces. This is the specific line which selects the types out of the DLL.
1

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.


Oh nice, didn't realize the loader was on git.

Ah, yes that's what I suspected it was doing... we can try something like this:

I hope posting code isn't bad form considering it is already on git


Type baseClassType = Type.GetType(baseClassName);
if (baseClassType == null)
{
throw new ArgumentException("Invalid type name: " + baseClassName);
}
typeNames =
(from t in types
where t.IsClass && t != baseClassType // must be class and not the base type
where baseClassType.IsAssignableFrom(t) // must be assignable to the base class (derives from)
where t.GetConstructor(Type.EmptyTypes) != null // must have a default constructor (should we require public)
where !t.IsAbstract // must not be abstract, otherwise we can't construct it!!
select t.FullName
).ToList();
1

Also, on line 89 of that same file I we select the first one without any indication to the user that there was more then one... moreover, this is non-deterministic between builds. So if there are multiple algorithms in a single project, it might pick one the first time and a different one the next. Certainly not a huge issue, just noticed it while perusing some code :)
0

Awesome thank you. I'll add you as a contributor on the new project for open sourcing and update the library. We should use the 0,1 or infinity rule -- so if more than 1 algorithm fail or show dialog to select the right one..
1

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.


Update Backtest





0

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.


Loading...

This discussion is closed