Overall Statistics
Total Trades
255
Average Win
3.55%
Average Loss
-2.51%
Compounding Annual Return
7.219%
Drawdown
54.200%
Expectancy
0.018
Net Profit
7.256%
Sharpe Ratio
0.356
Probabilistic Sharpe Ratio
22.161%
Loss Rate
58%
Win Rate
42%
Profit-Loss Ratio
1.42
Alpha
0.157
Beta
-0.065
Annual Standard Deviation
0.529
Annual Variance
0.28
Information Ratio
0.946
Tracking Error
0.706
Treynor Ratio
-2.902
Total Fees
â‚®24778.77
Estimated Strategy Capacity
â‚®44000000.00
Lowest Capacity Asset
BTCUSDT 2V3
Portfolio Turnover
80.87%
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Brokerages;

namespace QuantConnect.Algorithm.CSharp
{
    public class BybitCryptoFutureDataAlgorithm : QCAlgorithm
    {
        public Symbol _symbol;

        public override void Initialize()
        {
            SetStartDate(2022, 1, 1);
            SetEndDate(2023, 1, 1);
            SetAccountCurrency("USDT", 100000);

            SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin);

            var cryptoFuture = AddCryptoFuture("BTCUSDT", Resolution.Daily);
            // perpetual futures does not have a filter function
            _symbol = cryptoFuture.Symbol;

            // Historical data
            var history = History(_symbol, 10, Resolution.Daily);
            Debug($"We got {history.Count()} from our history request for {_symbol}");
        }

        public override void OnData(Slice slice)
        {
            if (slice.MarginInterestRates.ContainsKey(_symbol))
            {
                var interestRate = slice.MarginInterestRates[_symbol].InterestRate;
                Log($"{_symbol} price at {slice.Time}: {interestRate}");
            }

            if (!slice.Bars.ContainsKey(_symbol) || !slice.QuoteBars.ContainsKey(_symbol))
            {
                return;
            }
            
            var quote = slice.QuoteBars[_symbol];
            var price = slice.Bars[_symbol].Price;
            
            if (price - quote.Bid.Close > quote.Ask.Close - price)
            {
                SetHoldings(_symbol, -1m);
            }
            else
            {
                SetHoldings(_symbol, 1m);
            }
        }
    }
}