Overall Statistics
Total Orders
396
Average Win
3.38%
Average Loss
-2.84%
Compounding Annual Return
63.709%
Drawdown
38.900%
Expectancy
0.212
Net Profit
168.370%
Sharpe Ratio
1.251
Sortino Ratio
1.614
Probabilistic Sharpe Ratio
53.060%
Loss Rate
45%
Win Rate
55%
Profit-Loss Ratio
1.19
Alpha
0.495
Beta
0.05
Annual Standard Deviation
0.402
Annual Variance
0.162
Information Ratio
0.736
Tracking Error
0.449
Treynor Ratio
10.07
Total Fees
$0.00
Estimated Strategy Capacity
$270000.00
Lowest Capacity Asset
BTCUSD E3
Portfolio Turnover
53.60%
#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

using QuantConnect.DataSource;

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;
            }
        }
    }
}