Hi, I'm one of the Quantopian users who switched to QuantConnect after it closed.
Quantopian has been a part of my life for the last 6 years, where I created over 3,000 algorithms.
So far I have successfully migrated about 3 dozens of my latest algorithms to QuantConnect.
A week ago, I asked QuantConnect Support to help me with a simple "Returns Rank head" strategy.
I'm still waiting for an answer.
So I decided to open this thread where former Quantopian users can get an answers on the peculiarities
of QuantConnect dialect of the Python.
Can somebody help me to port this 19 lines algorithm to QuantConnect API?
# talib Aroon portfolio
import talib
# --------------------------------------------------------
assets, bond = symbols('SPY', 'QQQ', 'TLT'), symbol('IEF')
period, lev = 21, 1.0
# --------------------------------------------------------
def initialize(context):
schedule_function(trade, date_rules.every_day(), time_rules.market_open(minutes = 65))
def trade(context, data):
wt_a = 0; wt = lev/len(assets);
for asset in assets:
H = data.history(asset, 'high', period + 1, '1d')
L = data.history(asset, 'low', period + 1, '1d')
AroonDown, AroonUp = talib.AROON(H, L, period)
if AroonUp[-1] > AroonDown[-1]:
order_target_percent(asset, wt)
wt_a += wt
else:
order_target_percent(asset, 0)
wt_b = lev - wt_a
order_target_percent(bond, wt_b)
record(lev = context.account.leverage)
Derek Melchin
Hi Vladimir,
Welcome to QC! See the attached backtest for the translated algorithm. Going forward, consider replacing the talib indicator with our built-in AroonOscillator indicator, as it'll be less computationally demanding than talib.
Refer to our documentation for more information on indicators.
Best,
Derek Melchin
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.
Vladimir
Derek Melchin,
Thank you for helping and unlocking this discussion.
Frogloks
Many thanks to Vladimir for this thread.
Will someone please take a look at this example algo and help me understand some peculiar behavior? This algo buys a share of TSLA, SWIR & CLNE market on close and liquidates them market on open.
It appears MOC orders in each symbol fill at the same price on 11/16 and 11/17 . This behavior repeats for 11/23 & 24. Additionally prices seem mis-aligned. On the 25th, TSLA fills at $555.38, another vendor reports this as the closing price of the 24th. However, the fill on the 27th is aligned with other sources.
Thank you for taking a look
Jared Broad
Hi RJ, please complete Boot Camp if possible. The time-frontier shift is covered in Boot Camp videos - or is the fifth item in the documentation list.
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.
Frogloks
Thank you for your prompt reply and warm welcome to Quantopian emigrants. I will invest more time in the boot camp.
Mohamed Ajmal
Is there a way out where we can get the code or algo from quantopion...???
Derek Melchin
Hi Mohamed,
The Quantopian site has been shutdown. Try contacting them to recover old projects stored on their servers.
Best,
Derek Melchin
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.
Vladimir
What is synonymous with Quantopian
data.can_trade(symbol)
to check if the symbol is avalable for trading
Vladimir
In QuantConnect I used to plot account_leverage in my algorithms.
account_leverage = self.Portfolio.TotalHoldingsValue / self.Portfolio.TotalPortfolioValue
Is this definition of account_leverage correct?
What is the correct synonymous with Quantopian
context.account.leverage
Vladimir
What is synonymous with Quantopian
data.can_trade(symbol)
to check if the symbol is avalable for trading
Derek Melchin
Hi Vladimir,
To check if a security is available for trading, we can use the condition
self.security.IsTradable and \ data.ContainsKey(self.symbol) and \ data[self.symbol] is not None
`IsTradable` means that the security was not removed from the universe and/or delisted and
data.ContainsKey(symbol) and data[self.symbol] is not None
shows that there is data in the current slice.
Yes, that's the correct definition of account leverage.
See the attached backtest for reference.
Best,
Derek Melchin
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.
Vladimir
Hi Derek,
I am trying to build Equal-weighted portfolio of stocks with different participation dates
in attached back-test.
By design
from Jan 2008 to Dec 2011 self.wt['QQQ'] should be 1.0
from Dec 2011 to Nov 2014 self.wt['QQQ'] and self.wt['XIV'] should be 0.5
What I am missing?
Derek Melchin
Hi Vladimir,
To resolve this, we should replace
if self.Securities[sec].IsTradable == True
with
if self.CurrentSlice.ContainsKey(sec) and self.CurrentSlice[sec] is not None
See the attached backtest for reference.
Best,
Derek Melchin
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.
Gv
Derek Melchin
How do we modify below line to make sure that "sec" is not only tradable currently but also has history of data from past 30days?
Derek Melchin
Hi Gv,
To ensure there is atleast 30 days of history, we can:
We can then check the `IsReady` property of the RollingWindow or indicator to determine if there is enough history. Refer to the Momentum in Mutual Fund Returns tutorial for an example of this technique.
Best,
Derek Melchin
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.
Vladimir
QC
I really miss the tab that was in Quantopian "Positions" - end-of-day portfolio positions in USD
for all portfolio items, including cash.
Derek Melchin
Hi Vladimir,
Thanks for the suggestion. As a workaround for now, we recommend saving the holdings data to a variable in the algorithm. When the OnEndOfAlgorithm method is called, the data can then be saved in the ObjectStore. After the backtest, we can load the data into the research environment.
Best,
Derek Melchin
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.
Vladimir
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!