Overall Statistics
Total Orders
29
Average Win
0.08%
Average Loss
-0.03%
Compounding Annual Return
-25.300%
Drawdown
0.700%
Expectancy
1.712
Net Profit
-0.478%
Sharpe Ratio
-14.45
Sortino Ratio
-19.176
Probabilistic Sharpe Ratio
0.000%
Loss Rate
25%
Win Rate
75%
Profit-Loss Ratio
2.62
Alpha
-0.251
Beta
-0.036
Annual Standard Deviation
0.016
Annual Variance
0
Information Ratio
1.238
Tracking Error
0.123
Treynor Ratio
6.612
Total Fees
$51.62
Estimated Strategy Capacity
$12000000.00
Lowest Capacity Asset
UNPH R735QTJ8XC9X
Portfolio Turnover
20.01%
#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


using QuantConnect.DataSource;

namespace QuantConnect
{
	public class KavoutCompositeFactorBundleAlgorithm : QCAlgorithm
	{
		private DateTime _time = DateTime.MinValue;
		
		public override void Initialize()
		{
			SetStartDate(2003, 1, 10);
			SetEndDate(2003, 1, 15);
			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;
			
			// Accessing Data
			var points = slice.Get<KavoutCompositeFactorBundle>();
			
			var sortedByScore = from s in points.Values
							orderby TotalScore(s) descending
							select s.Symbol.Underlying;
			var longSymbols = sortedByScore.Take(10).ToList();
			var shortSymbols = sortedByScore.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 kavoutCompositeFactorBundleSymbol = AddData<KavoutCompositeFactorBundle>(security.Symbol).Symbol;
				
				// Historical Data
				var history = History(new[]{kavoutCompositeFactorBundleSymbol}, 60, Resolution.Daily);
				Debug($"We got {history.Count()} items from our history request");
			}
		}
		
		private decimal TotalScore(KavoutCompositeFactorBundle value)
		{
			/// Return the total score to integrate overall likelihood to outcompete, take equal weighting for each factor
			return value.Growth + value.ValueFactor + value.Quality + value.Momentum + value.LowVolatility;
		}
	}
}