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 __init__(self): | |
self.donchian = DonchianChannels() | |
def next(self): | |
if self.data[0] > self.donchian.dch[0]: | |
self.sell() | |
elif self.data[0] < self.donchian.dcl[0]: | |
self.buy() |
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 __init__(self): | |
self.donchian = DonchianChannels() | |
def next(self): | |
if self.data[0] > self.donchian.dch[-1]: | |
self.sell() | |
elif self.data[0] < self.donchian.dcl[-1]: | |
self.buy() |
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
if price0 > channel_high_1: | |
sell() | |
elif price0 < channel_low_1: | |
buy() |
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
class DonchianChannels(bt.Indicator): | |
''' | |
Params Note: | |
- ``lookback`` (default: -1) | |
If `-1`, the bars to consider will start 1 bar in the past and the | |
current high/low may break through the channel. | |
If `0`, the current prices will be considered for the Donchian | |
Channel. This means that the price will **NEVER** break through the |
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
$ ./fractional-sizes.py --fractional --plot | |
2005-02-14,3079.93,3083.38,3065.27,3075.76,0.00 | |
2005-02-15,3075.20,3091.64,3071.08,3086.95,0.00 | |
... | |
2005-03-21,3052.39,3059.18,3037.80,3038.14,0.00 | |
2005-03-21,Enter Short | |
2005-03-22,Sell Order Completed - Size: -16.457437774427774 @Price: 3040.55 Value: -50039.66 Comm: 0.00 | |
2005-03-22,Trade Opened - Size -16.457437774427774 @Price 3040.55 | |
2005-03-22,3040.55,3053.18,3021.66,3050.44,0.00 | |
... |
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
$ ./fractional-sizes.py --plot | |
2005-02-14,3079.93,3083.38,3065.27,3075.76,0.00 | |
2005-02-15,3075.20,3091.64,3071.08,3086.95,0.00 | |
... | |
2005-03-21,3052.39,3059.18,3037.80,3038.14,0.00 | |
2005-03-21,Enter Short | |
2005-03-22,Sell Order Completed - Size: -16 @Price: 3040.55 Value: -48648.80 Comm: 0.00 | |
2005-03-22,Trade Opened - Size -16 @Price 3040.55 | |
2005-03-22,3040.55,3053.18,3021.66,3050.44,0.00 | |
... |
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
#!/usr/bin/env python | |
# -*- coding: utf-8; py-indent-offset:4 -*- | |
############################################################################### | |
# Copyright (C) 2019 Daniel Rodriguez - MIT License | |
# - https://opensource.org/licenses/MIT | |
# - https://en.wikipedia.org/wiki/MIT_License | |
############################################################################### | |
import argparse | |
import logging | |
import sys |
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
#!/usr/bin/env python | |
# -*- coding: utf-8; py-indent-offset:4 -*- | |
############################################################################### | |
# Copyright (C) 2019 Daniel Rodriguez - MIT License | |
# - https://opensource.org/licenses/MIT | |
# - https://en.wikipedia.org/wiki/MIT_License | |
############################################################################### | |
import argparse | |
import random |
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
import argparse | |
import datetime | |
import glob | |
import os.path | |
import backtrader as bt | |
class NetPayOutData(bt.feeds.GenericCSVData): | |
lines = ('npy',) # add a line containing the net payout yield |
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' |