Back to Community
Converting Quantopian Python scripts into JavaScript?

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 =;  
    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 =;  
    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!

2 responses

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.



The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

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!