2.3 EoM

The ease of movement indicator considers both market direction and volume. A large positive (negative) value indicates a large movement occurred on high volume.

This notebook defines formulas which add an EoM column. Some strategies will use these formulas to define bull and bear signals.

Import Packages

In [1]:
import numpy as np
import pandas as pd
import cPickle as pickle
shortUniverse = True

Load Pickle Data

First, we’ll load the pickle we developed in the previous section. The new prices dataframe is given a new name to reflect edits made during this notebook.

In [2]:
if shortUniverse:
    with open('intermediaries/prices.p', 'rb') as handle:
        prices = pickle.load(handle)
else:
    with open('intermediaries/prices-full.p', 'rb') as handle:
        prices = pickle.load(handle)

Development of EoM

The following formula adds an RSI column to a price dataframe. The calculation adds intermediate columns called ‘dist’, ‘box’ and ‘EV1’. The lattermost is smoothed using a 14-day (by default) simple moving average to create ‘EoM’.

In [3]:
def add_EoM(df, lag=14):
    df['medPrice'] = (df['high'] + df['low'])/2
    df['dist'] = df['medPrice'] - df.groupby('symbol')['medPrice'].shift(1)
    df['box'] = (df['volume']/1e8)/(df['high'] - df['low'])
    df['EV1'] = df['dist'] / df['box']
    df['EoM'] = df.groupby('symbol')['EV1'].apply(pd.rolling_mean, lag)
    df = df.drop(['medPrice', 'dist', 'box', 'EV1'], axis=1)
    return df
In [4]:
prices = add_EoM(prices)

Output Example

The first 11th through 20th observations are displayed below.

In [5]:
prices.head(20).tail(10)
Out[5]:
sector symbol open high low close volume ret_cc ret_oc ret_co EoM
Date
2015-01-16 XLP PG 86.347025 87.681347 86.270235 87.594956 8815700 0.015350 0.014349 1.001012e-03 NaN
2015-01-20 XLP PG 87.594956 88.113327 86.874997 87.537361 9869900 -0.000658 -0.000658 -2.381447e-09 NaN
2015-01-21 XLP PG 86.779006 87.537362 86.039843 87.095788 6974500 -0.005057 0.003644 -8.700966e-03 NaN
2015-01-22 XLP PG 88.014947 88.643350 86.883826 88.575677 7211200 0.016849 0.006351 1.049813e-02 NaN
2015-01-23 XLP PG 88.140625 88.159964 86.961162 87.086847 6745700 -0.016951 -0.012028 -4.923751e-03 NaN
2015-01-26 XLP PG 86.961162 86.961162 85.791368 86.603461 9371700 -0.005566 -0.004122 -1.444257e-03 0.108978
2015-01-27 XLP PG 84.205862 84.312208 83.161747 83.616131 14417400 -0.035103 -0.007028 -2.807524e-02 -0.045320
2015-01-28 XLP PG 83.751478 84.022181 82.185312 82.320660 14033400 -0.015614 -0.017232 1.617366e-03 -0.131708
2015-01-29 XLP PG 82.929723 83.248759 82.320659 82.823377 12054500 0.006088 -0.001283 7.371424e-03 -0.382432
2015-01-30 XLP PG 82.262648 82.388333 81.450563 81.489235 14685300 -0.016239 -0.009446 -6.793194e-03 -0.439680

Save Formulas

No new price file is created. However, add_EoM has been added to the separate document “helper_functions.py” which can be imported into future tests.

Potential Extensions

This space is reserved.