Skip to content

Instantly share code, notes, and snippets.

@mementum
mementum / vanktharp-coinflip.py
Created Aug 26, 2019
Beating The Random Entry
View vanktharp-coinflip.py
#!/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
@mementum
mementum / ported-pinescript-right.py
Created Sep 4, 2019
Ported Pinescript-Backtrader right
View ported-pinescript-right.py
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()
@mementum
mementum / two-million-indicators-only-pypy-run06.txt
Created Oct 26, 2019
Two Million Candles Indicators Only PyPy Run 06
View two-million-indicators-only-pypy-run06.txt
$ ./two-million-candles.py --strat indicators=True
Cerebro Start Time: 2019-10-26 09:05:55.967969
Strat Init Time: 2019-10-26 09:06:44.072969
Time Loading Data Feeds: 48.10
Number of data feeds: 100
Total indicators: 300
Moving Average to be used: SMA
Indicators period 1: 10
Indicators period 2: 50
Strat Start Time: 2019-10-26 09:06:44.779971
@mementum
mementum / two-million-trade-pypy-run05.txt
Created Oct 26, 2019
Two Million Candles Trade PyPy Run 05
View two-million-trade-pypy-run05.txt
$ ./two-million-candles.py --strat indicators=True,trade=True
Cerebro Start Time: 2019-10-26 08:57:36.114415
Strat Init Time: 2019-10-26 08:58:25.569448
Time Loading Data Feeds: 49.46
Number of data feeds: 100
Total indicators: 300
Moving Average to be used: SMA
Indicators period 1: 10
Indicators period 2: 50
Strat Start Time: 2019-10-26 08:58:26.230445
@mementum
mementum / two-million-exactbars-pypy-run04.txt
Created Oct 26, 2019
Two Million Candles Exactbars Mode PyPy Run 04
View two-million-exactbars-pypy-run04.txt
$ ./two-million-candles.py --cerebro exactbars=True,stdstats=False
Cerebro Start Time: 2019-10-26 08:44:32.309689
Strat Init Time: 2019-10-26 08:44:32.406689
Time Loading Data Feeds: 0.10
Number of data feeds: 100
Strat Start Time: 2019-10-26 08:44:32.409689
Pre-Next Start Time: 2019-10-26 08:44:32.451689
Time Calculating Indicators: 0.04
Next Start Time: 2019-10-26 08:44:32.451689
Strat warm-up period Time: 0.00
@mementum
mementum / two-million-exactbars-run03.txt
Created Oct 26, 2019
Two Million Candles Exactbars Mode Run 03
View two-million-exactbars-run03.txt
$ ./two-million-candles.py --cerebro exactbars=False,stdstats=False
Cerebro Start Time: 2019-10-26 08:37:08.014348
Strat Init Time: 2019-10-26 08:38:21.850392
Time Loading Data Feeds: 73.84
Number of data feeds: 100
Strat Start Time: 2019-10-26 08:38:21.851394
Pre-Next Start Time: 2019-10-26 08:38:21.857393
Time Calculating Indicators: 0.01
Next Start Time: 2019-10-26 08:38:21.857393
Strat warm-up period Time: 0.00
@mementum
mementum / two-million-batch-pypy-run02.txt
Created Oct 26, 2019
Two Million Candles Batch Mode PyPy Run 01
View two-million-batch-pypy-run02.txt
$ ./two-million-candles.py
Cerebro Start Time: 2019-10-26 08:39:42.958689
Strat Init Time: 2019-10-26 08:40:31.260691
Time Loading Data Feeds: 48.30
Number of data feeds: 100
Strat Start Time: 2019-10-26 08:40:31.338692
Pre-Next Start Time: 2019-10-26 08:40:31.612688
Time Calculating Indicators: 0.27
Next Start Time: 2019-10-26 08:40:31.612688
Strat warm-up period Time: 0.00
@mementum
mementum / two-million-batch-run01.txt
Created Oct 26, 2019
Two Million Candles Batch Mode Run 01
View two-million-batch-run01.txt
$ ./two-million-candles.py
Cerebro Start Time: 2019-10-26 08:33:15.563088
Strat Init Time: 2019-10-26 08:34:31.845349
Time Loading Data Feeds: 76.28
Number of data feeds: 100
Strat Start Time: 2019-10-26 08:34:31.864349
Pre-Next Start Time: 2019-10-26 08:34:32.670352
Time Calculating Indicators: 0.81
Next Start Time: 2019-10-26 08:34:32.671351
Strat warm-up period Time: 0.00
@mementum
mementum / performance-test.py
Created Oct 26, 2019
Peformance Test Script
View performance-test.py
#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-
###############################################################################
import argparse
import datetime
import backtrader as bt
class St(bt.Strategy):
View generate-candles.py
import numpy as np
import pandas as pd
COLUMNS = ['open', 'high', 'low', 'close', 'volume', 'openinterest']
CANDLES = 20000
STOCKS
dateindex = pd.date_range(start='2010-01-01', periods=CANDLES, freq='15min')
for i in range(STOCKS):