Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Migration from quantopian 1 to quantopian 2 help

Hey guys !

I'm trying to migrate one of algorithms from q1 to q2 but I'm a bit puzzled as to how I need to migrate the following code:

def ordering_logic(context, data):
record(leverage=context.account.leverage*100)
if 'Close' in data['VIX'] and 'Close' in data['VXV']:
vix = data['VIX']['Close']
#vxst = data['VXST']['Close']
vxv = data['VXV']['Close']
#slope = (vix/vxst)

The data[sid(N)] format should turn into data.current ?
I've been fiddling with it for quite some time now and I can't seem to find out what I'm doing wrong. I don't have a lot of experience with programming and I'm more into math so please don't kill me :)

7 responses

Looks like my code, just share with me and I'll replace the pieces. This one is a bit more onerous as you have to change the fetcher part as well

Actually try this:

 vix  = data.current('VIX','Close')  
 vxst = data.current('VXST','Close')  
 vxv  = data.current('VXV','Close')

I changed it to this:

def ordering_logic(context, data):
record(leverage=context.account.leverage*100)
if 'Close' in data.current('VIX') and 'Close' in data.current('VXV'):
vix = data.current('VIX','Close')
#vxst = data.current('VXST','Close')
vxv = data.current('VXV','Close')
#slope = (vix/vxst)
slope = (vxv/vix)
record(slope=slope*100)

But then where the slope line is it gets this error: SyntaxError: unindent does not match any outer indentation level

So it has to do something with the amount of tabs left of the word slope (there are 2 tabs), but any less or more are still faulty.

So I've fixed the indentations with the IntelliJ python sdk, maybe they could visualise indentation in the online editor ?

I'm trying to figure out the same problem - can you show an example of how you get around the SyntaxError?

Hi Peter,

That specific syntax error involves indentation/whitespace. Would you mind posting the section of the code that exhibits this error, with all whitespace intact? To post code with proper formatting, surround it with 3 backticks in a row on both sides, like this:

    ```  
    code  
    ```  
Disclaimer

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.

when i correct it to
def ordering_logic(context, data):
record(leverage=context.account.leverage*100)
if 'Close' in data.current('VIX') and 'Close' in data.current('VXV'):
vix = data.current('VIX','Close')
#vxst = data['VXST']['Close']
vxv = data.current('VXV','Close')
#slope = (vix/vxst)
slope = (vxv/vix)
record(slope=slope*100)

i get error message:

TypeError: current() takes exactly 2 positional arguments (1 given)
There was a runtime error on line 85.