Overall Statistics
Total Orders
229
Average Win
3.54%
Average Loss
-2.29%
Compounding Annual Return
129.607%
Drawdown
21.700%
Expectancy
0.405
Start Equity
100000.0
End Equity
264451.14
Net Profit
164.451%
Sharpe Ratio
2.559
Sortino Ratio
3.851
Probabilistic Sharpe Ratio
88.756%
Loss Rate
45%
Win Rate
55%
Profit-Loss Ratio
1.54
Alpha
0.862
Beta
0.06
Annual Standard Deviation
0.341
Annual Variance
0.116
Information Ratio
1.677
Tracking Error
0.418
Treynor Ratio
14.5
Total Fees
$0.00
Estimated Strategy Capacity
$530000.00
Lowest Capacity Asset
BTCUSD 2XR
Portfolio Turnover
53.00%
from AlgorithmImports import *
from QuantConnect.DataSource import *

class BlockchainBitcoinMetadataAlgorithm(QCAlgorithm):
    
    def initialize(self) -> None:
        self.set_start_date(2019, 11, 1)   # Set Start Date
        self.set_end_date(2020, 12, 31)    # Set End Date
        self.set_cash(100000)

        self.btcusd = self.add_crypto("BTCUSD", Resolution.MINUTE).symbol
        ### Requesting data
        self.bitcoin_metadata_symbol = self.add_data(BitcoinMetadata, self.btcusd).symbol

        ### Historical data
        history = self.history(BitcoinMetadata, self.bitcoin_metadata_symbol, 60, Resolution.DAILY)
        self.debug(f"We got {len(history)} items from our history request for {self.btcusd} Blockchain Bitcoin Metadata")

        self.last_demand_supply = None

    def on_data(self, slice: Slice) -> None:
        ### Retrieving data
        data = slice.Get(BitcoinMetadata)
        
        if self.bitcoin_metadata_symbol in data and data[self.bitcoin_metadata_symbol] != None:
            current_demand_supply = data[self.bitcoin_metadata_symbol].numberof_transactions / data[self.bitcoin_metadata_symbol].hash_rate

            # comparing the average transaction-to-hash-rate ratio changes, we will buy bitcoin or hold cash
            if self.last_demand_supply != None and current_demand_supply > self.last_demand_supply:
                self.set_holdings(self.btcusd, 1)
            else:
                self.set_holdings(self.btcusd, 0)

            self.last_demand_supply = current_demand_supply