Overall Statistics
Total Trades
14
Average Win
0.61%
Average Loss
0%
Compounding Annual Return
0.242%
Drawdown
1.000%
Expectancy
0
Net Profit
2.453%
Sharpe Ratio
0.586
Probabilistic Sharpe Ratio
9.381%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.002
Beta
0
Annual Standard Deviation
0.004
Annual Variance
0
Information Ratio
-0.051
Tracking Error
0.216
Treynor Ratio
8.18
Total Fees
$40.70
using System;
using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using System.Linq;
using QuantConnect;
using QuantConnect.Securities.Future;
using QuantConnect.Interfaces;
using QuantConnect.Indicators;
using QuantConnect.Securities;
using QuantConnect.Algorithm.Framework.Execution ;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Orders;
using Quant;

namespace Quant
{
   
public partial class Algorithm_YM :  NullAlphaModel
{
	
	public RollingWindow<decimal> BidPriceYM = new RollingWindow<decimal>(3);
    public RollingWindow<decimal> AskPriceYM = new RollingWindow<decimal>(3);
    public RollingWindow<decimal> VolumeYM = new RollingWindow<decimal>(3);

    public OrderTicket EntryOrder { get; set; }
    public Func<QCAlgorithm, string, decimal, OneCancelsOtherTicketSet> OnOrderFilledEvent { get; set; }
    public OneCancelsOtherTicketSet ProfitLossOrders { get; set; }
    
	private readonly Symbol _symbol;
    public Algorithm_YM(Symbol symbol)
    {
        _symbol = symbol;
    }


public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice slice)
{
	var accountCurrencyCash = algorithm.Portfolio.TotalPortfolioValue;

    foreach(var chain in slice.FutureChains)
    {

    // remplacer les lettre entre guillemet par l'abreviation correspondant au contract analysé. 
	if (chain.Value.Symbol.StartsWith("YM"))
    {
	var YM = (from futuresContract in chain.Value.OrderBy(x => x.Expiry)
	where futuresContract.Expiry > algorithm.Time.Date.AddDays(1) 
	select futuresContract).FirstOrDefault();
    
    if (YM != null)
	{
		
	BidPriceYM.Add(YM.BidPrice);
	AskPriceYM.Add(YM.AskPrice);
	VolumeYM.Add(YM.Volume);
	
	if (!BidPriceYM.IsReady || !AskPriceYM.IsReady || !VolumeYM.IsReady)
	continue;

	if (YM.BidPrice != 0 && YM.AskPrice != 0)
	{

	var _quantityy = (decimal)(VolumeYM[0]+VolumeYM[1]) * 0.00001m;
	
	if (BidPriceYM[0]>AskPriceYM[1]) 
	{
	OnOrderFilledEvent = (algo, Symbol, FillPrice) =>
	{
	return new OneCancelsOtherTicketSet(
	algo.LimitOrder(YM.Symbol, -_quantityy, FillPrice * VarYM.TPLong, "Profit Long _Target"),
	algo.StopMarketOrder(YM.Symbol, -_quantityy, FillPrice * VarYM.SLLong, "Stop Long _Loss"));
	};
	this.EntryOrder = algorithm.MarketOrder(YM.Symbol, _quantityy, false, "Entry");
	break;
	}
	

	if (AskPriceYM[0]<BidPriceYM[1]) 
	{
	OnOrderFilledEvent = (algo, Symbol, FillPrice) =>
	{
	return new OneCancelsOtherTicketSet(
	algo.LimitOrder(YM.Symbol, -_quantityy, FillPrice * VarYM.TPShort, "Profit Short _Target"),
	algo.StopMarketOrder(YM.Symbol, -_quantityy, FillPrice * VarYM.SLShort, "Stop Short _Loss"));
	};
	this.EntryOrder = algorithm.MarketOrder(YM.Symbol, _quantityy, false, "Entry");
	break;	
	}

	}}}}
    return Enumerable.Empty<Insight>();

}
}
}
using System;
using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using System.Linq;
using QuantConnect;
using QuantConnect.Interfaces;
using QuantConnect.Indicators;
using QuantConnect.Securities;
using QuantConnect.Orders;

namespace Quant
{
public class Algos
{

        public RollingWindow<decimal> BidPriceYM = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPriceYM = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumeYM = new RollingWindow<decimal>(3);
         
        public RollingWindow<decimal> BidPriceNQ = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPriceNQ = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumeNQ = new RollingWindow<decimal>(3);
                
        public RollingWindow<decimal> BidPriceRTY = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPriceRTY = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumeRTY = new RollingWindow<decimal>(3);
                
