Example Minute Intraday Algorithm

Example Minute Algorithm for showing how to run an algorithm on intraday minute timeseries datasets

What does the base class provide?

Algorithms automatically provide the following member variables to any custom algorithm that derives the analysis_engine.algo.BaseAlgo.process method.

By deriving the process() member method using an inherited class, you can quickly build algorithms that determine buy and sell conditions from any of the automatically extracted datasets from the redis pipeline:

  • self.df_daily
  • self.df_minute
  • self.df_calls
  • self.df_puts
  • self.df_quote
  • self.df_pricing
  • self.df_stats
  • self.df_peers
  • self.df_iex_news
  • self.df_financials
  • self.df_earnings
  • self.df_dividends
  • self.df_company
  • self.df_yahoo_news

Recent Pricing Information

  • self.latest_close
  • self.latest_high
  • self.latest_open
  • self.latest_low
  • self.latest_volume
  • self.ask
  • self.bid

Latest Backtest Date and Intraday Minute

  • self.latest_min
  • self.backtest_date

Note

self.latest_min - Latest minute row in self.df_minute

Note

self.backtest_date - Latest dataset date which is considered the backtest date for historical testing with the data pipeline structure (it’s the date key in the dataset node root level)

Balance Information

  • self.balance
  • self.prev_bal

Note

If a key is not in the dataset, the algorithms’s member variable will be an empty pandas DataFrame created with: pd.DataFrame([]) except self.pricing which is just a dictionary. Please ensure the engine successfully fetched and cached the dataset in redis using a tool like redis-cli and a query of keys * or keys <TICKER>_* on large deployments.

Supported environment variables

# 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
class analysis_engine.mocks.example_algo_minute.ExampleMinuteAlgo(**kwargs)[source]
get_result()[source]
process(algo_id, ticker, dataset)[source]

Derive custom algorithm buy and sell conditions before placing orders. Just implement your own process method.

Parameters:
  • algo_id – string - algo identifier label for debugging datasets during specific dates
  • ticker – string - ticker
  • dataset

    a dictionary of identifiers (for debugging) and multiple pandas pd.DataFrame objects. Dictionary where keys represent a label from one of the data sources (IEX, Yahoo, FinViz or other). Here is the supported dataset structure for the process method:

    Note

    There are no required keys for data, the list below is not hard-enforced by default. This is just a reference for what is available with the v1 engine.

    dataset = {
        'id': <string TICKER_DATE - redis cache key>,
        'date': <string DATE>,
        'data': {
            'daily': pd.DataFrame([]),
            'minute': pd.DataFrame([]),
            'quote': pd.DataFrame([]),
            'stats': pd.DataFrame([]),
            'peers': pd.DataFrame([]),
            'news1': pd.DataFrame([]),
            'financials': pd.DataFrame([]),
            'earnings': pd.DataFrame([]),
            'dividends': pd.DataFrame([]),
            'calls': pd.DataFrame([]),
            'puts': pd.DataFrame([]),
            'pricing': dictionary,
            'news': pd.DataFrame([])
        }
    }
    

    example:

    dataset = {
        'id': 'SPY_2018-11-02
        'date': '2018-11-02',
        'data': {
            'daily': pd.DataFrame,
            'minute': pd.DataFrame,
            'calls': pd.DataFrame,
            'puts': pd.DataFrame,
            'news': pd.DataFrame
        }
    }
    
analysis_engine.mocks.example_algo_minute.get_algo(**kwargs)[source]

Make sure to define the get_algo for your custom algorithms to work as a backup with the sa.py tool… Not anticipating issues, but if we do with importlib this is the backup plan.

Please file an issue if you see something weird and would like some help: https://github.com/AlgoTraders/stock-analysis-engine/issues

Parameters:kwargs – dictionary of keyword arguments