| Overall Statistics |
|
Total Trades 49 Average Win 45.83% Average Loss -5.73% Compounding Annual Return 51.713% Drawdown 49.700% Expectancy 1.570 Net Profit 333.705% Sharpe Ratio 1.018 Probabilistic Sharpe Ratio 34.349% Loss Rate 71% Win Rate 29% Profit-Loss Ratio 8.00 Alpha 0.527 Beta -0.222 Annual Standard Deviation 0.497 Annual Variance 0.247 Information Ratio 0.746 Tracking Error 0.55 Treynor Ratio -2.282 Total Fees $0.00 Estimated Strategy Capacity $2900000.00 Lowest Capacity Asset BTCUSD XJ Portfolio Turnover 4.78% |
#region imports
from AlgorithmImports import *
#endregion
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
class MovingAverageCrossover(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1) # set start date
self.SetCash(10000) # set strategy cash
self.AddCrypto("BTCUSD", Resolution.Daily) # Bitcoin data
self.fast = self.EMA("BTCUSD", 14, Resolution.Daily)
self.slow = self.EMA("BTCUSD", 28, Resolution.Daily)
self.long_term = self.EMA("BTCUSD", 50, Resolution.Daily)
self.previous = None
self.stopMarketTicket = None
def OnData(self, data):
if not self.fast.IsReady or not self.slow.IsReady or not self.long_term.IsReady:
return
if self.previous is not None and self.previous.date() == self.Time.date():
return
holdings = self.Portfolio["BTCUSD"].Quantity
if self.fast.Current.Value > self.slow.Current.Value and self.Securities["BTCUSD"].Close > self.long_term.Current.Value:
if holdings <= 0:
self.SetHoldings("BTCUSD", 1.0)
self.stopMarketTicket = self.StopMarketOrder("BTCUSD",
-self.Portfolio["BTCUSD"].Quantity,
0.9 * self.Securities["BTCUSD"].Close)
elif self.fast.Current.Value < self.slow.Current.Value and self.Securities["BTCUSD"].Close < self.long_term.Current.Value:
if holdings >= 0:
self.SetHoldings("BTCUSD", -1.0)
self.stopMarketTicket = self.StopMarketOrder("BTCUSD",
self.Portfolio["BTCUSD"].Quantity,
1.1 * self.Securities["BTCUSD"].Close)
self.previous = self.Time
def OnOrderEvent(self, orderEvent):
order = self.Transactions.GetOrderById(orderEvent.OrderId)
if order.Type == OrderType.StopMarket and orderEvent.Status == OrderStatus.Filled:
self.stopMarketTicket = None