Overall Statistics
Total Trades
393
Average Win
3.41%
Average Loss
-2.84%
Compounding Annual Return
63.691%
Drawdown
38.900%
Expectancy
0.213
Net Profit
168.311%
Sharpe Ratio
1.293
Probabilistic Sharpe Ratio
53.036%
Loss Rate
45%
Win Rate
55%
Profit-Loss Ratio
1.20
Alpha
0.511
Beta
0.05
Annual Standard Deviation
0.402
Annual Variance
0.162
Information Ratio
0.736
Tracking Error
0.449
Treynor Ratio
10.411
Total Fees
$0.00
Estimated Strategy Capacity
$250000.00
Lowest Capacity Asset
BTCUSD E3
namespace QuantConnect.Algorithm.CSharp
{
    public class BlockchainBitcoinMetadataAlgorithm : QCAlgorithm
    {
        private Symbol _bitcoinMetadataSymbol;
        private Symbol _btcSymbol;
        private decimal? _lastDemandSupply = null;

        public override void Initialize()
        {
            SetStartDate(2019, 1, 1);  //Set Start Date
            SetEndDate(2020, 12, 31);    //Set End Date
            SetCash(100000);

            _btcSymbol = AddCrypto("BTCUSD", Resolution.Minute, Market.Bitfinex).Symbol; 
            // Requesting data
            _bitcoinMetadataSymbol = AddData<BitcoinMetadata>(_btcSymbol).Symbol;

            // Historical data
            var history = History(new[]{_bitcoinMetadataSymbol}, 60, Resolution.Daily);
            Debug($"We got {history.Count()} items from our history request for {_btcSymbol} Blockchain Bitcoin Metadata");
        }

        public override void OnData(Slice slice)
        {
            // Get data
            var data = slice.Get<BitcoinMetadata>();
            if (!data.IsNullOrEmpty())
            {
                var currentDemandSupply = data[_bitcoinMetadataSymbol].NumberofTransactions / data[_bitcoinMetadataSymbol].HashRate;

                // comparing the average transaction-to-hash-rate ratio changes, we will buy bitcoin or hold cash
                if (_lastDemandSupply != null && currentDemandSupply > _lastDemandSupply)
                {
                    SetHoldings(_btcSymbol, 1);
                }
                else
                {
                    SetHoldings(_btcSymbol, 0);
                }

                _lastDemandSupply = currentDemandSupply;
            }
        }
    }
}