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 matplotlib.pyplot as plt | |
| import numpy as np | |
| import pandas as pd | |
| import pyrenko | |
| import scipy.optimize as opt | |
| from scipy.stats import iqr | |
| import talib | |
| from catalyst import run_algorithm | |
| from catalyst.api import (record, symbol, order_target, order_target_percent, get_datetime) |
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 initialize(context): | |
| context.asset = symbol('eth_btc') | |
| context.leverage = 1.0 # 1.0 - no leverage | |
| context.n_history = 24 * 15 # Number of lookback bars for modelling | |
| context.tf = '60T' # How many minutes in a timeframe | |
| context.model = pyrenko.renko() # Renko object | |
| context.part_cover_ratio = 0.166 # Partially cover position ratio | |
| context.last_brick_size = 0.0 # Last optimal brick size (just for storing) | |
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
| # Function for optimization | |
| def evaluate_renko(brick, history, column_name): | |
| renko_obj = pyrenko.renko() | |
| renko_obj.set_brick_size(brick_size = brick, auto = False) | |
| renko_obj.build_history(prices = history) | |
| return renko_obj.evaluate()[column_name] | |
| def handle_data(context, data): | |
| current_time = get_datetime().time() | |
| if current_time.hour == 0 and current_time.minute == 0: |
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 analyze(context, perf): | |
| # Summary output | |
| print('Total return: ' + str(perf.algorithm_period_return[-1])) | |
| print('Sortino coef: ' + str(perf.sortino[-1])) | |
| print('Max drawdown: ' + str(np.min(perf.max_drawdown))) | |
| print('Alpha: ' + str(perf.alpha[-1])) | |
| print('Beta: ' + str(perf.beta[-1])) | |
| perf.to_csv('perf_' + str(context.asset) + '.csv') | |
| f = plt.figure(figsize = (7.2, 7.2)) |
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
| run_algorithm( | |
| capital_base = 10, | |
| data_frequency = 'daily', | |
| initialize = initialize, | |
| handle_data = handle_data, | |
| analyze = analyze, | |
| exchange_name = 'bitfinex', | |
| quote_currency = 'btc', | |
| start = pd.to_datetime('2017-12-1', utc = True), | |
| end = pd.to_datetime('2018-11-12', utc = True)) |
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
| python renko_trend_following.py |
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 quandl | |
| import pandas as pd | |
| from matplotlib import pyplot as plt | |
| import requests | |
| import statsmodels.tsa.stattools as ts | |
| from statsmodels.tsa.vector_ar.vecm import coint_johansen | |
| def get_bitfinex_asset(asset, ts_ms_start, ts_ms_end): | |
| url = 'https://api.bitfinex.com/v2/candles/trade:1D:t' + asset + '/hist' | |
| params = { 'start': ts_ms_start, 'end': ts_ms_end, 'sort': 1} |
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
| BTCUSD and ETHUSD: p-value = 0.06576979804268955 | |
| BTCUSD and LTCUSD: p-value = 0.07347140678450967 | |
| BTCUSD and XMRUSD: p-value = 0.021570889424181703 | |
| BTCUSD and NEOUSD: p-value = 0.10239483419041967 | |
| BTCUSD and XRPUSD: p-value = 0.00900122457399106 | |
| BTCUSD and ZECUSD: p-value = 0.16378128244807538 | |
| ETHUSD and BTCUSD: p-value = 0.31796015423321283 | |
| ETHUSD and LTCUSD: p-value = 0.609075825185015 | |
| ETHUSD and XMRUSD: p-value = 0.17284643088428048 | |
| ETHUSD and NEOUSD: p-value = 0.12876967722061067 |
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 matplotlib.pyplot as plt | |
| import numpy as np | |
| import pandas as pd | |
| import scipy.stats as st | |
| from catalyst import run_algorithm | |
| from catalyst.api import (record, symbol, order_target_percent, date_rules, time_rules, get_datetime) | |
| def initialize(context): | |
| context.A = symbol('xmr_usd') |
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
| context.set_commission(maker = 0.001, taker = 0.002) | |
| context.set_slippage(slippage = 0.0005) |
OlderNewer