Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Algorithm.CSharp/QuantConnect.Algorithm.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<DebugType>portable</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
<PackageReference Include="Accord" Version="3.6.0" />
<PackageReference Include="Accord.Fuzzy" Version="3.6.0" />
<PackageReference Include="Accord.MachineLearning" Version="3.6.0" />
Expand Down
3 changes: 1 addition & 2 deletions Algorithm.Framework/Alphas/BasePairsTradingAlphaModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def __init__(self, lookback = 1,
self.pairs = dict()
self.securities = set()

resolution_string = Extensions.get_enum_string(resolution, Resolution)
self.name = f'{self.__class__.__name__}({self.lookback},{resolution_string},{Extensions.normalize_to_str(threshold)})'
self.name = f'{self.__class__.__name__}({self.lookback},{resolution},{Extensions.normalize_to_str(threshold)})'


def update(self, algorithm, data):
Expand Down
5 changes: 1 addition & 4 deletions Algorithm.Framework/Alphas/ConstantAlphaModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def __init__(self, type, direction, period, magnitude = None, confidence = None,
self.securities = []
self.insights_time_by_symbol = {}

type_string = Extensions.GetEnumString(type, InsightType)
direction_string = Extensions.GetEnumString(direction, InsightDirection)

self.Name = '{}({},{},{}'.format(self.__class__.__name__, type_string, direction_string, strfdelta(period))
self.Name = '{}({},{},{}'.format(self.__class__.__name__, type, direction, strfdelta(period))
if magnitude is not None:
self.Name += ',{}'.format(magnitude)
if confidence is not None:
Expand Down
3 changes: 1 addition & 2 deletions Algorithm.Framework/Alphas/EmaCrossAlphaModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def __init__(self,
self.prediction_interval = Time.multiply(Extensions.to_time_span(resolution), fast_period)
self.symbol_data_by_symbol = {}

resolution_string = Extensions.get_enum_string(resolution, Resolution)
self.name = '{}({},{},{})'.format(self.__class__.__name__, fast_period, slow_period, resolution_string)
self.name = '{}({},{},{})'.format(self.__class__.__name__, fast_period, slow_period, resolution)


def update(self, algorithm, data):
Expand Down
6 changes: 2 additions & 4 deletions Algorithm.Framework/Alphas/MacdAlphaModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def __init__(self,
self.insightCollection = InsightCollection()
self.symbolData = {}

resolutionString = Extensions.GetEnumString(resolution, Resolution)
movingAverageTypeString = Extensions.GetEnumString(movingAverageType, MovingAverageType)
self.Name = '{}({},{},{},{},{})'.format(self.__class__.__name__, fastPeriod, slowPeriod, signalPeriod, movingAverageTypeString, resolutionString)
self.Name = '{}({},{},{},{},{})'.format(self.__class__.__name__, fastPeriod, slowPeriod, signalPeriod, movingAverageType, resolution)


def Update(self, algorithm, data):
Expand Down Expand Up @@ -99,7 +97,7 @@ def OnSecuritiesChanged(self, algorithm, changes):
if data is not None:
# clean up our consolidator
algorithm.SubscriptionManager.RemoveConsolidator(symbol, data.Consolidator)

# remove from insight collection manager
self.CancelInsights(algorithm, symbol)

Expand Down
3 changes: 1 addition & 2 deletions Algorithm.Framework/Alphas/RsiAlphaModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def __init__(self,
self.insight_period = Time.multiply(Extensions.to_time_span(resolution), period)
self.symbol_data_by_symbol ={}

resolution_string = Extensions.get_enum_string(resolution, Resolution)
self.name = '{}({},{})'.format(self.__class__.__name__, period, resolution_string)
self.name = '{}({},{})'.format(self.__class__.__name__, period, resolution)

def update(self, algorithm, data):
'''Updates this alpha model with the latest data from the algorithm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self,
# If the argument is an instance of Resolution or Timedelta
# Redefine rebalancing_func
rebalancing_func = rebalance
if isinstance(rebalance, int):
if isinstance(rebalance, Resolution):
rebalance = Extensions.to_time_span(rebalance)
if isinstance(rebalance, timedelta):
rebalancing_func = lambda dt: dt + rebalance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, rebalance = Resolution.DAILY, portfolio_bias = PortfolioBias.
# If the argument is an instance of Resolution or Timedelta
# Redefine rebalancing_func
rebalancing_func = rebalance
if isinstance(rebalance, int):
if isinstance(rebalance, Resolution):
rebalance = Extensions.to_time_span(rebalance)
if isinstance(rebalance, timedelta):
rebalancing_func = lambda dt: dt + rebalance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self,
# If the argument is an instance of Resolution or Timedelta
# Redefine rebalancing_func
rebalancing_func = rebalance
if isinstance(rebalance, int):
if isinstance(rebalance, Resolution):
rebalance = Extensions.to_time_span(rebalance)
if isinstance(rebalance, timedelta):
rebalancing_func = lambda dt: dt + rebalance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
<PackageReference Include="Accord" Version="3.6.0" />
<PackageReference Include="Accord.Math" Version="3.6.0" />
<PackageReference Include="Accord.Statistics" Version="3.6.0" />
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/QuantConnect.Algorithm.Python.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<Compile Include="..\Common\Properties\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
</ItemGroup>
<ItemGroup>
<Content Include="OptionUniverseFilterGreeksShortcutsRegressionAlgorithm.py" />
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/UpdateOrderRegressionAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def on_data(self, data):
limit_price = (1 + self.limit_percentage)*data["SPY"].high if not is_long else (1 - self.limit_percentage)*data["SPY"].low

request = SubmitOrderRequest(order_type, self.security.symbol.security_type, "SPY", self.quantity, stop_price, limit_price, 0, 0.01, True,
self.utc_time, str(order_type))
self.utc_time, str(int(order_type)))
ticket = self.transactions.add_order(request)
self.tickets.append(ticket)

Expand Down
2 changes: 1 addition & 1 deletion Algorithm/QuantConnect.Algorithm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="NodaTime" Version="3.0.5" />
Expand Down
3 changes: 1 addition & 2 deletions Algorithm/Selection/ManualUniverseSelectionModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def create_universes(self, algorithm: QCAlgorithm) -> list[Universe]:

market = key[0]
security_type = key[1]
security_type_str = Extensions.get_enum_string(security_type, SecurityType)
universe_symbol = Symbol.create(f"manual-universe-selection-model-{security_type_str}-{market}", security_type, market)
universe_symbol = Symbol.create(f"manual-universe-selection-model-{security_type}-{market}", security_type, market)

if security_type == SecurityType.BASE:
# add an entry for this custom universe symbol -- we don't really know the time zone for sure,
Expand Down
2 changes: 1 addition & 1 deletion AlgorithmFactory/QuantConnect.AlgorithmFactory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
<PackageReference Include="NodaTime" Version="3.0.5" />
</ItemGroup>
<ItemGroup>
Expand Down
35 changes: 35 additions & 0 deletions Common/Algorithm/Framework/Portfolio/PortfolioTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using QuantConnect.Securities;
using System.Collections.Generic;
using QuantConnect.Securities.Positions;
using QuantConnect.Algorithm.Framework.Alphas;

namespace QuantConnect.Algorithm.Framework.Portfolio
{
Expand Down Expand Up @@ -62,6 +63,40 @@ public PortfolioTarget(Symbol symbol, decimal quantity, string tag = "")
Tag = tag;
}

/// <summary>
/// Initializes a new instance of the <see cref="PortfolioTarget"/> class
/// </summary>
/// <param name="symbol">The symbol this target is for</param>
/// <param name="quantity">The target quantity</param>
/// <param name="tag">The target tag with additional information</param>
public PortfolioTarget(Symbol symbol, int quantity, string tag = "")
: this(symbol, (decimal)quantity, tag)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="PortfolioTarget"/> class
/// </summary>
/// <param name="symbol">The symbol this target is for</param>
/// <param name="insightDirection">
/// The insight direction, which will be used to calculate the target quantity
/// (1 for Up, 0 for flat, -1 for down)
/// </param>
/// <param name="tag">The target tag with additional information</param>
public PortfolioTarget(Symbol symbol, InsightDirection insightDirection, string tag = "")
: this(symbol,
insightDirection switch
{
InsightDirection.Up => 1m,
InsightDirection.Down => -1m,
InsightDirection.Flat => 0m,
_ => throw new ArgumentOutOfRangeException(nameof(insightDirection), insightDirection,
Messages.PortfolioTarget.InvalidInsightDirection(symbol, insightDirection)),
},
tag)
{
}

/// <summary>
/// Creates a new target for the specified percent
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3185,6 +3185,7 @@ public static PyList ToPyListUnSafe(this IEnumerable enumerable)
/// <param name="value">Numeric value</param>
/// <param name="pyObject">Python object that encapsulated a Enum Type</param>
/// <returns>String that represents the enumerated object</returns>
[Obsolete("Deprecated as of 2025-07. Please use `str()`.")]
public static string GetEnumString(this int value, PyObject pyObject)
{
Type type;
Expand Down
11 changes: 10 additions & 1 deletion Common/Messages/Messages.Algorithm.Framework.Portfolio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

using System.Runtime.CompilerServices;

using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Interfaces;
using QuantConnect.Securities.Positions;

Expand Down Expand Up @@ -77,6 +77,15 @@ public static string ToString(Algorithm.Framework.Portfolio.PortfolioTarget port

return str;
}

/// <summary>
/// Returns a string message saying the insight direction is invalid for the given symbol
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string InvalidInsightDirection(QuantConnect.Symbol symbol, InsightDirection insightDirection)
{
return Invariant($"Invalid insight direction {insightDirection} for symbol: {symbol}.");
}
}
}
}
2 changes: 1 addition & 1 deletion Common/QuantConnect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<Message Text="SelectedOptimization $(SelectedOptimization)" Importance="high" />
</Target>
<ItemGroup>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
<PackageReference Include="CloneExtensions" Version="1.3.0" />
<PackageReference Include="fasterflect" Version="3.0.0" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion Engine/QuantConnect.Lean.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<Message Text="SelectedOptimization $(SelectedOptimization)" Importance="high" />
</Target>
<ItemGroup>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
<PackageReference Include="fasterflect" Version="3.0.0" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
Expand Down
2 changes: 1 addition & 1 deletion Indicators/QuantConnect.Indicators.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<Message Text="SelectedOptimization $(SelectedOptimization)" Importance="high" />
</Target>
<ItemGroup>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Report/QuantConnect.Report.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
<PackageReference Include="Deedle" Version="2.1.0" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
Expand Down
2 changes: 1 addition & 1 deletion Research/QuantConnect.Research.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PackageReference Include="Plotly.NET" Version="5.1.0" />
<PackageReference Include="Plotly.NET.CSharp" Version="0.13.0" />
<PackageReference Include="Plotly.NET.Interactive" Version="5.0.0" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
<PackageReference Include="NodaTime" Version="3.0.5" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Algorithm/AlgorithmIndicatorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ from QuantConnect.Indicators import *
def create_intraday_vwap_indicator(name):
return IntradayVwap(name)
def create_consolidator():
return TradeBarConsolidator(Resolution.HOUR)
return TradeBarConsolidator(timedelta(minutes=1))
";

using (Py.GIL())
Expand Down
2 changes: 1 addition & 1 deletion Tests/QuantConnect.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<ItemGroup>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.44" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.45" />
<PackageReference Include="Accord" Version="3.6.0" />
<PackageReference Include="Accord.Math" Version="3.6.0" />
<PackageReference Include="Common.Logging" Version="3.4.1" />
Expand Down
Loading