chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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 QuantConnect.Data;
|
||||
using QuantConnect.Orders.Fees;
|
||||
using QuantConnect.Orders.Fills;
|
||||
using QuantConnect.Orders.Slippage;
|
||||
|
||||
namespace QuantConnect.Securities.Cfd
|
||||
{
|
||||
/// <summary>
|
||||
/// CFD Security Object Implementation for CFD Assets
|
||||
/// </summary>
|
||||
/// <seealso cref="Security"/>
|
||||
public class Cfd : Security
|
||||
{
|
||||
private readonly ContractSymbolProperties _symbolProperties;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the CFD 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 Cfd(SecurityExchangeHours exchangeHours,
|
||||
Cash quoteCurrency,
|
||||
SubscriptionDataConfig config,
|
||||
SymbolProperties symbolProperties,
|
||||
ICurrencyConverter currencyConverter,
|
||||
IRegisteredSecurityDataTypesProvider registeredTypes)
|
||||
: this(exchangeHours, quoteCurrency, config, new ContractSymbolProperties(symbolProperties), currencyConverter, registeredTypes)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the CFD 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 Cfd(SecurityExchangeHours exchangeHours,
|
||||
Cash quoteCurrency,
|
||||
SubscriptionDataConfig config,
|
||||
ContractSymbolProperties symbolProperties,
|
||||
ICurrencyConverter currencyConverter,
|
||||
IRegisteredSecurityDataTypesProvider registeredTypes)
|
||||
: base(config,
|
||||
quoteCurrency,
|
||||
symbolProperties,
|
||||
new CfdExchange(exchangeHours),
|
||||
new CfdCache(),
|
||||
new SecurityPortfolioModel(),
|
||||
new ImmediateFillModel(),
|
||||
new ConstantFeeModel(0),
|
||||
NullSlippageModel.Instance,
|
||||
new ImmediateSettlementModel(),
|
||||
Securities.VolatilityModel.Null,
|
||||
new SecurityMarginModel(50m),
|
||||
new CfdDataFilter(),
|
||||
new SecurityPriceVariationModel(),
|
||||
currencyConverter,
|
||||
registeredTypes,
|
||||
Securities.MarginInterestRateModel.Null
|
||||
)
|
||||
{
|
||||
Holdings = new CfdHolding(this, currencyConverter);
|
||||
_symbolProperties = symbolProperties;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the CFD 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 for storing Security data</param>
|
||||
public Cfd(Symbol symbol,
|
||||
SecurityExchangeHours exchangeHours,
|
||||
Cash quoteCurrency,
|
||||
SymbolProperties symbolProperties,
|
||||
ICurrencyConverter currencyConverter,
|
||||
IRegisteredSecurityDataTypesProvider registeredTypes,
|
||||
SecurityCache securityCache)
|
||||
: this(symbol, exchangeHours, quoteCurrency, new ContractSymbolProperties(symbolProperties), currencyConverter, registeredTypes, securityCache)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the CFD 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 for storing Security data</param>
|
||||
public Cfd(Symbol symbol,
|
||||
SecurityExchangeHours exchangeHours,
|
||||
Cash quoteCurrency,
|
||||
ContractSymbolProperties symbolProperties,
|
||||
ICurrencyConverter currencyConverter,
|
||||
IRegisteredSecurityDataTypesProvider registeredTypes,
|
||||
SecurityCache securityCache)
|
||||
: base(symbol,
|
||||
quoteCurrency,
|
||||
symbolProperties,
|
||||
new CfdExchange(exchangeHours),
|
||||
securityCache,
|
||||
new SecurityPortfolioModel(),
|
||||
new ImmediateFillModel(),
|
||||
new ConstantFeeModel(0),
|
||||
NullSlippageModel.Instance,
|
||||
new ImmediateSettlementModel(),
|
||||
Securities.VolatilityModel.Null,
|
||||
new SecurityMarginModel(50m),
|
||||
new CfdDataFilter(),
|
||||
new SecurityPriceVariationModel(),
|
||||
currencyConverter,
|
||||
registeredTypes,
|
||||
Securities.MarginInterestRateModel.Null
|
||||
)
|
||||
{
|
||||
Holdings = new CfdHolding(this, currencyConverter);
|
||||
_symbolProperties = symbolProperties;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the contract multiplier for this CFD security
|
||||
/// </summary>
|
||||
public decimal ContractMultiplier
|
||||
{
|
||||
get { return _symbolProperties.ContractMultiplier; }
|
||||
set { _symbolProperties.SetContractMultiplier(value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum price variation for this CFD security
|
||||
/// </summary>
|
||||
public decimal MinimumPriceVariation
|
||||
{
|
||||
get { return SymbolProperties.MinimumPriceVariation; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decomposes the specified currency pair into a base and quote currency provided as out parameters
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input symbol to be decomposed</param>
|
||||
/// <param name="symbolProperties">The symbol properties for this security</param>
|
||||
/// <param name="baseCurrency">The output base currency</param>
|
||||
/// <param name="quoteCurrency">The output quote currency</param>
|
||||
public static void DecomposeCurrencyPair(Symbol symbol, SymbolProperties symbolProperties, out string baseCurrency, out string quoteCurrency)
|
||||
{
|
||||
quoteCurrency = symbolProperties.QuoteCurrency;
|
||||
if (symbol.Value.EndsWith(quoteCurrency))
|
||||
{
|
||||
baseCurrency = symbol.Value.RemoveFromEnd(quoteCurrency);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException($"Symbol doesn't end with {quoteCurrency}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the securities symbol
|
||||
/// </summary>
|
||||
public static implicit operator Symbol(Cfd 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.Cfd
|
||||
{
|
||||
/// <summary>
|
||||
/// CFD 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 CfdCache : 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.Cfd
|
||||
{
|
||||
/// <summary>
|
||||
/// CFD packet by packet data filtering mechanism for dynamically detecting bad ticks.
|
||||
/// </summary>
|
||||
/// <seealso cref="SecurityDataFilter"/>
|
||||
public class CfdDataFilter : 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.Cfd
|
||||
{
|
||||
/// <summary>
|
||||
/// CFD exchange class - information and helper tools for CFD exchange properties
|
||||
/// </summary>
|
||||
/// <seealso cref="SecurityExchange"/>
|
||||
public class CfdExchange : 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="CfdExchange"/> class using the specified
|
||||
/// exchange hours to determine open/close times
|
||||
/// </summary>
|
||||
/// <param name="exchangeHours">Contains the weekly exchange schedule plus holidays</param>
|
||||
public CfdExchange(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.Cfd
|
||||
{
|
||||
/// <summary>
|
||||
/// CFD holdings implementation of the base securities class
|
||||
/// </summary>
|
||||
/// <seealso cref="SecurityHolding"/>
|
||||
public class CfdHolding : SecurityHolding
|
||||
{
|
||||
/// <summary>
|
||||
/// CFD Holding Class constructor
|
||||
/// </summary>
|
||||
/// <param name="security">The CFD security being held</param>
|
||||
/// <param name="currencyConverter">A currency converter instance</param>
|
||||
public CfdHolding(Cfd security, ICurrencyConverter currencyConverter)
|
||||
: base(security, currencyConverter)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user