Overall Statistics
Total Orders
363
Average Win
0.87%
Average Loss
-0.41%
Compounding Annual Return
357.983%
Drawdown
16.700%
Expectancy
0.341
Net Profit
14.271%
Sharpe Ratio
3.72
Sortino Ratio
6.698
Probabilistic Sharpe Ratio
63.656%
Loss Rate
57%
Win Rate
43%
Profit-Loss Ratio
2.15
Alpha
2.107
Beta
0.676
Annual Standard Deviation
0.724
Annual Variance
0.524
Information Ratio
2.54
Tracking Error
0.718
Treynor Ratio
3.987
Total Fees
$827.42
Estimated Strategy Capacity
$210000.00
Lowest Capacity Asset
CZR V3Y20BEIYSTH
Portfolio Turnover
212.21%
#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

namespace QuantConnect
{
	public class ExtractAlphaTrueBeatsDataAlgorithm : QCAlgorithm
	{
		private DateTime _time = DateTime.MinValue;
		
		public override void Initialize()
		{
			SetStartDate(2019, 1, 1);
			SetEndDate(2019, 2, 1);
			SetCash(100000);
			
			AddUniverse(MyCoarseFilterFunction);
			UniverseSettings.Resolution = Resolution.Minute;
		}
		
		private IEnumerable<Symbol> MyCoarseFilterFunction(IEnumerable<CoarseFundamental> coarse)
		{
			return (from c in coarse
					where c.HasFundamentalData
					orderby c.DollarVolume descending
					select c.Symbol).Take(100);
		}
		
		public override void OnData(Slice slice)
		{
			if (_time > Time) return;
			
			// Retrieve data
			var points = slice.Get<ExtractAlphaTrueBeats>();
			
			if (points.IsNullOrEmpty()) return;
			
			List<ExtractAlphaTrueBeat> trueBeats = new List<ExtractAlphaTrueBeat>(
				points.SelectMany(point => point.Value.Select(x => (ExtractAlphaTrueBeat)x))
			);
			
			var sortedByTrueBeat = from trueBeat in trueBeats
									where (trueBeat.TrueBeat != null)
									orderby trueBeat.TrueBeat descending
									select trueBeat.Symbol.Underlying;

			var longSymbols = sortedByTrueBeat.Take(10).ToList();
			var shortSymbols = sortedByTrueBeat.TakeLast(10).ToList();
			
			foreach (var kvp in Portfolio)
			{
				var symbol = kvp.Key;
				if (kvp.Value.Invested && 
				!longSymbols.Contains(symbol) && 
				!shortSymbols.Contains(symbol))
				{
					Liquidate(symbol);
				}
			}
			
			var targets = new List<PortfolioTarget>();
			targets.AddRange(longSymbols.Select(symbol => new PortfolioTarget(symbol, 0.05m)));
			targets.AddRange(shortSymbols.Select(symbol => new PortfolioTarget(symbol, -0.05m)));
			
			SetHoldings(targets);
			
			_time = Expiry.EndOfDay(Time);
		}
		
		public override void OnSecuritiesChanged(SecurityChanges changes)
		{
			foreach(var security in changes.AddedSecurities)
			{
				// Requesting data
				var extractAlphaTrueBeatsSymbol = AddData<ExtractAlphaTrueBeats>(security.Symbol).Symbol;
				
				// Historical Data
	            var history = History(new[]{extractAlphaTrueBeatsSymbol}, 10, Resolution.Daily);
	            Log($"We got {history.Count()} items from our history request for {security.Symbol} ExtractAlpha True Beats data");
			}
		}
	}
}