Back to Community
Simple way Algorithms about "Short VIXY"

Simple way Algorithms about "Short VIXY"

Clone Algorithm
6
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
"""
Short VIXY base on how much it rise from bottom
"""
from quantopian.algorithm import attach_pipeline, pipeline_output
 
def initialize(context):
    """
    Called once at the start of the algorithm.
    """   
    context.vxx = symbol('VIXY')
    #1.2 means rise 20% from bottom
    context.shortSthartPercent = 1.2
    #how many position to short
    context.shortPositionPercent = -0.25
    #how much percent profit when to cover short position
    context.coverPricePercent = 0.15
    
    context.beforeShortPrice = 0
    context.minPrice = 100
    context.prePrice = 0
    # Before Market 3 minute do action
    schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_close(minutes=3))
     
 
def my_rebalance(context,data):
    """
    Execute orders according to our schedule_function() timing. 
    """
    today_price = data.history(context.vxx, "price", 1, "1m")[-1]
    #split check
    if today_price > context.prePrice * 2:
        context.minPrice = context.minPrice * 5
        context.beforeShortPrice = context.beforeShortPrice * 5
    if today_price < context.minPrice:
        context.minPrice = today_price
    if today_price >= context.minPrice * context.shortSthartPercent and context.portfolio.positions[context.vxx].amount == 0:
        if data.can_trade(context.vxx):
            order_target_percent(context.vxx, context.shortPositionPercent)
        context.beforeShortPrice = today_price
    if context.portfolio.positions[context.vxx].amount != 0 and today_price <= context.beforeShortPrice * (1-context.coverPricePercent):
        if data.can_trade(context.vxx):
            order_target_percent(context.vxx, 0)
        
    context.prePrice = today_price    
    pass
There was a runtime error.