Overall Statistics
Total Orders
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
139.121%
Drawdown
42.800%
Expectancy
0
Net Profit
140.171%
Sharpe Ratio
3.098
Sortino Ratio
4.067
Probabilistic Sharpe Ratio
79.219%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-1.045
Beta
0.75
Annual Standard Deviation
0.556
Annual Variance
0.309
Information Ratio
-9.795
Tracking Error
0.201
Treynor Ratio
2.298
Total Fees
$399.00
Estimated Strategy Capacity
$130000.00
Lowest Capacity Asset
BTCUSD 2XR
Portfolio Turnover
0.13%
from AlgorithmImports import *
from QuantConnect.DataSource import *
from QuantConnect.Data.UniverseSelection import *

class CoinAPIDataAlgorithm(QCAlgorithm):

    def Initialize(self) -> None:
        self.SetStartDate(2020, 6, 1)
        self.SetEndDate(2021, 6, 1)
        self.SetCash(100000)
        self.UniverseSettings.Asynchronous = True
        # Coinbase accepts Cash account type only, AccountType.Margin will result in an exception.
        self.SetBrokerageModel(BrokerageName.Coinbase, AccountType.Cash)

        # Warm up the security with the last known price to avoid conversion error
        self.SetSecurityInitializer(lambda security: security.SetMarketPrice(self.GetLastKnownPrice(security)))

        # Requesting data
        crypto = self.AddCrypto("BTCUSD", Resolution.Minute, Market.Coinbase)
        self.btcusd = crypto.Symbol
        self.minimum_order_size = crypto.SymbolProperties.MinimumOrderSize
        self.threshold = 0.5
        
        # Historical data
        history = self.History(self.btcusd, 30, Resolution.Daily)
        self.Debug(f"We got {len(history)} items from our history request")

        # Add Crypto Coarse Fundamental Universe Selection
        self.AddUniverse(CryptoUniverse.Coinbase(self.UniverseSelectionFilter))

    def UniverseSelectionFilter(self, crypto_coarse):
        return [datum.Symbol for datum in crypto_coarse
                if datum.Volume >= 100 
                and datum.VolumeInUsd > 10000]

    def OnData(self, slice: Slice) -> None:
        if self.Portfolio.CashBook['BTC'].Amount == 0:
            free_cash = self.Portfolio.CashBook['USD'].Amount * (1-self.Settings.FreePortfolioValuePercentage)
            quantity = self.threshold*free_cash / slice[self.btcusd].Price
            quantity -= quantity % self.minimum_order_size
            if quantity > 0:
                self.MarketOrder(self.btcusd, quantity)