Back to Community
How do I write and import my own modules that I can share in my algos

Hi,

I am new on quantopian. I have not found anything about how to write modules that I can import into my algos instead of copy and pasting code from other algos. Does anyone know the answer?

Thanks,
Norbert

8 responses

Hi Norbert,
So we currently do not support importing custom modules into your algorithm. However, we do support a number of modules listed here: https://www.quantopian.com/help#ide-module-import. If you need a specific module that we don't currently support, feel free to make a suggestion and we can look into adding it.

I'm not sure how new to Python you are, so here is a good guide if you're getting started: http://www.codecademy.com/tracks/python. Please excuse me if you're not new to Python as well!

Gus

Disclaimer

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.

Hi Gus,

I am not new to python. That's why I am asking. It is considered good coding style to put every bit of code that is generic enough into some lib to avoid duplicated code. How do you support this paradigm.

Thanks,
Norbert

Hello Norbert - Unfortunately, we don't support that yet. We don't have rich code management system. If you have a useful function in one algo, and you want to use it in a second algo, your only option is to copy and paste it.

We get a number of requests for stronger code management tools, and we totally agree. It's just not built yet.

Disclaimer

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.

Bump.
Or expose a function in the Quantopian lib that loads modules,code from e.g. /data/modules folder.
A REST Api would be great too.

BUMP (prays to bump gods)

Ugly Hack Temporary Solution:

  1. Code a separate website to login and read your own algorithm (not sure if allowed or possible, only one way to find out)
  2. Make web code to create a csv file with a column for the FunctionName, FunctionParameters, and FunctionText.
  3. Save csv to own site
  4. Fetch csv
  5. Write code to easily turn fetched code into executable code.
    Basic example:
    def custom_exec(function_name, params):
    imported_code = write_param_declaration_snippet(function_name, params) + retrieve_function_body(function_name)
    return exec imported_code

BUT, FROM CODER TO CODER, MY GOOD FRIEND QUANTOPIAN, YOU MUST EVERY DAY DEAL WITH THE GUILT OF KNOWING A USER IS IMPLEMENTING SUCH AN UGLY HACK.

Yea where is this.
We want things like
- Proper git management for branching etc
- Proper module management so we can import, chop and change using our own functions
- A proper test environment to be able to unit test sections of our code

If we are going to be serious about making a profitable algorithm, then these things are basically necessary.
Git can be done by managing our code offline, and then somehow executing it online (I don't know how to do this yet but I hear it may be possible with zipline etc).
Module management just requires that we don't use the Quantopian IDE.
A test environment means we need access to data really, kind of like how the notebooks work.

Is there some kind of Quantopian API that we can send code to, and get various results back? For example the notebook code blocks?

Would be great to be able to write our own libraries / modules instead of having to copy and paste.

Version control would be great too.

Bumpity bumpy bump.

Just my 2C... I understand adding code mgmt is non-trivial and you really need automated regression testing for users as well. Without these features I don't see how a serious quant trader can use the platform beyond a tinkering side project ( and be confident in the quality and correctness of their code ).

Is it something that is being actively worked on? Would be really cool.