Overall Statistics
Total Orders
91
Average Win
3.03%
Average Loss
-1.52%
Compounding Annual Return
-69.408%
Drawdown
38.800%
Expectancy
-0.321
Net Profit
-32.647%
Sharpe Ratio
-1.137
Sortino Ratio
-1.593
Probabilistic Sharpe Ratio
6.199%
Loss Rate
77%
Win Rate
23%
Profit-Loss Ratio
2.00
Alpha
-0.577
Beta
0.1
Annual Standard Deviation
0.475
Annual Variance
0.226
Information Ratio
-1.883
Tracking Error
0.484
Treynor Ratio
-5.418
Total Fees
$0.00
Estimated Strategy Capacity
$140000.00
Lowest Capacity Asset
BTCUSD 2XR
Portfolio Turnover
116.56%
#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    using System.Text.RegularExpressions;
    using QuantConnect.Algorithm.Framework;
    using QuantConnect.Algorithm.Framework.Selection;
    using QuantConnect.Algorithm.Framework.Alphas;
    using QuantConnect.Algorithm.Framework.Portfolio;
    using QuantConnect.Algorithm.Framework.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Algorithm.Selection;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;   
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion

namespace QuantConnect.DataLibrary.Tests
{
    public class CoinGeckoAlgorithm : QCAlgorithm
    {
        private Symbol _cryptoSymbol;
        private Symbol _customDataSymbol;
        private RollingWindow<CoinGecko> _window;

        public override void Initialize()
        {
            SetStartDate(2019, 1, 1);  //Set Start Date
            SetEndDate(2019, 5, 1);    //Set End Date

            _cryptoSymbol = AddCrypto("BTCUSD").Symbol;
            _customDataSymbol = AddData<CoinGecko>("BTC").Symbol;
            _window = new RollingWindow<CoinGecko>(2);
        }

        public override void OnData(Slice slice)
        {
            var data = slice.Get<CoinGecko>();
            if (!data.IsNullOrEmpty() && data.ContainsKey(_customDataSymbol))
            {
                _window.Add(data[_customDataSymbol]);
                if (!_window.IsReady)
                {
                    return;
                }

                // Buy BTCUSD if the market cap of BTC is increasing
                if (_window[0].MarketCap > _window[1].MarketCap)
                {
                    SetHoldings(_cryptoSymbol, 1);
                }
                else
                {
                    SetHoldings(_cryptoSymbol, -1);
                }
            }
        }

        public override void OnOrderEvent(OrderEvent orderEvent)
        {
            if (orderEvent.Status.IsFill())
            {
                Debug($"Purchased Stock: {orderEvent.Symbol}");
            }
        }
    }
}