chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Orders.Fees;
|
||||
using QuantConnect.Orders.Fills;
|
||||
using QuantConnect.Orders.Slippage;
|
||||
|
||||
namespace QuantConnect.Securities.Index
|
||||
{
|
||||
/// <summary>
|
||||
/// INDEX Security Object Implementation for INDEX Assets
|
||||
/// </summary>
|
||||
/// <seealso cref="Security"/>
|
||||
public class Index : Security
|
||||
{
|
||||
private bool _isTradable;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether or not this security should be considered tradable
|
||||
/// </summary>
|
||||
public override bool IsTradable {
|
||||
get => _isTradable;
|
||||
set
|
||||
{
|
||||
if (value) ManualSetIsTradable = true;
|
||||
_isTradable = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Field to check if the user has manually set IsTradable field to true
|
||||
/// </summary>
|
||||
internal bool ManualSetIsTradable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the INDEX security
|
||||
/// </summary>
|
||||
/// <param name="exchangeHours">Defines the hours this exchange is open</param>
|
||||
/// <param name="quoteCurrency">The cash object that represent the quote currency</param>
|
||||
/// <param name="config">The subscription configuration for this security</param>
|
||||
/// <param name="symbolProperties">The symbol properties for this security</param>
|
||||
/// <param name="currencyConverter">Currency converter used to convert <see cref="CashAmount"/>
|
||||
/// instances into units of the account currency</param>
|
||||
/// <param name="registeredTypes">Provides all data types registered in the algorithm</param>
|
||||
public Index(SecurityExchangeHours exchangeHours,
|
||||
Cash quoteCurrency,
|
||||
SubscriptionDataConfig config,
|
||||
SymbolProperties symbolProperties,
|
||||
ICurrencyConverter currencyConverter,
|
||||
IRegisteredSecurityDataTypesProvider registeredTypes)
|
||||
: base(config,
|
||||
quoteCurrency,
|
||||
symbolProperties,
|
||||
new IndexExchange(exchangeHours),
|
||||
new IndexCache(),
|
||||
new SecurityPortfolioModel(),
|
||||
new ImmediateFillModel(),
|
||||
new ConstantFeeModel(0),
|
||||
NullSlippageModel.Instance,
|
||||
new ImmediateSettlementModel(),
|
||||
Securities.VolatilityModel.Null,
|
||||
new SecurityMarginModel(50m),
|
||||
new IndexDataFilter(),
|
||||
new SecurityPriceVariationModel(),
|
||||
currencyConverter,
|
||||
registeredTypes,
|
||||
Securities.MarginInterestRateModel.Null
|
||||
)
|
||||
{
|
||||
IsTradable = false; //Index are non tradable by default
|
||||
Holdings = new IndexHolding(this, currencyConverter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the INDEX security
|
||||
/// </summary>
|
||||
/// <param name="symbol">The security's symbol</param>
|
||||
/// <param name="exchangeHours">Defines the hours this exchange is open</param>
|
||||
/// <param name="quoteCurrency">The cash object that represent the quote currency</param>
|
||||
/// <param name="symbolProperties">The symbol properties for this security</param>
|
||||
/// <param name="currencyConverter">Currency converter used to convert <see cref="CashAmount"/>
|
||||
/// instances into units of the account currency</param>
|
||||
/// <param name="registeredTypes">Provides all data types registered in the algorithm</param>
|
||||
/// <param name="securityCache">Cache to store security information</param>
|
||||
public Index(Symbol symbol,
|
||||
SecurityExchangeHours exchangeHours,
|
||||
Cash quoteCurrency,
|
||||
SymbolProperties symbolProperties,
|
||||
ICurrencyConverter currencyConverter,
|
||||
IRegisteredSecurityDataTypesProvider registeredTypes,
|
||||
SecurityCache securityCache)
|
||||
: base(symbol,
|
||||
quoteCurrency,
|
||||
symbolProperties,
|
||||
new IndexExchange(exchangeHours),
|
||||
securityCache,
|
||||
new SecurityPortfolioModel(),
|
||||
new ImmediateFillModel(),
|
||||
new ConstantFeeModel(0),
|
||||
NullSlippageModel.Instance,
|
||||
new ImmediateSettlementModel(),
|
||||
Securities.VolatilityModel.Null,
|
||||
new SecurityMarginModel(50m),
|
||||
new IndexDataFilter(),
|
||||
new SecurityPriceVariationModel(),
|
||||
currencyConverter,
|
||||
registeredTypes,
|
||||
Securities.MarginInterestRateModel.Null
|
||||
)
|
||||
{
|
||||
IsTradable = false; //Index are non tradable by default
|
||||
Holdings = new IndexHolding(this, currencyConverter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the security to its initial state by marking it as uninitialized and non-tradable
|
||||
/// and clearing the subscriptions.
|
||||
/// </summary>
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
ManualSetIsTradable = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the securities symbol
|
||||
/// </summary>
|
||||
public static implicit operator Symbol(Index security) => security.Symbol;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Securities.Index
|
||||
{
|
||||
/// <summary>
|
||||
/// INDEX specific caching support
|
||||
/// </summary>
|
||||
/// <remarks>Class is virtually empty and scheduled to be made obsolete. Potentially could be used for user data storage.</remarks>
|
||||
/// <seealso cref="SecurityCache"/>
|
||||
public class IndexCache : SecurityCache
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Securities.Index
|
||||
{
|
||||
/// <summary>
|
||||
/// Index packet by packet data filtering mechanism for dynamically detecting bad ticks.
|
||||
/// </summary>
|
||||
/// <seealso cref="SecurityDataFilter"/>
|
||||
public class IndexDataFilter : SecurityDataFilter
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Securities.Index
|
||||
{
|
||||
/// <summary>
|
||||
/// INDEX exchange class - information and helper tools for Index exchange properties
|
||||
/// </summary>
|
||||
/// <seealso cref="SecurityExchange"/>
|
||||
public class IndexExchange : SecurityExchange
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of trading days per year for this security, used for performance statistics.
|
||||
/// </summary>
|
||||
public override int TradingDaysPerYear
|
||||
{
|
||||
// 365 - Saturdays = 313;
|
||||
get { return 313; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IndexExchange"/> class using the specified
|
||||
/// exchange hours to determine open/close times
|
||||
/// </summary>
|
||||
/// <param name="exchangeHours">Contains the weekly exchange schedule plus holidays</param>
|
||||
public IndexExchange(SecurityExchangeHours exchangeHours)
|
||||
: base(exchangeHours)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Securities.Index
|
||||
{
|
||||
/// <summary>
|
||||
/// Index holdings implementation of the base securities class
|
||||
/// </summary>
|
||||
/// <seealso cref="SecurityHolding"/>
|
||||
public class IndexHolding : SecurityHolding
|
||||
{
|
||||
/// <summary>
|
||||
/// INDEX Holding Class constructor
|
||||
/// </summary>
|
||||
/// <param name="security">The INDEX security being held</param>
|
||||
/// <param name="currencyConverter">A currency converter instance</param>
|
||||
public IndexHolding(Index security, ICurrencyConverter currencyConverter)
|
||||
: base(security, currencyConverter)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Securities.Index
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods for Index Symbols
|
||||
/// </summary>
|
||||
public static class IndexSymbol
|
||||
{
|
||||
private static readonly Dictionary<string, string> _indexExchange = new(StringComparer.InvariantCultureIgnoreCase)
|
||||
{
|
||||
{ "SPX", Market.CBOE },
|
||||
{ "NDX", "NASDAQ" },
|
||||
{ "VIX", Market.CBOE },
|
||||
{ "SPXW", Market.CBOE },
|
||||
{ "NQX", "NASDAQ" },
|
||||
{ "VIXW", Market.CBOE },
|
||||
{ "RUT", "RUSSELL" },
|
||||
{ "BKX", "PHLX" },
|
||||
{ "BXD", Market.CBOE },
|
||||
{ "BXM", Market.CBOE },
|
||||
{ "BXN", Market.CBOE },
|
||||
{ "BXR", Market.CBOE },
|
||||
{ "CLL", Market.CBOE },
|
||||
{ "COR1M", Market.CBOE },
|
||||
{ "COR1Y", Market.CBOE },
|
||||
{ "COR30D", Market.CBOE },
|
||||
{ "COR3M", Market.CBOE },
|
||||
{ "COR6M", Market.CBOE },
|
||||
{ "COR9M", Market.CBOE },
|
||||
{ "DJX", Market.CBOE },
|
||||
{ "DUX", Market.CBOE },
|
||||
{ "DVS", Market.CBOE },
|
||||
{ "DXL", Market.CBOE },
|
||||
{ "EVZ", Market.CBOE },
|
||||
{ "FVX", Market.CBOE },
|
||||
{ "GVZ", Market.CBOE },
|
||||
{ "HGX", "PHLX" },
|
||||
{ "MID", "PSE" },
|
||||
{ "MIDG", Market.CBOE },
|
||||
{ "MIDV", Market.CBOE },
|
||||
{ "MRUT", "RUSSELL" },
|
||||
{ "NYA", "PSE" },
|
||||
{ "NYFANG", "NYSE" },
|
||||
{ "NYXBT", "NYSE" },
|
||||
{ "OEX", Market.CBOE },
|
||||
{ "OSX", "PHLX" },
|
||||
{ "OVX", Market.CBOE },
|
||||
{ "XDA", "PHLX" },
|
||||
{ "XDB", "PHLX" },
|
||||
{ "XEO", Market.CBOE },
|
||||
{ "XMI", "PSE" },
|
||||
{ "XNDX", "NASDAQ" },
|
||||
{ "XSP", Market.CBOE },
|
||||
{ "BRR", Market.CME },
|
||||
{ "BRTI", Market.CME },
|
||||
{ "CEX", Market.CBOE },
|
||||
{ "COMP", "NASDAQ" },
|
||||
{ "DJCIAGC", Market.CME },
|
||||
{ "DJCICC", Market.CME },
|
||||
{ "DJCIGC", Market.CME },
|
||||
{ "DJCIGR", Market.CME },
|
||||
{ "DJCIIK", Market.CME },
|
||||
{ "DJCIKC", Market.CME },
|
||||
{ "DJCISB", Market.CME },
|
||||
{ "DJCISI", Market.CME },
|
||||
{ "DJR", Market.CBOE },
|
||||
{ "DRG", "PSE" },
|
||||
{ "PUT", Market.CBOE },
|
||||
{ "RUA", "RUSSELL" },
|
||||
{ "RUI", "RUSSELL" },
|
||||
{ "RVX", Market.CBOE },
|
||||
{ "SET", Market.CBOE },
|
||||
{ "SGX", Market.CBOE },
|
||||
{ "SKEW", Market.CBOE },
|
||||
{ "SPSIBI", "PSE" },
|
||||
{ "SVX", Market.CBOE },
|
||||
{ "TNX", Market.CBOE },
|
||||
{ "TYX", Market.CBOE },
|
||||
{ "UKX", "ISE" },
|
||||
{ "UTY", "PHLX" },
|
||||
{ "VIF", Market.CBOE },
|
||||
{ "VIN", Market.CBOE },
|
||||
{ "VIX1D", Market.CBOE },
|
||||
{ "VIX1Y", Market.CBOE },
|
||||
{ "VIX3M", Market.CBOE },
|
||||
{ "VIX6M", Market.CBOE },
|
||||
{ "VIX9D", Market.CBOE },
|
||||
{ "VOLI", "NASDAQ" },
|
||||
{ "VPD", Market.CBOE },
|
||||
{ "VPN", Market.CBOE },
|
||||
{ "VVIX", Market.CBOE },
|
||||
{ "VWA", Market.CBOE },
|
||||
{ "VWB", Market.CBOE },
|
||||
{ "VXD", Market.CBOE },
|
||||
{ "VXN", Market.CBOE },
|
||||
{ "VXO", Market.CBOE },
|
||||
{ "VXSLV", Market.CBOE },
|
||||
{ "VXTH", Market.CBOE },
|
||||
{ "VXTLT", Market.CBOE },
|
||||
{ "XAU", "PHLX" },
|
||||
{ "DJI", Market.CME },
|
||||
{ "DWCPF", Market.CME },
|
||||
{ "UTIL", Market.CME },
|
||||
{ "DAX", Market.EUREX },
|
||||
{ "DXY", "NYBOT" },
|
||||
{ "RLS", Market.CBOE },
|
||||
{ "SMLG", "PSE" },
|
||||
{ "SPGSCI", Market.CME },
|
||||
{ "VAF", Market.CBOE },
|
||||
{ "VRO", Market.CBOE },
|
||||
{ "AEX", "FTA" },
|
||||
{ "DJINET", Market.CBOE },
|
||||
{ "DTX", Market.CBOE },
|
||||
{ "SP600", Market.CBOE },
|
||||
{ "SPSV", "PSE" },
|
||||
{ "FTW5000", "AMEX" },
|
||||
{ "DWCF", "PSE" },
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, string> _indexMarket = new(StringComparer.InvariantCultureIgnoreCase)
|
||||
{
|
||||
{ "HSI", Market.HKFE },
|
||||
{ "N225", Market.OSE },
|
||||
{ "SX5E", Market.EUREX },
|
||||
{ "DAX", Market.EUREX }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the actual exchange the index lives on
|
||||
/// </summary>
|
||||
/// <remarks>Useful for live trading</remarks>
|
||||
/// <returns>The exchange of the index</returns>
|
||||
public static string GetIndexExchange(Symbol symbol)
|
||||
{
|
||||
return _indexExchange.TryGetValue(symbol.Value, out var market)
|
||||
? market
|
||||
: symbol.ID.Market;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lean market for this index ticker
|
||||
/// </summary>
|
||||
/// <returns>The market of the index</returns>
|
||||
public static bool TryGetIndexMarket(string ticker, out string market)
|
||||
{
|
||||
return _indexMarket.TryGetValue(ticker, out market);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user