launch_financial_batch_process
Description
Enterprise users only.
Launch a batch financial process. A batch process is a group of experiments.
Simple Example
import datetime
financialNetworkDef = {}
st = datetime.datetime(2010,1,4,10,0,0)
et = datetime.datetime(2010,2,4,11,0,0)
financialNetworkDef['securities_emitter'] = {'dependencies':{'input':['AAPL','KO']}}
financialNetworkDef['time_emitter'] = {'dependencies':{'input':None,
'start_date':st,
'end_date':et,
'increment':['minutes',1],
'mode':'backtest', }
}
financialNetworkDef['strategy'] = {'name':'strategy',
'type':'FixedAllocationStrategy',
'dependencies':{'input':{
'time':['__ref','time_emitter','output'],
'securities':['__ref','securities_emitter','output'],
'marketos':['__ref','marketos'],
'profit_take':1.01,
'profit_stop':0.995,
'core_min': 0.25,
'core_max': 10,
'core_step': 2,
'base_trade_portion': 0.25,
'secs_bias':{'AAPL':0.5,'KO':0.5,'cash':0},
'currency':"CAD",}
}}
financialNetworkDef['price'] = {'name':'price',
'type':'PriceEmitter',
'dependencies':{'input':{'time':['__ref','time_emitter','output'],
'Ticker':['__ref','securities_emitter','output'],
'resolution':'minute',
'bars':5,
'fields':['OpenPrice','ClosePrice','DateTime']
}
}
}
financialNetworkDef['percentagefilter'] = {'name':'percentagefilter',
'type':'PercentageFilter',
'dependencies':{'input':['__ref','price','output'],
'fields':['OpenPrice']
}
}
financialNetworkDef['mindiff'] = {'name':'mindiff',
'type':'MinutesDiff',
'dependencies':{'input':['__ref','percentagefilter','output'],
'field':'DateTime',
'new_field':'MinuteDelta'
}
}
financialNetworkDef['marketos'] = {'name':'marketos',
'type':'MarketOsRunner',
'dependencies':{'input':{'time_in':['__ref','time_emitter','output'],
'prices':['__ref','price','output']
},
'experiment_id':['__ref','experiment_id'],
'fill_field':'OpenPrice',
'mos_settings':{'holdings':{'cash':100000}}
}
}
expVars = {}
expVars['profit_take'] = {'location':['strategy','dependencies','input','profit_take'], 'values':[1.005,1.01,1.02,1.005]}
expVars['profit_stop'] = {'location':['strategy','dependencies','input','profit_stop'], 'values':[0.995,0.98,0.998,0.99]}
expVars['core_step'] = {'location':['strategy','dependencies','input','core_step'], 'values':[4,2,0.5,0.25]}
#expVars['core_min'] = {'location':['strategy','dependencies','input','core_min'], 'values':[0.15,0.25,0.5]}
#expVars['base_trade_portion'] = {'location':['strategy','dependencies','input','base_trade_portion'], 'values':[0.15,0.3]}
choices = []
for i in [0,1,2,3]:
for j in [0,1,2,3]:
for k in [0,1,2]:
choices.append([i,j,k])
expDefs = {}
cnt = 0;
for i in range(1,len(choices)*9):
# Populate the data values
date_mod = i%9
expDefs[cnt] = {}
expDefs[cnt]['start_date'] ={'value':datetime.datetime(2011,1+date_mod,5,10,0,0),'location':['time_emitter','dependencies','start_date']}
expDefs[cnt]['end_date']= {'value':datetime.datetime(2011,2+date_mod,5,15,0,0),'location':['time_emitter','dependencies','end_date']}
if (expDefs[cnt]['start_date']['value'].weekday() >= 5):
expDefs[cnt]['start_date']['value'] = expDefs[cnt]['start_date']['value'] + datetime.timedelta(days=2)
expDefs[cnt]['end_date']['value']= expDefs[cnt]['end_date']['value'] + datetime.timedelta(days=2)
# Populate all the behaviour vars
choice = choices[i%len(choices)]
key = 0
for idx in choice:
var = list(expVars.keys())[key]
val = expVars[var]['values'][idx]
loc = expVars[var]['location']
expDefs[cnt][var] ={'value':val,'location':loc}
key = key + 1
cnt = cnt +1
print(len(expDefs))
feature={}
feature['mode'] = 'jef'
feature['experiment_variables'] = expDefs
feature['financialNetworkDef'] = financialNetworkDef
feature['code'] = codeString
feature['api_key'] = api_key
pq.launch_financial_batch_process(feature,remote=False)
Simple Example Output
prep
sett
em
CREATING MONGO
em Done
batchProcess-2019-12-12T11:54:02.3235922019-12-12T11:54:02.323993 submitted to queue experiment_id=0d1688c6-b563-47e3-bc23-889ff1af99dd
{'experiment_id': '0d1688c6-b563-47e3-bc23-889ff1af99dd'}