| Overall Statistics |
|
Total Trades 38 Average Win 194.75% Average Loss -4.56% Compounding Annual Return 332.600% Drawdown 43.500% Expectancy 10.507 Net Profit 2325.062% Sharpe Ratio 1.966 Loss Rate 74% Win Rate 26% Profit-Loss Ratio 42.73 Alpha 1.309 Beta 0.186 Annual Standard Deviation 0.677 Annual Variance 0.459 Information Ratio 1.774 Tracking Error 0.682 Treynor Ratio 7.163 Total Fees $1629.10 |
# WarmCryptoCrossover (Py) v0.02
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Data import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from datetime import datetime
import decimal as d
import numpy as np
class WarmupAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017,1,1) #Set Start Date
self.SetEndDate(2017,11,5) #Set End Date
self.SetCash(1000) #Set Strategy Cash
# define crypto we want to trade on
# ETHUSD or LTCUSD or BTCUSD
self.target_crypto = "ETHUSD"
# Set brokerage to GDAX for cryptos
self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
# Set crypto and time resolution
self.AddCrypto(self.target_crypto, Resolution.Hour)
# Define windows in days for EMA
# 168 hours in a week, 1440 minutes in a day
fast_period = 16
slow_period = (168 * 2)
medium_period = ((slow_period - fast_period) / 2) + fast_period
# Define a fast and slow exponential moving average
self.fast = self.EMA(self.target_crypto, fast_period)
self.medium = self.EMA(self.target_crypto, medium_period)
self.slow = self.EMA(self.target_crypto, slow_period)
# Define average direction
self.adxr = self.ADXR(self.target_crypto, medium_period)
# Request warmup data
self.SetWarmup(slow_period)
# Plot EMAs
self.PlotIndicator(self.target_crypto,self.fast,self.medium,self.slow)
self.first = True
def OnData(self, data):
if self.first and not self.IsWarmingUp:
self.first = False
self.Log("Fast: {0}".format(self.fast.Samples))
self.Log("Medium: {0}".format(self.medium.Samples))
self.Log("Slow: {0}".format(self.slow.Samples))
self.Log("ADXR >> {0}".format(self.adxr.Samples))
# Determine holdings (# of units held) and price of unit
holdings = self.Portfolio[self.target_crypto].Quantity
price = self.Securities[self.target_crypto].Price
# define a small tolerance on our checks to avoid bouncing
if holdings > 0:
tolerance = 0.0001
else:
tolerance = 0.0001
self.Log("ADXR >> {0}".format(self.adxr))
# we only want to go long if we're currently short or flat
if holdings <= 0:
# if the fast is greater than the slow, we'll go long
if self.fast.Current.Value > self.slow.Current.Value * d.Decimal(1 + tolerance):
self.Log("BUY >> {0}".format(price))
self.SetHoldings(self.target_crypto, 1)
# we only want to liquidate if we're currently long
# if the fast is less than the slow we'll liquidate our long
if holdings > 0:
if self.fast.Current.Value < self.slow.Current.Value * d.Decimal(1 - tolerance):
self.Log("SELL >> {0}".format(price))
self.SetHoldings(self.target_crypto, 0)