Files
quantconnect--lean/Common/Algorithm/Framework/Alphas/Analysis/ISecurityValuesProvider.cs
Martin Molinero c39638668c Overall performance improvements
- `FactorFile` will keep an ordered reversed list with the dates.
Calling `Reverse()` on the `SortedList` is expensive.
- `MapFiles` will keep first and last date, so we don't need to call
`First()` and `Last()` multiple times.
- `Liquidate` will go through all the algorithms securities only if
necessary
- `TradeBar` parsing will not call `new T` for pure `TradeBar` which is
expensive
- Removing `Lazy` hash code and security type for the
`SecurityIdentifier`, replacing for direct initialization. Accessing the
`Lazy` value adds an overhead.
- Replacing `Enum` to string for hardcoded switch statement. `Enum.ToString` is expensive.
- `DataManager` will be lazy for counting the subscriptions for
determining if its above the limit
- Adding `AlgorithmSecurityValuesProvider.GetAllValues()`, removes the
need to fetch all the security keys twice.
- During universe selection, will not try to re add already added symbol
2019-04-22 10:47:27 -03:00

63 lines
2.8 KiB
C#

/*
* 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.Collections.Generic;
namespace QuantConnect.Algorithm.Framework.Alphas.Analysis
{
/// <summary>
/// Provides a simple abstraction that returns a security's current price and volatility.
/// This facilitates testing by removing the dependency of IAlgorithm on the analysis components
/// </summary>
public interface ISecurityValuesProvider
{
/// <summary>
/// Gets the current values for the specified symbol (price/volatility)
/// </summary>
/// <param name="symbol">The symbol to get price/volatility for</param>
/// <returns>The insight target values for the specified symbol</returns>
SecurityValues GetValues(Symbol symbol);
/// <summary>
/// Gets the current values for all the algorithm securities (price/volatility)
/// </summary>
/// <returns>The insight target values for all the algorithm securities</returns>
ReadOnlySecurityValuesCollection GetAllValues();
}
/// <summary>
/// Provides extension methods for <see cref="ISecurityValuesProvider"/>
/// </summary>
public static class SecurityValuesProviderExtensions
{
/// <summary>
/// Creates a new instance of <see cref="ReadOnlySecurityValuesCollection"/> to hold all <see cref="SecurityValues"/> for
/// the specified symbol at the current instant in time
/// </summary>
/// <param name="securityValuesProvider">Security values provider fetches security values for each symbol</param>
/// <param name="symbols">The symbols to get values for</param>
/// <returns>A collection of</returns>
public static ReadOnlySecurityValuesCollection GetValues(this ISecurityValuesProvider securityValuesProvider, ICollection<Symbol> symbols)
{
var values = new Dictionary<Symbol, SecurityValues>(symbols.Count);
foreach (var symbol in symbols)
{
values[symbol] = securityValuesProvider.GetValues(symbol);
}
return new ReadOnlySecurityValuesCollection(values);
}
}
}