Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Standard deviation with VWAP

I need help with this code. I am trying to get standard deviation for the VWAP and I dont think it coming coming out right. Can let me know what I can do to improve my code?

import numpy  as np  
import pandas as pd  
import math as m  
import talib

def initialize(context):  
    context.security = sid(26807)


def handle_data(context, data):  
    open_orders = get_open_orders()  
    hist = data.history(context.security, ['price', 'volume'], 240, '1d')[:-1]  
    hist2 = data.history(context.security, ['price','volume'], 1, '1d')  
    vwap1 = (hist['price'] * hist['volume']).sum() / hist['volume'].sum()  
    price = data.current(context.security, "price")  
    vol= data.current(context.security, "volume")  
    totvol = hist['volume'].sum()  
    var = (vol/totvol) * (price - vwap1) * (price - vwap1)  
    std_upper_1 = vwap1 + m.sqrt(var)  
    std_lower_1 = vwap1 - m.sqrt(var)  
    std_upper_2 = vwap1 + m.sqrt(var) *2  
    std_lower_2 = vwap1 - m.sqrt(var) *2  



    if price > vwap1:  
        if context.security not in open_orders:  
            order_target_percent(context.security, 1.0)  
    if price < vwap1:  
        if context.security not in open_orders:  
            order_target_percent(context.security, -1.0)