Created
July 22, 2019 22:09
-
-
Save mementum/54658f5550ff18383309c45271b9dbe5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run(args=None): | |
args = parse_args(args) | |
cerebro = bt.Cerebro() | |
# Data feed kwargs | |
dkwargs = dict(**eval('dict(' + args.dargs + ')')) | |
# Parse from/to-date | |
dtfmt, tmfmt = '%Y-%m-%d', 'T%H:%M:%S' | |
if args.fromdate: | |
fmt = dtfmt + tmfmt * ('T' in args.fromdate) | |
dkwargs['fromdate'] = datetime.datetime.strptime(args.fromdate, fmt) | |
if args.todate: | |
fmt = dtfmt + tmfmt * ('T' in args.todate) | |
dkwargs['todate'] = datetime.datetime.strptime(args.todate, fmt) | |
# add all the data files available in the directory datadir | |
for fname in glob.glob(os.path.join(args.datadir, '*')): | |
data = NetPayOutData(dataname=fname, **dkwargs) | |
cerebro.adddata(data) | |
# add strategy | |
cerebro.addstrategy(St, **eval('dict(' + args.strat + ')')) | |
# set the cash | |
cerebro.broker.setcash(args.cash) | |
cerebro.run() # execute it all | |
# Basic performance evaluation ... final value ... minus starting cash | |
pnl = cerebro.broker.get_value() - args.cash | |
print('Profit ... or Loss: {:.2f}'.format(pnl)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment