Back to Posts
Listen to Thread

Greetings! I'm currently trying to convert the Python algorithm that I made on Quantopian into JavaScript. Here's a simplistic example taken from one of Quantopian's examples:

var initialize = function() {  
    var __kwargs = __kwargs_get(arguments);  
    var __varargs = __varargs_get(arguments);  
    var $v1 = Array.prototype.slice.call(arguments).concat(js(__varargs));  
    var context = ('context' in __kwargs) ? __kwargs['context'] : $v1[0];  
    context.PY$__setattr__('appl', sid(int(24)));  
    context.PY$__setattr__('max_notional', float(1000000.1));  
    context.PY$__setattr__('min_notional', float(-1000000.0));  
return None;  
}
var handle_data = function() {  
    var __kwargs = __kwargs_get(arguments);  
    var __varargs = __varargs_get(arguments);  
    var $v2 = Array.prototype.slice.call(arguments).concat(js(__varargs));  
    var context = ('context' in __kwargs) ? __kwargs['context'] : $v2[0];  
    var data = ('data' in __kwargs) ? __kwargs['data'] : $v2[1];  
    var vwap = data.PY$__getitem__(context.PY$__getattr__('appl')).PY$__getattr__('vwap')($c3);  
    var price = data.PY$__getitem__(context.PY$__getattr__('appl')).PY$__getattr__('price');  
    var notional = context.PY$__getattr__('portfolio').PY$__getattr__('positions').PY$__getitem__(context.PY$__getattr__('appl')).PY$__getattr__('amount').PY$__mul__(price);  
    if (bool(js(price.PY$__lt__(vwap.PY$__mul__(float(0.995)))) && js(notional.PY$__gt__(context.PY$__getattr__('min_notional')))) === True) {  
        order(context.PY$__getattr__('appl'), int(-100));  
    } else {  
        if (bool(js(price.PY$__gt__(vwap.PY$__mul__(float(1.005)))) && js(notional.PY$__lt__(context.PY$__getattr__('max_notional')))) === True) {  
            order(context.PY$__getattr__('appl'), int(100).PY$__pos__());  
        }  
    }  
return None;  
}

Is this the best way to do it? Are there any errors? How would I go about efficiently integrating Quantopian libraries? Any help is greatly appreciated!

Hi Taylor, can you give some more context about what you're trying to do?

The Quantopian IDE / backtester only supports algorithms written in Python, because we execute them in a Python environment on our servers. Our backtester (Zipline) is standalone, but requires a lot of the scientific Python stack.

In summary, I don't think there's a good place to run your javascript-based algorithms.

Jean

Yes; I'm trying to port the Python-based algorithms to JavaScript to run them on a custom environment I've already setup (that's also JavaScript :P). I'm currently porting Zipline into JavaScript to use in conjunction w/ my computational program. Essentially, the ported Zipline and some other utilities will handle the calculation side of the algorithms and my custom plotter will chart those algorithms in an efficient manor. If this can be pulled off, then we no longer have to keep playing around w/ stock data that already exists, and project future outcomes w/ any kind of stock, including ones that aren't supported by Quantopian's database! There are tons of other programming languages that JavaScript can compile into and vice-versa as well! Also, JavaScript-related programs have the ability to actually monitor stock progressions as they occur!

Log in to reply to this thread.
Not a member? Sign up!