Back to Community
help with deprecated warnings while selling insurance against a crash

thanks

1 response

If you'd like to get the prior day's close price you'll want to use the data.history() method with "1d" as the frequency parameter. The most recent bar in the returned data structure is the same value returned by data.current, the other bars are the close prices from previous days.

The logs in this algo should help clarify what's going on.

Clone Algorithm
4
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):
    context.spy = symbol('SPY')
    schedule_function(market_close, time_rule=time_rules.market_close())
 
           

def market_close(context, data):
    dt = get_datetime()
    current_px = data.current(context.spy, 'close')
    historical_prices = data.history(context.spy, 'close', 2, '1d')
    
    msg = "\nCurrent price = {}".format(current_px)
    msg += "\nMost recent history = {}".format(historical_prices.iloc[-1])
    msg += "\nYesterdays Close = {}".format(historical_prices.iloc[-2])
    log.info(msg)
    
    
def handle_data(context,data):
    pass          
    
There was a runtime error.