        public RollingWindow<decimal> BidPriceEMD = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPriceEMD = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumeEMD = new RollingWindow<decimal>(3);
        
        //Metals
        public RollingWindow<decimal> BidPriceGC = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPriceGC = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumeGC = new RollingWindow<decimal>(3);
                
        public RollingWindow<decimal> BidPricePL = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPricePL = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumePL = new RollingWindow<decimal>(3);
         
        public RollingWindow<decimal> BidPricePA = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPricePA = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumePA = new RollingWindow<decimal>(3);
		
		//Currencies
	   	public RollingWindow<decimal> BidPriceGBP = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPriceGBP = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumeGBP = new RollingWindow<decimal>(3);
                
        public RollingWindow<decimal> BidPriceCAD = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPriceCAD = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumeCAD = new RollingWindow<decimal>(3);
                
        public RollingWindow<decimal> BidPriceJPY = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPriceJPY = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumeJPY = new RollingWindow<decimal>(3);
                
        public RollingWindow<decimal> BidPriceCHF = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPriceCHF = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumeCHF = new RollingWindow<decimal>(3);
                
        public RollingWindow<decimal> BidPriceEUR = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> AskPriceEUR = new RollingWindow<decimal>(3);
        public RollingWindow<decimal> VolumeEUR = new RollingWindow<decimal>(3);

public bool CanRunLocally { get; } = true;

public Language[] Languages { get; } = { Language.CSharp };
}
}
namespace QuantC
{
public static class VarGC
{
	public const decimal MaxQuantity = 20m ;
	public const decimal CentageLoss = 0.15m ;
	public const decimal valpoint = 5 ;
	public const decimal minprizefluct = 0.25m ;
	
	public const decimal Coefminsize = 0.0003m ;
	public const decimal coefBidAskSize = 1.5m ;
	public const decimal coefVolume = 1.5m ;
	public const int 	 minVolume = 500 ;
	public const decimal TPLong = 1.001m ;
	public const decimal SLLong = 0.95m ;
	public const decimal TPShort = 1.001m ;
	public const decimal SLShort = 0.95m ;
}
}
namespace QuantConnect
{
public static class VarES
{
	public const decimal MaxQuantity = 50m ;
	public const decimal CentageLoss = 0.1m ;
	public const decimal valpoint = 12.5m ;
	public const decimal minprizefluct = 0.25m ;
	
    public const decimal Coefminsize = minprizefluct ;
	public const decimal coefBidAskSize = 4m ;
	public const decimal coefVolume = 0.98m ;
	public const int	 minVolume = 15800 ;
	public const decimal TPLong = 1.001m ;
	public const decimal SLLong = 0.972m ;
	public const decimal TPShort = 1.001m ;
	public const decimal SLShort = 0.972m ;
}
}
namespace Quant
{
public static class VarCAD
{
	public const decimal MaxQuantity = 100000m ;
	public const decimal CentageLoss = 0.15m ;	
	public const decimal valpoint = 5m ; 	
	public const decimal minprizefluct = 0.00005m ;
	
	public const decimal Coefminsize = 0.0005m ;
	public const decimal coefBidAskSize = 1.8m ;	
	public const decimal coefVolume = 1.8m ;	
	public const int	 minVolume = 500 ;	
	public const decimal TPLong = 1.0025m ;	
	public const decimal SLLong = 0.95m ;	
	public const decimal TPShort = 1.0025m ; 	
	public const decimal SLShort = 0.95m ;
}
}
namespace Quant
{
public static class VarPL
{
	public const decimal MaxQuantity = 50m ;
	public const decimal CentageLoss = 0.15m ;
	public const decimal valpoint = 10 ;
	public const decimal minprizefluct = 0.1m ;
	
	public const decimal Coefminsize = 0.0002m ;
	public const decimal coefBidAskSize = 2.5m ;
	public const decimal coefVolume = 2.5m ;
	public const int	 minVolume = 100 ;
	public const decimal TPLong = 1.0009m ;
	public const decimal SLLong = 0.95m ;
	public const decimal TPShort = 1.0009m ;
	public const decimal SLShort = 0.95m ;
}
}
namespace Quant
{
public static class VarGBP
{
	public const decimal MaxQuantity = 62500m ;
	public const decimal CentageLoss = 0.15m ;	
	public const decimal valpoint = 6.25m ; 	
	public const decimal minprizefluct = 0.0001m ;
	
