Run an Algorithm

Run an Algo

Supported environment variables

export REDIS_ADDRESS="localhost:6379"
export REDIS_DB="0"
export S3_ADDRESS="localhost:9000"
export S3_BUCKET="dev"
export AWS_ACCESS_KEY_ID="trexaccesskey"
export AWS_SECRET_ACCESS_KEY="trex123321"
export AWS_DEFAULT_REGION="us-east-1"
export S3_SECURE="0"
export WORKER_BROKER_URL="redis://0.0.0.0:6379/13"
export WORKER_BACKEND_URL="redis://0.0.0.0:6379/14"

# to show debug, trace logging please export ``SHARED_LOG_CFG``
# to a debug logger json file. To turn on debugging for this
# library, you can export this variable to the repo's
# included file with the command:
export SHARED_LOG_CFG=/opt/sa/analysis_engine/log/debug-logging.json
analysis_engine.run_algo.run_algo(ticker=None, tickers=None, algo=None, balance=None, commission=None, start_date=None, end_date=None, datasets=None, num_owned_dict=None, cache_freq='daily', auto_fill=True, load_config=None, report_config=None, history_config=None, extract_config=None, use_key=None, extract_mode='all', iex_datasets=None, redis_enabled=True, redis_address=None, redis_db=None, redis_password=None, redis_expire=None, redis_key=None, s3_enabled=True, s3_address=None, s3_bucket=None, s3_access_key=None, s3_secret_key=None, s3_region_name=None, s3_secure=False, s3_key=None, celery_disabled=True, broker_url=None, result_backend=None, label=None, name=None, timeseries=None, trade_strategy=None, verbose=False, publish_to_slack=True, publish_to_s3=True, publish_to_redis=True, extract_datasets=None, config_file=None, config_dict=None, version=1, raise_on_err=True, **kwargs)[source]

Run an algorithm with steps:

  1. Extract redis keys between dates
  2. Compile a data pipeline dictionary (call it data)
  3. Call algorithm’s myalgo.handle_data(data=data)

Note

If no algo is set, the analysis_engine.algo.BaseAlgo algorithm is used.

Note

Please ensure Redis and Minio are running before trying to extract tickers

Stock tickers to extract

Parameters:
  • ticker – single stock ticker/symbol/ETF to extract
  • tickers – optional - list of tickers to extract
  • use_key – optional - extract historical key from Redis

Algo Configuration

Parameters:
  • algo – derived instance of analysis_engine.algo.Algo object
  • balance – optional - float balance parameter can also be set on the algo object if not set on the args
  • commission – float for single trade commission for buy or sell. can also be set on the algo objet
  • start_date – string YYYY-MM-DD_HH:MM:SS cache value
  • end_date – string YYYY-MM-DD_HH:MM:SS cache value
  • dataset_types – list of strings that are iex or yahoo datasets that are cached.
  • cache_freq – optional - depending on if you are running data feeds on a daily cron (default) vs every minute (or faster)
  • num_owned_dict – not supported yet
  • auto_fill – optional - boolean for auto filling buy/sell orders for backtesting (default is True)
  • trading_calendartrading_calendar.TradingCalendar object, by default analysis_engine.calendars. always_open.AlwaysOpen trading calendar # TradingCalendar by TFSExchangeCalendar
  • config_file – path to a json file containing custom algorithm object member values (like indicator configuration and predict future date units ahead for a backtest)
  • config_dict – optional - dictionary that can be passed to derived class implementations of: def load_from_config(config_dict=config_dict)

Timeseries

Parameters:timeseries – optional - string to set day or minute backtesting or live trading (default is minute)

Trading Strategy

Parameters:trade_strategy – optional - string to set the type of Trading Strategy for backtesting or live trading (default is count)

Algorithm Dataset Loading, Extracting, Reporting and Trading History arguments

Parameters:
  • load_config – optional - dictionary for setting member variables to load an agorithm-ready dataset from a file, s3 or redis
  • report_config – optional - dictionary for setting member variables to publish an algo trading performance report to s3, redis, a file or slack
  • history_config – optional - dictionary for setting member variables to publish an algo trade history to s3, redis, a file or slack
  • extract_config – optional - dictionary for setting member variables to publish an algo trading performance report to s3, redis, a file or slack

(Optional) Data sources, datafeeds and datasets to gather

Parameters:iex_datasets – list of strings for gathering specific IEX datasets which are set as consts: analysis_engine.iex.consts.FETCH_*.

(Optional) Redis connectivity arguments

Parameters:
  • redis_enabled – bool - toggle for auto-caching all datasets in Redis (default is True)
  • redis_address – Redis connection string format is host:port (default is localhost:6379)
  • redis_db – Redis db to use (default is 0)
  • redis_password – optional - Redis password (default is None)
  • redis_expire – optional - Redis expire value (default is None)
  • redis_key – optional - redis key not used (default is None)

(Optional) Minio (S3) connectivity arguments

Parameters:
  • s3_enabled – bool - toggle for auto-archiving on Minio (S3) (default is True)
  • s3_address – Minio S3 connection string format host:port (default is localhost:9000)
  • s3_bucket – S3 Bucket for storing the artifacts (default is dev) which should be viewable on a browser: http://localhost:9000/minio/dev/
  • s3_access_key – S3 Access key (default is trexaccesskey)
  • s3_secret_key – S3 Secret key (default is trex123321)
  • s3_region_name – S3 region name (default is us-east-1)
  • s3_secure – Transmit using tls encryption (default is False)
  • s3_key – optional s3 key not used (default is None)

(Optional) Celery worker broker connectivity arguments

Parameters:
  • celery_disabled – bool - toggle synchronous mode or publish to an engine connected to the Celery broker and backend (default is True - synchronous mode without an engine or need for a broker or backend for Celery)
  • broker_url – Celery broker url (default is redis://0.0.0.0:6379/13)
  • result_backend – Celery backend url (default is redis://0.0.0.0:6379/14)
  • label – tracking log label
  • publish_to_slack – optional - boolean for publishing to slack (coming soon)
  • publish_to_s3 – optional - boolean for publishing to s3 (coming soon)
  • publish_to_redis – optional - boolean for publishing to redis (coming soon)

(Optional) Debugging

Parameters:
  • verbose – bool - show extract warnings and other debug logging (default is False)
  • raise_on_err – optional - boolean for unittests and developing algorithms with the analysis_engine.run_algo.run_algo helper. When set to True exceptions will are raised to the calling functions
  • kwargs – keyword arguments dictionary