I used the Sample Portfolio Allocation and changed the symbols to Vanguard's VCR and VHT ETF's. Due to duplicate tickers, I had to set a lookup date. Set the start date back to 2004. It implodes and I cannot understand why. Any ideas?
I used the Sample Portfolio Allocation and changed the symbols to Vanguard's VCR and VHT ETF's. Due to duplicate tickers, I had to set a lookup date. Set the start date back to 2004. It implodes and I cannot understand why. Any ideas?
You had the right idea - and almost the right implementation. The function "order_target_percent" makes it's calculations based on the number of filled shares, and ignores any open orders to reach the target amount. To avoid the wild swings back-and-forth, you should wait to rebalance until there are no more open orders. So the portfolio weights are maintained. I cloned your algo and added "if get_open_order():return" on line 6
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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.
Thank you for the thoughtful response. I've many more questions, but have only a few hours here, so I'll dig deeper before papering the community with questions. Understanding Excel logic functions and Google Scripts, I thought this would be a little easier, but can't seem to find a cohesive and comprehensive library of available code logic and argument building blocks beyond the API reference page. If you have any pointers, they would be welcome.
A few issues remain that I will throw out there. I really am searching for the underlying key to unlocking each question for myself as it will make me go much faster. If anyone can point me in a direction or has the time to respond, that would be a fantastic start to what I am trying to accomplish...
To answer your questions,
In the backtester, orders are submitted in one bar and filled in the next bar. They will be filled according to the slippage model. So in daily mode (which is what you had) an order submitted on Monday will get filled on Tuesday at the end of the day. In minute mode backtesting, an order submitted at 9:31AM will get filled at 9:32AM. I would recommend to backtest in minute mode because you get more frequent price data and it's closer to simulating live trading. Just because your algo runs every minute, that doesn't mean it has to trade that frequently. You can use schedule_function to specify the day and time to trade: https://www.quantopian.com/help#api-schedulefunction
I'm not sure what you mean, could you clarify? Maybe with an example?
Yes, cash can go negative. If you want to prevent this, you can add it as part of your code and here's an example. Also, the "order_target" family of functions will seek to your target positions and should avoid dipping into negative cash if used properly. In case you haven't seen them, you can also set trading guards in your algo.
Are you looking to prevent drift by rebalancing? If so, the order_target functions will keep your target amounts as your portfolio shrinks and grows. Otherwise, could you share an example (in words) of what you're trying to do?
You can do direct date comparisons, here is an example: https://www.quantopian.com/posts/rebalance-algo-9-sector-etfs. However, I'd recommend to use schedule_function instead, it's simpler to code and much easier to apply the datetime comparison.
Orders are rounded down to the nearest whole share.
record() is limited to 5 parameters, but if you want to plot more custom variables then try the research environment. It's currently in beta, and if you don't have access, you can jump the waitlist by submitting an entry to the contest.
Let me know if that helps and if you have any other questions!
Alisa
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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.