Hi all,
I've been having difficulties getting some Python code running - i.e.: just getting simple History data.
On the other hand, I managed to get the "same" Python code but in C# running without issues.
Does C# have better support than Python at QuantConnect?
What about local development? I'm used to local editors for syntax, compilation checks, etc and I feel that the web IDE is not ideal, at least for me, if you want to get continuity while developing.
Looking forward to hearing about your experiences.
Cheers,
Arthur
ps: See the code snippets below:
class HistorySpike(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 7, 2)
self.SetEndDate(2018, 7, 2)
self.SetCash(25000)
self.AddEquity("SPY", Resolution.Minute)
slices = self.History(TimeSpan.FromDays(5))
if not slices.empty:
bars = slices.loc["SPY"]
close = bars["close"]
self.Log("...")
namespace QuantConnect
{
public class HistorySpike : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2018, 7, 2);
SetEndDate(2018, 7, 2);
SetCash(25000);
AddEquity("SPY", Resolution.Minute);
IEnumerable<Slice> slices = History(TimeSpan.FromDays(5));
IEnumerable<TradeBar> bars = slices.Get("SPY");
IEnumerable<decimal> decimals = slices.Get("SPY", Field.Close);
double[] doubleArray = decimals.ToDoubleArray();
Log("...");
}
}
}
Gurumeher Sawhney
QuantConnect supports both C# and Python, however, LEAN is written in C# and its local development will be easier in C# and Visual Studio. It is one of our goals to have LEAN written in Python soon.
The reason to why the self.History function did not work is because the method call above provides an enumerable slice. If we want to request pandas, the method call self.History(self.Securities.Keys, (TimeSpan.FromDays(5)) will work. Otherwise, we can do:
slices = self.History(4, Resolution.Daily)
for slice in slices:
self.Debug(slice["SPY"].Close)
Arthur Gassner
Hi Gurumeher,
Thanks for your help. It worked!
Good to know about the goal of having LEAN written in Python.
Thanks,
Arthur
Arthur Gassner
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!