In this thread, we are going to cover the differences between Quantopian and QuantConnect APIs.
Basic Algorithm
In QuantConnect, all algorithms must have an Initialize method to setup your strategy. Once setup most algorithms have OnData event handlers to process market data and make trading decisions:
# Quantopian
def initialize(context):
# Reference to AAPL
context.aapl = sid(24)
def handle_data(context, data):
# Position 100% of our portfolio to be long in AAPL
order_target_percent(context.aapl, 1.00)# QuantConnect
class MyAlgo(QCAlgorithm):
def Initialize(self):
# Reference to AAPL
self.aapl = self.AddEquity("AAPL")
def OnData(self, data):
# Position 100% of our portfolio to be long in AAPL
self.SetHoldings("AAPL", 1.00)
Please note that we must define a class with the QuantConnect API and it must inherit from QCAlgorithm.
self refers to the instance attributes of the algorithm class. It is used to access methods and members of QCAlgorithm like AddEquity in the example above.
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!