Overall Statistics
Total Trades
11
Average Win
1.95%
Average Loss
-0.81%
Compounding Annual Return
4040.800%
Drawdown
1.200%
Expectancy
1.550
Net Profit
11.685%
Sharpe Ratio
72.712
Probabilistic Sharpe Ratio
99.779%
Loss Rate
25%
Win Rate
75%
Profit-Loss Ratio
2.40
Alpha
16.526
Beta
0.391
Annual Standard Deviation
0.226
Annual Variance
0.051
Information Ratio
63.566
Tracking Error
0.263
Treynor Ratio
41.976
Total Fees
$3217.26
Estimated Strategy Capacity
$31000000.00
Lowest Capacity Asset
BTCBUSD 18R
/*
 * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
 * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/

using System.Linq;
using QuantConnect.Data;
using QuantConnect.Brokerages;

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

        public override void Initialize()
        {
            SetStartDate(2022, 10, 1);
            SetEndDate(2022, 10, 10);
            SetCash("BUSD", 100000);

            SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin);

            var cryptoFuture = AddCryptoFuture("BTCBUSD", 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.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);
            }
        }
    }
}