Reputation: 21
I utilize python's map() function to pass parameters to a trading model and output the results. I use itertools.product to find all the possible combinations of the two parameters, then pass the combination to my function named "run". The function run returns a pandas dataframe of returns. The Column header is a tuple of the two parameters and the sharpe ratio of the returns. See below:
def run((x,y)):
ENTRYMULT = x
PXITR1PERIOD = y
create_trade()
pull_settings()
pull_marketdata()
create_position()
create_pnl_output()
return DataFrame(DF3['NETPNL'].values, index=DF3.index, columns=[(ENTRYMULT,PXITR1PERIOD,SHARPE)])
My main() function uses the Pool() capability to run map() on all 8 cores:
if __name__ == '__main__':
global DF3
pool = Pool()
test1 =pool.map(run,list(itertools.product([x * 0.1 for x in range(10,12)], range(100,176,25))))
print test1
I realize the map function can only output lists. The output is a list of the header from the returned dataframe My output from print test1 looks like this:
[(1.0, 150, -8.5010673966997263)
2011-11-17 18.63
2011-11-18 17.86
2011-11-21 17.01
2011-11-22 15.92
2011-11-23 15.56
2011-11-24 15.56
2011-11-25 15.36
2011-11-28 15.18
2011-11-29 15.84
2011-11-30 NaN , (1.0, 175, -9.4016837593189102)
2011-11-17 22.63
2011-11-18 22.03
2011-11-21 21.36
2011-11-22 19.93
2011-11-23 19.77
2011-11-24 19.77
2011-11-25 19.68
2011-11-28 19.16
2011-11-29 19.56
2011-11-30 NaN , (1.1, 100, -20.255968672741457)
2011-11-17 12.03
2011-11-18 10.95
2011-11-21 10.03
2011-11-22 9.003
2011-11-23 8.221
2011-11-24 8.221
2011-11-25 7.903
2011-11-28 7.709
2011-11-29 6.444
2011-11-30 NaN , (1.1, 125, -18.178187305758119)
2011-11-17 14.64
2011-11-18 13.76
2011-11-21 12.89
2011-11-22 11.85
2011-11-23 11.34
2011-11-24 11.34
2011-11-25 11.16
2011-11-28 11.06
2011-11-29 10.14
2011-11-30 NaN , (1.1, 150, -14.486791104380069)
2011-11-17 26.25
2011-11-18 25.57
2011-11-21 24.76
2011-11-22 23.74
2011-11-23 23.48
2011-11-24 23.48
2011-11-25 23.43
2011-11-28 23.38
2011-11-29 22.93
2011-11-30 NaN , (1.1, 175, -12.118290962161304)
2011-11-17 24.66
2011-11-18 24.21
2011-11-21 23.57
2011-11-22 22.14
2011-11-23 22.06
2011-11-24 22.06
2011-11-25 22.11
2011-11-28 21.64
2011-11-29 21.24
2011-11-30 NaN ]
My end goal is to have a pandas dataframe with an index (same for all returns), column headers of the (ENTRYMULT, PXITR1PERIOD, SHARPE) with the corresponding returns below. I will then be doing a pairwise correlation calculation across all of the return series.
Upvotes: 2
Views: 5381
Reputation: 105591
I think all you need to do is:
data = DataFrame(dict(test1))
that will result in a DataFrame whose columns are the elements like (1.1, 175, -12.118290962161304)
in pandas 0.6.1 (to be released soon) you'll also be able to do:
data = DataFrame.from_items(test1)
Upvotes: 4