Overall Statistics
Total Orders
541
Average Win
0.19%
Average Loss
-0.20%
Compounding Annual Return
-1.835%
Drawdown
8.300%
Expectancy
-0.068
Net Profit
-3.641%
Sharpe Ratio
-1.234
Sortino Ratio
-1.053
Probabilistic Sharpe Ratio
1.224%
Loss Rate
52%
Win Rate
48%
Profit-Loss Ratio
0.93
Alpha
-0.042
Beta
-0.001
Annual Standard Deviation
0.034
Annual Variance
0.001
Information Ratio
-0.202
Tracking Error
0.166
Treynor Ratio
40.959
Total Fees
$584.79
Estimated Strategy Capacity
$10000000.00
Lowest Capacity Asset
MELI TV0AIPE7984L
Portfolio Turnover
3.45%
#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 ExtractAlphaTacticalModelAlgorithm : QCAlgorithm
	{
		private DateTime _time = DateTime.MinValue;
		
		public override void Initialize()
		{
			SetStartDate(2021, 10, 10);
			SetEndDate(2023, 10, 10);
			SetCash(100000);
			
			AddUniverse(MyCoarseFilterFunction);
			UniverseSettings.Resolution = Resolution.Minute;
		}
		
		private IEnumerable<Symbol> MyCoarseFilterFunction(IEnumerable<CoarseFundamental> coarse)
		{
			return (from c in coarse
					where c.HasFundamentalData && c.Price > 4
					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<ExtractAlphaTacticalModel>();
			var sortedByScore = from s in points.Values
							where (s.Score != null)
							orderby s.Score 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 extractAlphaTacticalModelSymbol = AddData<ExtractAlphaTacticalModel>(security.Symbol).Symbol;
				
				// Historical Data
				var history = History(new[]{extractAlphaTacticalModelSymbol}, 60, Resolution.Daily);
				Debug($"We got {history.Count()} items from our history request");
			}
		}
	}
}