	public const decimal Coefminsize = 0.00013m ;	
	public const decimal coefBidAskSize = 2.5m ;	
	public const decimal coefVolume = 2.5m ;	
	public const int	 minVolume = 200 ;	
	public const decimal TPLong = 1.00029m ;	
	public const decimal SLLong = 0.95m ;	
	public const decimal TPShort = 1.00029m ; 	
	public const decimal SLShort = 0.95m ;
}
}
namespace Quant
{
public static class VarCHF
{
	public const decimal MaxQuantity = 100m ;
	public const decimal CentageLoss = 0.15m ;		
	public const decimal valpoint = 12.5m ; 	
	public const decimal minprizefluct = 0.0001m ;
	
	public const decimal Coefminsize = 0.00005m ;	
	public const decimal coefBidAskSize = 1.5m ;	
	public const decimal coefVolume = 1.5m ;	
	public const int     minVolume =1000 ;	
	public const decimal TPLong = 1.001m ;	
	public const decimal SLLong = 0.993m ;	
	public const decimal TPShort = 1.001m ;
	public const decimal SLShort = 0.993m ;
}
}
namespace Quant
{
public static class VarRTY
{
	public const decimal MaxQuantity = 50m ;
	public const decimal CentageLoss = 0.15m ; 
	public const decimal valpoint = 5 ; 
	public const decimal minprizefluct = 0.1m ;
	
	public const decimal Coefminsize = 0.0005m ;
	public const decimal coefBidAskSize = 2m ; 
	public const decimal coefVolume = 2m ; 
	public const int	 minVolume = 100 ; 
	public const decimal TPLong = 1.0015m ; 
	public const decimal SLLong = 0.95m ; 
	public const decimal TPShort = 1.0015m ; 
	public const decimal SLShort = 0.95m ;
}
}
namespace Quant
{
public static class VarJPY
{
	public const decimal MaxQuantity = 12500000m ;
	public const decimal CentageLoss = 0.15m ;	
	public const decimal valpoint = 6.25m ; 	
	public const decimal minprizefluct = 0.0000005m ;
	
	public const decimal Coefminsize = 0.00001m ;	
	public const decimal coefBidAskSize = 1.5m ;	
	public const decimal coefVolume = 1.5m ;	
	public const int	 minVolume = 1000 ;	
	public const decimal TPLong = 1.0012m ;	
	public const decimal SLLong = 0.96m ;	
	public const decimal TPShort = 1.0012m ; 	
	public const decimal SLShort = 0.96m ;
}
}
namespace Quant
{
public static class VarYM
{
	public const decimal MaxQuantity = 5m ;
	public const decimal CentageLoss = 0.15m ;
	public const decimal valpoint = 5m ;
	public const decimal minprizefluct = 1m ;
	
	public const decimal Coefminsize = 0.0002m ;
	public const decimal coefBidAskSize = 1.5m ;
	public const decimal coefVolume = 1.5m ;
	public const int	 minVolume = 800 ;
	public const decimal TPLong = 1.0005m ;
	public const decimal SLLong = 0.94m ;
	public const decimal TPShort = 1.0005m ;
	public const decimal SLShort = 0.94m ;
}
}
namespace Quant
{
public static class VarEMD
{	
	public const decimal MaxQuantity = 100m ;
	public const decimal CentageLoss = 0.15m ;	
	public const decimal valpoint = 10 ; 	
	public const decimal minprizefluct = 0.1m ;
	
	public const decimal Coefminsize = 0.0001m ;	
	public const decimal coefBidAskSize = 4m ;	
	public const decimal coefVolume = 4m ;	
	public const int	 minVolume = 100 ;	
	public const decimal TPLong = 1.001m ;	
	public const decimal SLLong = 0.95m ;	
	public const decimal TPShort = 1.001m ; 	
	public const decimal SLShort = 0.95m ;
}
}
using System;
using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using System.Linq;
using QuantConnect;
using QuantConnect.Securities.Future;
using QuantConnect.Interfaces;
using QuantConnect.Indicators;
using QuantConnect.Securities;
using QuantConnect.Algorithm.Framework.Execution ;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Orders;
using Quant;

namespace Quant
{

public partial class Algorithm_ES : NullAlphaModel
{

	public RollingWindow<decimal> BidPriceES = new RollingWindow<decimal>(3);
    public RollingWindow<decimal> AskPriceES = new RollingWindow<decimal>(3);
    public RollingWindow<decimal> VolumeES = new RollingWindow<decimal>(3);

    public OrderTicket EntryOrder { get; set; }
    public Func<QCAlgorithm, string, decimal, OneCancelsOtherTicketSet> OnOrderFilledEvent { get; set; }
    public OneCancelsOtherTicketSet ProfitLossOrders { get; set; }
    
