Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jay-johnson/988e74f24a7c1949b0eeb1f636f05274 to your computer and use it in GitHub Desktop.
Save jay-johnson/988e74f24a7c1949b0eeb1f636f05274 to your computer and use it in GitHub Desktop.
Run an Equity Algorithm using the Stock Analysis Engine
import pandas as pd
from analysis_engine.algo import EquityAlgo
ticker = 'SPY'
demo_algo = EquityAlgo(
ticker=ticker,
balance=1000.00,
commission=6.00,
name='test-{}'.format(ticker))
date_key = '{}_2018-11-05'.format(
ticker)
# mock the data pipeline in redis:
data = {
ticker: [
{
'date': date_key,
'data': {
'daily': pd.DataFrame([
{
'high': 280.01,
'low': 270.01,
'open': 275.01,
'close': 272.02,
'volume': 123,
'date': '2018-11-01 15:59:59'
},
{
'high': 281.01,
'low': 271.01,
'open': 276.01,
'close': 273.02,
'volume': 124,
'date': '2018-11-02 15:59:59'
},
{
'high': 282.01,
'low': 272.01,
'open': 277.01,
'close': 274.02,
'volume': 121,
'date': '2018-11-05 15:59:59'
}
]),
'minute': pd.DataFrame([]),
'news': pd.DataFrame([]),
'options': pd.DataFrame([])
# etc
}
}
]
}
# run the algorithm
demo_algo.handle_data(data=data)
# get the algorithm results
results = demo_algo.get_result()
print(results)
@virdesai
Copy link

virdesai commented Nov 8, 2018

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment