Back

Loading Securities - Quantopian Migration

Hi all,

New user here from Quantipian. I was wnating to load 8 different securities as part of my portfolio.

Over at Quantopian, I am used to doing the following.

def initialize(context):
set_symbol_lookup_date('2015-01-01')
context.equities = symbols(
# Equity
'VV', # US large cap
'VO', # US mid cap
'VB', # US small cap
)
context.fixedincome = symbols(
# Fixed income
'TLT', # Long-term government bond
'IEF', # Mid-term government bond
'LQD', # Corporate bond
)
context.realasset = symbols(
# Commodity and REIT
'GLD', # Gold
'VNQ', # US REIT
)
context.securities = context.equities + context.fixedincome + context.realasset

context.period = 252 # One year to evaluate past performance
context.lever = 2.0 # Leverage
context.allocation_intervals = 10 # Allocation intervals (100% / 10 = 10% increment)
context.weights = dict.fromkeys(context.securities, 0)
context.shares = dict.fromkeys(context.securities, 0)

Is there no one function that lets me load all 8 ETFs? Additionally, I am wanting to set the leverage level for the portfolio at 2x. Is there something in QuantConnect that is similar to the "context.level = 2.0" line from Quantopian?

 

Thank you in advance :) 

Update Backtest








def Initialize(self):
self.equity = ['VV', 'VO', 'VB']
self.fixedincome = ['TLT', 'IEF','LQD']
self.realasset = ['GLD', 'VNQ']

self.etfs = self.equity + self.fixedincome + self.realasset

for etf in self.etfs:
self.AddEquity(etf)

Something like this should work for adding the securities

2

hi, the leverage  discussion is quite new and 5 posts below your post :) (when you sort it by "Newest")

https://www.quantconnect.com/forum/discussion/3646/understanding-buying-power-calculation-and-setholdings

if you have time check the bootcamp (tab) inside the algorithm lab first

second would be check the multiple examples provided by the quantconnect team starting with this one: loading multiple assets using consolidator and indicator with rolling window

so you can learn whats a rolling window in the docu and how to use indicator and that stuff.....(read the documentation)

https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/MultipleSymbolConsolidationAlgorithm.pyhttps://github.com/QuantConnect/Lean/tree/master/Algorithm.Python
1

Jonathan's code should do the trick!

0

Update Backtest





0

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.


Loading...

This discussion is closed