| Overall Statistics |
|
Total Trades 50 Average Win 402.84% Average Loss -7.85% Compounding Annual Return 109.981% Drawdown 65.900% Expectancy 13.653 Net Profit 15316.777% Sharpe Ratio 1.793 Probabilistic Sharpe Ratio 82.192% Loss Rate 72% Win Rate 28% Profit-Loss Ratio 51.33 Alpha 0.862 Beta 0.203 Annual Standard Deviation 0.49 Annual Variance 0.24 Information Ratio 1.573 Tracking Error 0.505 Treynor Ratio 4.328 Total Fees $0.00 Estimated Strategy Capacity $8800000.00 Lowest Capacity Asset BTCUSD XJ |
# region imports
from AlgorithmImports import *
import ht_auth
# endregion
class MuscularBlueChicken(QCAlgorithm):
def Initialize(self):
ht_auth.SetToken(self.GetParameter("mlfinlab-api-key"))
from mlfinlab.labeling import trend_scanning_labels
self.trend_scanning_labels = trend_scanning_labels
self.SetStartDate(2016, 1, 1)
self.SetCash(100000)
self.symbol = self.AddCrypto("BTCUSD", Resolution.Daily).Symbol
self.lookback = 3 * 30 # 3 months
self.close_prices = pd.Series()
trade_bars = self.History[TradeBar](self.symbol, self.lookback)
for trade_bar in trade_bars:
self.update_history(trade_bar)
def update_history(self, trade_bar):
self.close_prices.loc[trade_bar.EndTime] = trade_bar.Close
self.close_prices = self.close_prices.iloc[-self.lookback:]
def OnData(self, data: Slice):
self.update_history(data[self.symbol])
labels = self.trend_scanning_labels(self.close_prices, self.close_prices.index, observation_window=self.lookback, look_forward=False)
trend_direction = labels['bin'].iloc[-1]
if trend_direction == 1 and not self.Portfolio[self.symbol].IsLong \
or trend_direction == -1 and self.Portfolio[self.symbol].IsLong:
self.SetHoldings(self.symbol, int(trend_direction > 0))