Back to Community
Not sure why this wont run.

New to both python and Quant. I've been looking at this for hours/referencing google for syntax related to lists and initialization. Totally stumped.

def initialize(context):

import pandas as pd  
import numpy as np  
tpos = ['sold', 'sold', 'sold', 'sold', 'sold'];  
context.t = sid(6653);  

def handle_data(context, data):
MA3D = data.history(context.t, 'price', 3, '1d').mean()
MA3M = data.history(context.t, 'price', 3, '1m').mean()
boughts = tpos.count('bought');
solds = tpos.count('sold');

if boughts < 5: ###buy  
    if MA3M <= MA3D:  
        order_shares(6653, 100)  
        tpos[1] = 'bought'  
        context.bp = data.current(context.t, 'price')  

if solds < 5:  
    if data.current(context.t, 'price') > context.bp:  
        order_target_percent(context.t,-0.20)  
        tpos[1] = 'sold'

My goal is basically to develop a simple algo which trades a few sets of a specific stock at a time based on price. I'm aware this isn't a winning strategy. This algo is only intended as a means of studying success of simple buy sell stategies as a basis for developing future quant algos.

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
# Backtest ID: 5a1e3b7e0adb494140b9bbf6
There was a runtime error.