Hi,
Here's another low capacity algo for you. You'll need to find more suitable stocks to trade a larger account. I do not recommend trading stock 'Y' with it as it is likely that a number of people are going to try that where I have published this script. That will likely ruin gains for that stock. I have a screener that can find suitable stocks.
This a mean reversion variant. I take the triangular moving average of the candle averages. Each of these candle averages is calculated by summing the open, high, low, and close and dividing by four. To calculate the distance from the tma to set the buy and sell points, I use half of the full range of the rolling window and subtract or add accordingly.
I have componentized the main calculations in the TMA2 class, so you can quickly copy and paste this component into more complex algos.
Use at your own risk.
Regards,
Warren Harding
Jared Broad
We have quote data coming soon :) Hopefully, we can give you realistic spreads on some of these low capacity algorithms.
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.
Warren Harding
Awesome news about the quote data. I have to try out the new debugging tools too.
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.
SLs
Hi, Warren Harding,
Thank you for this algo, this is really an example for me that quant trading is working.
Could you, please, explane how you do stocks screener , how to do search of suitable stocks for this algo, wat is important criteria to looking for ?
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.
Warren Harding
To screen, I calculate the returns on a per stock basis, then rank by returns. Note that there is a survivorship bias type of problem ingrained in this approach. However, you can keep an eye on the number of trades to overcome it. The backtest above has 894 trades. That's a fair size sample set which suggests that the pattern of price action with this stock has actually been suitable for the TMA2 approach.
Quantconnect does not easily let you see the returns on a per stock basis as best I know, but it can be done. You could use the trade log and recalculate the returns from that. Or you could do as I've done, I have a minimalist backtester that I integrated right into the Quantconnect script that lets me screen to see which stocks are behaving well for whatever strategy I want. That might not be the easiest approach but I have a proprietary minimalist backtester handy that I have already written. This approach gives me a lot of power where I can see which stocks have been behaving appropriately in recent time for any given strategy.
Much of the work is in the screening. TMA2 is actually a B-grade strategy kernel. I'm not for giving my best stuff away, sorry.
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.
Daniel Chen
It's an amazing algorithm! I would recommend combining the universe selection and the TMA2 approach to get better performance. My idea is that we could apply the TMA2 trading logic on stocks filtered by coarse and fine selection. As long as the number of filtered symbols is set to be small in the universe selection, the backtest result actually reflects the return on a per stock basis. Let me know if you have better ideas, thanks!
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.
Aaron Tawil INVESTOR
Daniel Chen actually gave that a try - thinking the same thing and applying the boot camp to it. Still needs some tweaking to get right though. The algo I cam up with just seemed to buy and hold, so I am sure I am doing something wrong. But working on it. Would love to try and include an RSI alpha metric to also help make decisions.
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.
Warren Harding
Thanks Daniel. I'll consider your advice.
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.
Warren Harding
Hi Daniel. It sounds like you are suggesting something similar to what I have already done. I have a multi-stock version that can screen for suitable stocks as the backtest proceeds in a rolling like fashion. I could move the screening into a coarse selection function and that would eliminate the need for ticker lists. I'm using a high dollar volume ticker list right now.
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.
Valery T INVESTOR
Your algorighm does not re-invest the profits. Why?
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.
Warren Harding
Hi Valery. You can only trade so much before you'll run into problems with orders not being filled.
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.
Valery T INVESTOR
Hi Warren.
From your experience, does paper trading with IB reflect the real trades (orders being filled)?
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.
Warren Harding
I haven't used IB's paper trading platform.
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.
Douglas Stridsberg
Valery T IB paper trading is unlikely to demonstrate realistic execution of this algorithm. Toy algorithms like these (submitting arbitrarily tight limit orders and crossing your fingers they get filled) have been submitted before and should not under any circumstances be relied upon to produce profitable live trading. A simple test of robustness (change date range, tickers, fee assumptions, etc.) highlights how cherry-picked the range displayed in the original post is.
Please always do your own thorough research before committing any kind of capital to any kind of strategy, no matter how beautiful the backtest looks to be.
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.
Warren Harding
Hi Douglas, good to see you again. Unlike Beer Money, you can increase the period so the limit orders aren't so tight. It will still profit in backtesting. I chose the last year's date range deliberately as market dynamics change, with 894 trades being put through there is a fair size sample set just trading the last year. You can't just change the ticker, many stocks simply don't revert to the mean as this one does. I use the standard fees. You are right about being careful live trading any strategy, it may simply not perform as expected due to market reaction or some other reason. I still think you should start with exceptional backtests, then see which ones perform well live. Starting with a mediocre backtest is almost certainly going to bring you mediocre results.
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.
Ian Larson
https://www.quantconnect.com/alpha/59c617b46d2ecebdafb790c52 I've been meaning to ask @Douglas Stridsberg about that one. Obviously the equity curve was negative during backtesting so...must be some method to the madness? This one is nothing to sneeze at though: https://www.quantconnect.com/alpha/06bffa9edd7355cdaab263fb2
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.
Jared Broad
I encouraged the submission of Procyonoides. It has a solid core thesis and is mostly negative due to the retail spread of our data vs the algorithm concept itself. Institutions have a better ability to execute and access to different contracts so a consistent slope in either direction can still be a valuable signal.
The alpha stream thesis and research technique is more important than profitability. Many of the biggest funds are simply seeking predictable/reliable uncorrelated out of sample curves.
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.
Warren Harding
Now, THIS is an unrealistic backtest. 3131728331330290000% annual return! 1.3% drawdown! I was hoping to be so rich. Again. Too bad it utterly fails. When you lower the position sizing to a realistic value that considers what will actually fill, the algo fails. The fees rise relative to profits. And it suffers from slippage problems that are compounded by the high frequency (I built a limit order version, it doesn't work either). And it's showing exponential growth that isn't realistic given the fill limitations.
At 98.029% annual returns and 4.9% drawdown TMA2 isn't actually that impressive. It passes all of my reality checks though.
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.
Valery T INVESTOR
Hi Jared,
What are your criterias for selecting such algo?
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.
Hao Bin Zhang
Warren Harding does the interactivebrokermodel actively take into account slippage or model the impact of large market orders? Also, how can an algorithm achieve 16 Sharpe even if it is relatively high frequency! That is really amazing!
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.
Warren Harding
I haven't used the brokerage models as much as I should. I've been using limit orders more and more as I don't trust slippage approximations. Also high frequency trading generally fails due to the slippage adding up with market orders. The default setting does not model large order impacts, I've been keeping order sizes small to stay on the safe side. High frequency algos can definitely profit well, those small gains can really add up.
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.
HanByul P
Hi Jing Wu, Just a quick question: Why is this algo waiting for a month and starting to run from a second month? Is it for warming up? Can we modify this algorithm to run from the first month? Just remove the flags? Please let me know. Thank you.
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.
Weiheng Liang
Thank Jing.
market cap = Shares Outstanding * Price = Shares Outstanding * (Earnings Per Share * PE ratio)
That's what I was waiting for. It's a huge improvement for my algo.
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.
Xi Liu
Hi Jing Wu,
1. I ran the Algo, and found the exit function(when current SPY price is lower than last N-day moving average price, then liquidate all the open positions and buy TLT.) doesn't work all the time. The exit function doesn't work, making it performs bad on crisis.
The momentum strategy has relatively higher volitility. I think one of the drawback of momentum strategy is failing to act quickly to close a bad position. I'm considering to add a Stop Market Order of the portfolio composite seperately. However, I'm new to do an alogo with python, after reading the Documentation and browing the internet, I only learned how to add StopMarket order while making market order, like this:
self.MarketOrder(self.baba, 300)
self._stopMarketTicket = self.StopMarketOrder(self.baba, -300, slice['BABA'].Close * Decimal(0.95), "stop market")
This algo's code seems complex to me, I can't find the place to get the price and deploy the StopMarket order.
Can you give me some instructions on this problem?
2. I want to test the algo with leverage, for example, 1.5 leverage then I modify LINE 96:
weight = 0.99/len(chosen_df)
for symbol in chosen_df.index:
self.AddEquity(symbol)
self.SetHoldings(symbol, weight)
I change 0.99 to 1.5, but it doesn't work. Do you know how to set the weight here?
Thank you a lot.
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.
Jon Quant
I have sprinkled a bunch of debug lines in the code just to analyze the behavior and I have noticed that if I set the following dates:
SetStartDate(2004, 1, 1); SetEndDate(2004, 4, 1);
...the value for the "symbols" variable in "FineSelectionFunction" gets assigned on 01/03/2004 only to be used by the "rebalance" function a month later, 02/02/2004. This tells me that the rebalance is operating on a fine "symbols" list that is a month old. Is this intentional?
One other behavior that I have noticed is that the "CoarseSelectionFunction" and "FineSelectionFunction" never gets called on the "MonthStart" day. In my example date window, it never gets called on 01/02/2004. Is the "MonthStart" schedule somehow interfering with the Coarse and Fine events?
Thanks!
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.
Jing Wu
Hi Xi Liu,
You can use self.StopMarketOrder() everywhere in your algortihm. For the stop price, you can use
"self.Securities["BABA"].Close" * Decimal(0.95) instead of "slice['BABA'].Close * Decimal(0.95)" because you can only get the slice data in OnData() method.
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.
HanByul P
Hi Jing Wu, I cloned your new method (for Market Cap) algo and ran for 2015 to March 1st of 2018. I found that the leverage went up to 500% (5x) in the early 2016 and came down to 300% (3x) in the end of this backtest period. You set the maximum weight to 0.99x as below. I guess something should be fixed. Can you take a look and fix the leverage control (e.g. maximum 2.0x)? Thank you.
weight = 0.99/len(chosen_df)
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.
Ton86
Hi Jing Wu,
I ran this today 4/2/2018 and was looking for the trade signals to occur by 10am PST since that seems to be the time the trades occur in the backtesting. Do we need to wait until end of first day of the month or should the signals be there by 10am PST, or another time?
When setting this up for trading live what types of alterations might need to be made? Is there a page/link that describes this or is this something support helps with after creating a live account?
Thank you!
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.
Ton86
Jing Wu,
Also seeing errors like this:
Backtest Handled Error: The order quantity for TLT cannot be calculated: the price of the security is zero.
Doesn't look like April 2018 TLT trade is getting executed because of it. Could it be that the algo is looking at the first of the month for the price but isn't seeing it because the first falls on a weekend?
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.
Yulong Jiang
Hi, Jing, I am new to QuantConnect so a little confused on your code.
it seems that you do everything on Intialize() and pass on OnData(), does it mean Initialize() will run many times instead of just setting the initialial condition?
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.
Michael Manus
nope only once
everything?? settings holdings are in rebalance ....
check the bootcamp(-tab) in the algorithm lab
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.
Wei Chian Ong
I'm a little bit confused by the code snippet below. We check the moving average exit gate, and if it shuts, we loop through each position, if it's not TLT (bonds), then we exit the position. That makes sense.
if self.Securities[self.spy].Price < spy_hist.mean(): for symbol in self.Portfolio.Keys: if symbol.Value != "TLT": self.Liquidate()
But, when we use self.Liquidate() and don't specify a security, doesn't it just liquidate every single position in the portfolio? Why bother to loop through the Portfolio keys at all, if we are just going to liquidate everything anyway? In my head it seems that self.Liquidate(symbol) or self.Liquidate(symbol.Value) would make more sense. Can someone tell me what I am missing?
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.
Weiheng Liang
Wei Chian Ong, what the code Liquidate() will do is possibly more tricky than you imagined. I suggest you check the code inside ideally debug carefully by using VS.
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.
Wei Chian Ong
Thanks for the reply. I've had a look at your previous post regarding the self.Liquidate() method, and my question probably doesn't run as deep as the intricacies of dark pools and slippage in actual trading. It's more of a question regarding the coding itself. The documentation and this forum post and reply seem to indicate that using self.Liquidate() without a security specified, will liquidate all positions, and I was having trouble understanding why we bother looping through each symbol in the portfolio and checking if it's not treasury bond ETF, if we go ahead and liquidate everything anyway, would it not make more sense to use self.Liquidate() with the actual position we are currently looping through?
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.
Weiheng Liang
I was not meaning dark pools. I was just saying we should look inside the detail codes of Liquidate() in VS if there is something confused.
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.
Wei Chian Ong
I'm not familiar with how to use visual studio (I assume that's what VS stands for), so I'll have to try it using log or debug calls.
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.
Nick Jensen
I cloned this algorithm and received an error "Invalid Token" on the self.SetStartDate function, so am unable to run or backtest. Is anyone receiving this same error? Is there an easy fix?
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.
Wei Chian Ong
I think I kept getting the same Nick and I wasn't sure why either. I deleted the code for the self.SetStartDate and self.SetEndDate and then re-typed them manually in case it was a whitespace issue or something (probably a very inefficient way to do that anyway). Same problem, but I repeated that several times and eventually it worked. Not a very scientific response to your question .......
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.
Jared Broad
The invalid token is from python 2.7 to python 3.6 upgrade. Since python 3.6 numbers can't be prefixed with 0 -- e.g. "01"
If you cloned an old backtest it can have dates with 2001, 01, 01 etc.
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.
Leng Dieb
I am trying the codes for the test on paper live server but it does not seem to generate any trade. Could you please advise anything need to be changed to run live for the paper trading?
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.
Tocht
Any updates?
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!