Back to Community
-24 Trillion % Returns?

If I get a negative return of -24,000,000,000,000% does that mean I lost it all?

I suppose that I could just do the opposite factors/strategy and that should return good results, right?

Clone Algorithm
1
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
from quantopian.algorithm import order_optimal_portfolio
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import SimpleMovingAverage
from quantopian.pipeline.filters import QTradableStocksUS
import quantopian.optimize as opt


def initialize(context):
    
    context.spy = sid(8554)
    context.trends = []    
    schedule_function(
        my_rebalance,
        date_rules.every_day(),
        time_rules.market_close()
    )
#    schedule_function(record_vars, date_rules.every_day(), time_rules.market_close())
    my_pipe = make_pipeline()
    attach_pipeline(my_pipe, 'my_pipeline')

    
def make_pipeline():

    base_universe = QTradableStocksUS()

    mean_10 = SimpleMovingAverage(
        inputs=[USEquityPricing.close],
        window_length=3,
        mask=base_universe
    )

    mean_30 = SimpleMovingAverage(
        inputs=[USEquityPricing.close],
        window_length=10,
        mask=base_universe
    )

    percent_difference = (mean_10 - mean_30) / mean_30

    bottom_rev = percent_difference.bottom(500)
#    bottom_rev = 
    mean_A = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=10, mask=bottom_rev)
    mean_B = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=5, mask=bottom_rev)
    mean_C = USEquityPricing.close.latest
    

    
    CA = mean_C < mean_A
    AB = mean_A < mean_B
    longs = CA & AB

    securities_to_trade = longs

    return Pipeline(
        columns={
            'longs': longs,
        },
        screen=(securities_to_trade),
    )


def compute_target_weights(context, data):

    pipe_results = pipeline_output('my_pipeline')
    
    weight = 1.0 / len(pipe_results.keys())
    weights = {}
    for security in context.portfolio.positions:
        if security not in pipe_results.keys() and data.can_trade(security):
            weights[security] = 0

    for security in pipe_results.keys():
        weights[security] = weight

    return weights 


def record_vars(context, data):
    record(msft=data.current(sid(5061), 'price'), aapl=data.current(sid(24), 'price'))


def my_rebalance(context, data):

    pipe_results = pipeline_output('my_pipeline')
    total = len(pipe_results)
#    target_weights = compute_target_weights(context, data)
    if total != 0:
        weight = 1.0 / len(pipe_results)
    else:
        weight = 0
    open_orders = get_open_orders()
    if open_orders: 
        for security, orders in open_orders.items(): 
            for oo in orders:
                message = 'Open order for {amount} shares in {stock}'
                message = message.format(amount=oo.amount, stock=security)
                log.info(message)
    if not pipe_results.keys() in list(get_open_orders().keys()):  
        for i in range(len(pipe_results)):
 #           log.info(str(pipe_results))
 #            log.info(str(pipe_results.keys()))            
 #            log.info(str(len(pipe_results)))
            log.info(str(i))
            log.info(str(pipe_results.keys()))
            log.info(pipe_results.index[i])
            log.info(total)
            log.info(weight)

            log.info(type(pipe_results))
            order_target_percent(pipe_results.index[i], weight)
There was a runtime error.
1 response

USE PROPER LEVERAGE