Back to Community
FutureSymbol() - ERROR Symbol Argument Must be a String

Trying to use the "future_symbol()" function to return a specific object in the futures chain. Usage like "future_symbol( 'VXN17')" works fine. However, as soon as "future_symbol( variable )" or "future_symbol( reference )" is used, the following error is returned:

Error InvalidFutureSymbolCall: 0077 symbol argument must be a string.

Okay, so that seems weird that you can't pass the symbol you want to return into future_symbol(). What's even weirder is if you use the IDE Debugger, everything works fine and you can pass in variables as much as you want.

In the attached Algorithm, line 11 works fine. Lines 12-15 throw the error. If you comment out lines 12-15 and use the Debugger to manually enter each one, they all work perfectly fine.

So it doesn't work when the Algo builds, but it works fine in the Debugger.....Can anyone explain what is going on or a possible workaround?

Clone Algorithm
0
Loading...
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
def initialize(context):
    pass

def before_trading_start(context, data):
    context.vx_future = continuous_future('vx') #VX futures only available from July 2012!!!
    vx_chain = data.current_chain(context.vx_future)
    
    context.front_contract = vx_chain[0]

    frontcarsym = context.front_contract.symbol
    context.assets = future_symbol( 'VXN17' )
    #context.assets = future_symbol( frontcarsym )
    #context.assets = future_symbol( vx_chain[0].symbol )
    #context.assets = future_symbol( context.front_contract.symbol )
    #context.assets = future_symbol( data.current_chain( continuous_future('VX'))[0].symbol)
    #comment out above lines 12-15 to get algorithm to Build.
    

'''
    Trying to use the "future_symbol()" function to return a specific object in the futures chain. Usage like "future_symbol( 'VXN17')" works fine. However, as soon as "future_symbol( variable )" or "future_symbol( reference )" is used, the following error is returned:

>     Error    InvalidFutureSymbolCall: 0077 symbol argument must be a string.

Okay, so that seems weird that you can't pass the symbol you want to return into future_symbol(). What's even weirder is that using the IDE Debugger, everything works fine.

In the attached Algorithm, line 11 works fine. Lines 12-15 throw the error. If you comment out lines 12-15 and use the Debugger to manually enter each one, they all work perfectly fine.

So it doesn't work when the Algo builds, but it works fine in the Debugger.....Can anyone else what is going on or a workaround?
'''
There was a runtime error.
5 responses

Found this Thread from back in October referencing similar findings. Built a string map to assist in returning history from future_symbol(): https://www.quantopian.com/posts/how-to-get-future-price-beyond-its-auto-close-date . Does not address how passing variables is allowed in Debugger, but not in algorithm.

Hii Chris Just wondering if you solve this? I’ve encountered the same issue. Thank you so much.

Hii Chris Just wondering if you solve this? I’ve encountered the same issue. Thank you so much.

Nope, unfortunately nothing. I thought I was pretty explicit in my explanation too, but Quantopian didn't acknowledge. Please post here if you find a solution as I am still curious how to resolve it.

As you noticed, the 'future_symbol' method works a bit different in the IDE vs the notebook environment. The symbol argument must be a string, and not a variable, in the IDE. Not really a way to work around this.

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.