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...
Backtest from to with initial capital
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.
1 response

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.