    private readonly Symbol _symbol;
    public Algorithm_ES(Symbol symbol)
    {
        _symbol = symbol;
    }

public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice slice)
{
	var accountCurrencyCash = algorithm.Portfolio.TotalPortfolioValue;

    foreach(var chain in slice.FutureChains)
    {

    // remplacer les lettre entre guillemet par l'abreviation correspondant au contract analysé. 
	if (chain.Value.Symbol.StartsWith("ES"))
    {
	var ES = (from futuresContract in chain.Value.OrderBy(x => x.Expiry)
	where futuresContract.Expiry > algorithm.Time.Date.AddDays(1) 
	select futuresContract).FirstOrDefault();
    
    if (ES != null)
	{
		
	BidPriceES.Add(ES.BidPrice);
	AskPriceES.Add(ES.AskPrice);
	VolumeES.Add(ES.Volume);
	
	if (!BidPriceES.IsReady || !AskPriceES.IsReady || !VolumeES.IsReady)
	continue;

	if (ES.BidPrice != 0 && ES.AskPrice != 0)
	{

	var _quantityy = (decimal)(VolumeES[0]+VolumeES[1]) * 0.00001m;
	
	if (BidPriceES[0]>AskPriceES[1]) 
	{
	OnOrderFilledEvent = (algo, Symbol, FillPrice) =>
	{
	return new OneCancelsOtherTicketSet(
	algo.LimitOrder(ES.Symbol, -_quantityy, FillPrice * VarES.TPLong, "Profit Long _Target"),
	algo.StopMarketOrder(ES.Symbol, -_quantityy, FillPrice * VarES.SLLong, "Stop Long _Loss"));
	};
	this.EntryOrder = algorithm.MarketOrder(ES.Symbol, _quantityy, false, "Entry");
	break;
	}
	

	if (AskPriceES[0]<BidPriceES[1]) 
	{
	OnOrderFilledEvent = (algo, Symbol, FillPrice) =>
	{
	return new OneCancelsOtherTicketSet(
	algo.LimitOrder(ES.Symbol, -_quantityy, FillPrice * VarES.TPShort, "Profit Short _Target"),
	algo.StopMarketOrder(ES.Symbol, -_quantityy, FillPrice * VarES.SLShort, "Stop Short _Loss"));
	};
	this.EntryOrder = algorithm.MarketOrder(ES.Symbol, _quantityy, false, "Entry");
	break;	
	}

	}}}}
    return Enumerable.Empty<Insight>();

}
}
}
using System;
using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using System.Linq;
using QuantConnect;
using QuantConnect.Securities.Future;
using QuantConnect.Interfaces;
using QuantConnect.Indicators;
using QuantConnect.Securities;
using QuantConnect.Algorithm.Framework.Execution ;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Orders;
using Quant;

namespace Quant
{
public partial class Algorithm : QCAlgorithm
{
	private String[] futureSymbols = new[] {"ES", "YM"};
	private Dictionary<Symbol, FuturesChain> contract_chains = new Dictionary<Symbol, FuturesChain>();
	private Dictionary<Symbol, Future> contracts = new Dictionary<Symbol, Future>();
	
	public OrderTicket EntryOrder { get; set; }
    public Func<QCAlgorithm, string, decimal, OneCancelsOtherTicketSet> OnOrderFilledEvent { get; set; }
    public OneCancelsOtherTicketSet ProfitLossOrders { get; set; }
	
	private Symbol _ES;
	private Symbol _YM;

public override void Initialize()
{
	SetStartDate(2000, 01, 01);
    SetEndDate(2010, 01, 01);
    SetCash(1000000);

foreach (var futureSymbol in futureSymbols) 
{
	Debug($"Registering {futureSymbol}");
	Future fut = AddFuture(futureSymbol, Resolution.Minute);
	fut.SetFilter(universe => universe.FrontMonth());
}

_ES = QuantConnect.Symbol.Create("ES", SecurityType.Future, Market.USA);
_YM = QuantConnect.Symbol.Create("YM", SecurityType.Future, Market.USA);

AddAlpha(new Algorithm_ES(_ES));
AddAlpha(new Algorithm_YM(_YM));

SetSecurityInitializer(x => x.SetSlippageModel(new CustomSlippageModel(this)));
SetBrokerageModel(BrokerageName.AlphaStreams);
SetExecution(new VolumeWeightedAveragePriceExecutionModel());

AddRiskManagement(new MaximumUnrealizedProfitPercentPerSecurity(0.1m));
AddRiskManagement(new MaximumDrawdownPercentPerSecurity(0.1m));

}

public class FuturesUniverseSelectionModel : FutureUniverseSelectionModel
{
	public FuturesUniverseSelectionModel(Func<DateTime, IEnumerable<Symbol>> futureChainSymbolSelector)
	:base(TimeSpan.FromDays(1), futureChainSymbolSelector){}
		
