This file contains 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
from __future__ import (absolute_import, division, print_function, unicode_literals) | |
import pandas as pd | |
import backtrader as bt | |
from strategies import hodl | |
from strategies import sma_crossover | |
from api import crypto_data | |
btc_usd = crypto_data.get_feed("BTC/USD", exchange="CCCAGG", resolution="day", length=182) | |
cerebro = bt.Cerebro() | |
cerebro.broker.setcash(100000.0) | |
cerebro.broker.setcommission(commission=0.001) | |
cerebro.addstrategy(sma_crossover.SMA_CrossOver) | |
cerebro.addstrategy(hodl.Hodl) | |
cerebro.adddata(btc_usd, name="BTC") | |
cerebro.run() | |
cerebro.plot(volume=False) |
This file contains 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
from __future__ import (absolute_import, division, print_function,unicode_literals) | |
import backtrader as bt | |
class Hodl(bt.Strategy): | |
def __init__(self): | |
pass | |
def next(self): | |
stake = 1 / len(self.datas) | |
#for d in self.datas: | |
self.order_target_percent(target=stake, data=self.datas[0]) |
This file contains 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
from __future__ import (absolute_import, division, print_function,unicode_literals) | |
import backtrader as bt | |
import backtrader.indicators as btind | |
class SMA_CrossOver(bt.Strategy): | |
params = ( | |
('fast', 10), | |
('slow', 30), | |
('_movav', btind.MovAv.SMA) | |
) | |
def __init__(self): | |
sma_fast = self.p._movav(period=self.p.fast) | |
sma_slow = self.p._movav(period=self.p.slow) | |
self.buysig = btind.CrossOver(sma_fast, sma_slow) | |
def next(self): | |
stake = 1 / len(self.datas) | |
if self.buysig > 0: | |
self.order_target_percent(target=stake, data=self.datas[0]) | |
elif self.buysig < 0: | |
self.order_target_percent(target=0.0, data=self.datas[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment