Overall Statistics
Total Orders
584
Average Win
0.18%
Average Loss
-0.12%
Compounding Annual Return
24.368%
Drawdown
16.300%
Expectancy
0.275
Start Equity
100000
End Equity
111951.66
Net Profit
11.952%
Sharpe Ratio
0.831
Sortino Ratio
1.112
Probabilistic Sharpe Ratio
41.998%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
1.48
Alpha
-0.159
Beta
1.556
Annual Standard Deviation
0.231
Annual Variance
0.053
Information Ratio
-0.2
Tracking Error
0.166
Treynor Ratio
0.123
Total Fees
$743.67
Estimated Strategy Capacity
$120000000.00
Lowest Capacity Asset
KO R735QTJ8XC9X
Portfolio Turnover
11.81%
from AlgorithmImports import *
from QuantConnect.DataSource import *

class BrainMLRankingDataAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2021, 1, 1)
        self.set_end_date(2021, 7, 8)
        self.set_cash(100000) 
        
        tickers = ["AAPL", "TSLA", "MSFT", "F", "KO"]
        self.symbol_by_dataset_symbol = {}
        for ticker in tickers:
            
            # Requesting data
            symbol = self.add_equity(ticker, Resolution.DAILY).symbol
            dataset_symbol = self.add_data(BrainStockRanking2Day, symbol).symbol
            self.symbol_by_dataset_symbol[dataset_symbol] = symbol
            
            # Historical data
            history = self.history(dataset_symbol, 365, Resolution.DAILY)
            self.debug(f"We got {len(history)} items from our history request for {symbol}")
        
    def on_data(self, slice: Slice) -> None:
        
        # Collect rankings for all symbols
        points = slice.Get(BrainStockRanking2Day)
        if points is None:
            return
        symbols = []
        ranks = []
        for point in points.Values:
            symbols.append(self.symbol_by_dataset_symbol[point.symbol])
            ranks.append(point.rank)
        
        # Rank each symbol's Brain ML ranking relative to each other
        if len(ranks) == 0:
            return
        ranks = [sorted(ranks).index(rank) + 1 for rank in ranks]
        
        # Place orders
        for i, rank in enumerate(ranks):
            weight = rank / sum(ranks)
            self.set_holdings(symbols[i], weight)