Back to Community
New Strategy - Turnaround Tuesday

as a beginner, I am searching for various strategies online. This is the one I just saw yesterday.

https://decodingmarkets.com/testing-turnaround-tuesday/

Based on the author's idea, I tried to reproduce this strategy on Quantopian. the return is not bad, and volatility is really good.

Here are my code and backtesting. It is pretty the same result.

Looking forward to the comments and improvement.

Clone Algorithm
65
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
"""
This is a template algorithm on Quantopian for you to adapt and fill in.
"""
import quantopian.algorithm as algo
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.filters import QTradableStocksUS


def initialize(context):
    """
    Called once at the start of the algorithm.
    """
    set_commission(commission.PerShare(cost=0.0075, min_trade_cost=1.0))
    set_slippage(slippage.VolumeShareSlippage(volume_limit=0.025, price_impact=0.1))

    # Create our dynamic stock selector.
    #algo.attach_pipeline(make_pipeline(), 'pipeline')
    context.stocks = sid(8554)
    context.order_monday = False 
    context.my_open=0
    
    schedule_function(rebalance, date_rules.week_start() , time_rules.market_close(minutes=1))
    schedule_function(rebalance, date_rules.week_start(days_offset=1) , time_rules.market_close(minutes=1))
    schedule_function(handle_data_daily, date_rules.every_day(), time_rules.market_open(minutes=1))  
    
    

def handle_data_daily(context, data):  
    context.my_open=data.current(context.stocks, "price")  
    
    
def make_pipeline():
    """
    A function to create our dynamic stock selector (pipeline). Documentation
    on pipeline can be found here:
    https://www.quantopian.com/help#pipeline-title
    """

    # Base universe set to the QTradableStocksUS
    base_universe = QTradableStocksUS()

    # Factor of yesterday's close price.
    yesterday_close = USEquityPricing.close.latest

    pipe = Pipeline(
        columns={
            'close': yesterday_close,
        },
        screen=base_universe
    )
    return pipe


def before_trading_start(context, data):
    """
    Called every day before market open.
    """
    pass

def rebalance(context, data):
    """
    Execute orders according to our schedule_function() timing.
    """
    current_price = data.current(context.stocks, "price")  
    current_date=data.current(context.stocks,'last_traded')
    current_close=current_price
    current_open=context.my_open

    long_mavg = data.history(context.stocks, 'price', 200, '1d').mean()
    if current_open>long_mavg:
        pass
        
    if current_date.weekday()==0:
        #print(current_date)
        #print("Monday")
        
        rate = (current_close/current_open)-1
        #print("current_close")
        #print(current_close)
        #print("current_open")
        #print(current_open)
        #print("rate")
        #print(rate)
        if rate<-0.01:
            #print("place order")
            order_id= order_target_percent(context.stocks,1)
            #print((get_order(order_id)))
            context.order_monday = True
            
        if rate>0.01:
            #print("place order")
            order_target_percent(context.stocks,-1)
            #print((get_order(order_id)))
            context.order_monday = True
        
        
    
    if current_date.weekday()==1 and context.order_monday==True:
        order_id=order_target_percent(context.stocks, 0)
        #print((get_order(order_id)))
        context.order_monday = False


def record_vars(context, data):
    """
    Plot variables at the end of each day.
    """
    pass


def handle_data(context, data):
    """
    Called every minute.
    """
    pass
There was a runtime error.