catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

"cannot pass '-D' / '--define' without '-t' / '--algotext'"

Open yeshymanoharan opened this issue 7 years ago • 3 comments

Dear Catalyst Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

  • Operating System: MacOS Sierra Darwin Kernel Version 16.6.0
  • Python Version: python 2.7
  • Python Bitness: 64
  • How did you install Catalyst: pip
  • Python packages: alembic==0.9.6 backports.functools-lru-cache==1.4 bcolz==0.12.1 boto3==1.5.7 botocore==1.8.21 Bottleneck==1.2.1 ccxt==1.10.544 certifi==2017.11.5 chardet==3.0.4 click==6.7 contextlib2==0.5.5 cycler==0.10.0 cyordereddict==1.0.0 Cython==0.27.3 decorator==4.1.2 docutils==0.14 empyrical==0.2.1 enigma-catalyst==0.4.0 futures==3.2.0 idna==2.6 intervaltree==2.1.0 jmespath==0.9.3 Logbook==1.1.0 lru-dict==1.1.6 Mako==1.0.7 MarkupSafe==1.0 matplotlib==2.1.0 multipledispatch==0.4.9 networkx==2.0 numexpr==2.6.4 numpy==1.13.3 pandas==0.19.2 pandas-datareader==0.5.0 patsy==0.4.1 pyparsing==2.2.0 python-dateutil==2.6.1 python-editor==1.0.3 pytz==2017.3 PyYAML==3.12 requests==2.18.4 requests-file==1.4.2 requests-ftp==0.3.1 s3transfer==0.1.12 scipy==1.0.0 six==1.11.0 sortedcontainers==1.5.9 SQLAlchemy==1.2.0 statsmodels==0.8.0 subprocess32==3.2.7 TA-Lib==0.4.10 tables==3.4.2 toolz==0.9.0 urllib3==1.22

Now that you know a little about me, let me tell you about the issue I am having:

I am making a batch scheduler that backtests the algorithms that I have developed for use with catalyst in multiple conditions. The goal is to be able to run the scheduler file from the command line, $ python Scheduler.py, and have this Scheduler file make a bash line 'catalyst run ...' and then run it using the python subprocess function. I thought about using the run_algo function, but I wanted to keep the catalyst installation and the trading algorithms separate, and there seemed to be an issue with handling bundles in that case. I wanted to be able to pass in global variables so that the algorithm could be slightly modified to analyze performance. For example, if I were using RSI as a metric, then I wanted to pass in different values for an RSI threshold that determined buy and sell signals. However, I was not able to use the define flag if I did not use algotext, or if I used the -f flag for files instead.

Here is how you can reproduce this issue on your machine: $ catalyst run -f algorithm.py ...(all of the required arguments)... -d global_variable=1

What steps have you taken to resolve this already?

I modified the run_algo.py file found in catalyst/catalyst/utils to remove the code that prevented the defines flag from being used if algotext was not called. This worked for me, and so far, I have not encountered any issues with the change.

The limitation that the defines flag currently has seemed unnecessarily restrictive, so I wanted to bring this issue up in the hopes that my change will be adopted. My modified run_algo.py file has been attached to this issue page so that it can be tested. run_algo.py.zip

Sincerely, Yeshy

yeshymanoharan avatar Jan 06 '18 22:01 yeshymanoharan

Thanks! We'll look into it and apply the changes as appropriate.

fredfortier avatar Jan 07 '18 00:01 fredfortier

Hi there thanks for the advice @yeshymanoharan ! Noob-question coming through:

Could you perhaps explain how you catch those 'global-variables' within the algorithm.py ? For example, when you run this $ catalyst run -f algorithm.py ...(all of the required arguments)... -d GLOBAL_VARIABLE=1

how do you use it in the algorithm.py ? Have been trying out for something like this but it doesnt work..

def initialize(context): context.global_variable = GLOBAL_VARIABLE

markofferman avatar Feb 11 '19 14:02 markofferman

Disregard, did not use your run_algo.py.zip file! Works like a charm.

markofferman avatar Feb 11 '19 16:02 markofferman