	public FutureFilterUniverse filter(FutureFilterUniverse filter){
	return filter.Expiration(TimeSpan.Zero, TimeSpan.FromDays(182)).OnlyApplyFilterAtMarketOpen();}
}

public class CustomSlippageModel : ISlippageModel
{
            private readonly QCAlgorithm _algorithm;
            
            public RollingWindow<decimal> High = new RollingWindow<decimal>(2);
            public RollingWindow<decimal> Low = new RollingWindow<decimal>(2);
            public RollingWindow<decimal> Volume = new RollingWindow<decimal>(2);
			
            public CustomSlippageModel(QCAlgorithm algorithm)
            {
				_algorithm = algorithm;
			}

            public decimal GetSlippageApproximation(Security asset, Order order)
            {			
    			High.Add(asset.High);
    			Low.Add(asset.Low);
    			Volume.Add(asset.Volume);
    			
    			var orderVolume = order.AbsoluteQuantity;
    			var slippage = (High[0]-Low[0]) * 0.01m / (Volume[0]/orderVolume);
    			
    			if (asset.Symbol.Value.StartsWith("ES"))
    			{
    			if (((High[0]-Low[0]) * 0.01m / (Volume[0]/orderVolume)) < VarES.minprizefluct)
    			{
    				return VarES.minprizefluct ;
    			}
    			}
    			
    			if (asset.Symbol.Value.StartsWith("YM"))
    			{
    			if (((High[0]-Low[0]) * 0.01m / (Volume[0]/orderVolume)) < VarES.minprizefluct)
    			{
    				return VarYM.minprizefluct ;
    			}
    			}
    			
				return slippage;
            }
}

public override void OnOrderEvent(OrderEvent orderEvent)
{
        	if (EntryOrder != null)
            {
                this.EntryOrder = null;
            }

            if (orderEvent.Status == OrderStatus.Filled || orderEvent.Status == OrderStatus.PartiallyFilled)
            {
                if (this.OnOrderFilledEvent != null)
                {
                    this.ProfitLossOrders = OnOrderFilledEvent(this, orderEvent.Symbol, orderEvent.FillPrice);
                    OnOrderFilledEvent = null;
                } 
                else if (this.ProfitLossOrders != null)
                {
                    this.ProfitLossOrders.Filled();
                    this.ProfitLossOrders = null;
                }
            }
}
}
}

namespace Quant
{
    public class OneCancelsOtherTicketSet
    {
        public OneCancelsOtherTicketSet(params OrderTicket[] orderTickets)
        {
            this.OrderTickets = orderTickets;
        }

        private OrderTicket[] OrderTickets { get; set; }

        public void Filled()
        {
            // Cancel all the outstanding tickets.
            foreach (var orderTicket in this.OrderTickets)
            {
                if (orderTicket.Status == OrderStatus.Submitted)
                {
                    orderTicket.Cancel();
                }
            }
        }
	}
}
namespace Quant
{
public static class VarEUR
{
	public const decimal MaxQuantity = 1000m ;
	public const decimal CentageLoss = 0.15m ;
	public const decimal valpoint = 6.25m ; 	
	public const decimal minprizefluct = 0.00005m ;
	
	public const decimal Coefminsize = 0.00055m ;	
	public const decimal coefBidAskSize = 1.5m ;	
	public const decimal coefVolume = 1.5m ;	
	public const int	 minVolume = 100 ;	
	public const decimal TPLong = 1.0011m ;	
	public const decimal SLLong = 0.95m ;	
	public const decimal TPShort = 1.0011m ; 	
	public const decimal SLShort = 0.95m ;
}
}
namespace Quant
{
public static class VarNQ
{
	public const decimal MaxQuantity = 20m ;
	public const decimal CentageLoss = 0.15m ;
	public const decimal valpoint = 5 ;
	public const decimal minprizefluct = 0.25m ;
	
	public const decimal Coefminsize = 0.0005m ;
	public const decimal coefBidAskSize = 1.8m ;
	public const decimal coefVolume = 1.8m ;
	public const int 	 minVolume = 900 ;
	public const decimal TPLong = 1.001m ;
	public const decimal SLLong = 0.95m ;
	public const decimal TPShort = 1.001m ;
	public const decimal SLShort = 0.95m ;
}
}