using System;
using System.Collections.Generic;
namespace NT8.Core.Common.Models
{
///
/// Risk management configuration
///
public class RiskConfig
{
// Phase 1 - Basic Risk Properties
///
/// Daily loss limit in dollars
///
public double DailyLossLimit { get; set; }
///
/// Maximum risk per trade in dollars
///
public double MaxTradeRisk { get; set; }
///
/// Maximum number of open positions
///
public int MaxOpenPositions { get; set; }
///
/// Whether emergency flatten is enabled
///
public bool EmergencyFlattenEnabled { get; set; }
// Phase 2 - Advanced Risk Properties (Optional)
///
/// Weekly loss limit in dollars (optional, for advanced risk management)
///
public double? WeeklyLossLimit { get; set; }
///
/// Trailing drawdown limit in dollars (optional, for advanced risk management)
///
public double? TrailingDrawdownLimit { get; set; }
///
/// Maximum cross-strategy exposure in dollars (optional, for advanced risk management)
///
public double? MaxCrossStrategyExposure { get; set; }
///
/// Maximum correlated exposure in dollars (optional, for advanced risk management)
///
public double? MaxCorrelatedExposure { get; set; }
///
/// Constructor for RiskConfig (Phase 1 - backward compatible)
///
public RiskConfig(
double dailyLossLimit,
double maxTradeRisk,
int maxOpenPositions,
bool emergencyFlattenEnabled)
{
DailyLossLimit = dailyLossLimit;
MaxTradeRisk = maxTradeRisk;
MaxOpenPositions = maxOpenPositions;
EmergencyFlattenEnabled = emergencyFlattenEnabled;
// Phase 2 properties default to null (not set)
WeeklyLossLimit = null;
TrailingDrawdownLimit = null;
MaxCrossStrategyExposure = null;
MaxCorrelatedExposure = null;
}
///
/// Constructor for RiskConfig (Phase 2 - with advanced parameters)
///
public RiskConfig(
double dailyLossLimit,
double maxTradeRisk,
int maxOpenPositions,
bool emergencyFlattenEnabled,
double? weeklyLossLimit,
double? trailingDrawdownLimit,
double? maxCrossStrategyExposure,
double? maxCorrelatedExposure)
{
DailyLossLimit = dailyLossLimit;
MaxTradeRisk = maxTradeRisk;
MaxOpenPositions = maxOpenPositions;
EmergencyFlattenEnabled = emergencyFlattenEnabled;
WeeklyLossLimit = weeklyLossLimit;
TrailingDrawdownLimit = trailingDrawdownLimit;
MaxCrossStrategyExposure = maxCrossStrategyExposure;
MaxCorrelatedExposure = maxCorrelatedExposure;
}
}
///
/// Position sizing configuration
///
public class SizingConfig
{
///
/// Sizing method to use
///
public SizingMethod Method { get; set; }
///
/// Minimum number of contracts
///
public int MinContracts { get; set; }
///
/// Maximum number of contracts
///
public int MaxContracts { get; set; }
///
/// Risk per trade in dollars
///
public double RiskPerTrade { get; set; }
///
/// Method-specific parameters
///
public Dictionary MethodParameters { get; set; }
///
/// Constructor for SizingConfig
///
public SizingConfig(
SizingMethod method,
int minContracts,
int maxContracts,
double riskPerTrade,
Dictionary methodParameters)
{
Method = method;
MinContracts = minContracts;
MaxContracts = maxContracts;
RiskPerTrade = riskPerTrade;
MethodParameters = methodParameters ?? new Dictionary();
}
}
///
/// Strategy configuration
///
public class StrategyConfig
{
///
/// Strategy name
///
public string Name { get; set; }
///
/// Trading symbol
///
public string Symbol { get; set; }
///
/// Strategy parameters
///
public Dictionary Parameters { get; set; }
///
/// Risk settings
///
public RiskConfig RiskSettings { get; set; }
///
/// Sizing settings
///
public SizingConfig SizingSettings { get; set; }
///
/// Constructor for StrategyConfig
///
public StrategyConfig(
string name,
string symbol,
Dictionary parameters,
RiskConfig riskSettings,
SizingConfig sizingSettings)
{
Name = name;
Symbol = symbol;
Parameters = parameters ?? new Dictionary();
RiskSettings = riskSettings;
SizingSettings = sizingSettings;
}
}
///
/// Position sizing methods
///
public enum SizingMethod
{
///
/// Fixed number of contracts
///
FixedContracts,
///
/// Fixed dollar risk amount
///
FixedDollarRisk,
///
/// Percentage of equity
///
PercentOfEquity,
///
/// Optimal F calculation
///
OptimalF,
///
/// Kelly Criterion sizing
///
KellyCriterion,
///
/// Volatility-adjusted sizing
///
VolatilityAdjusted
}
///
/// Risk levels
///
public enum RiskLevel
{
///
/// Low risk
///
Low,
///
/// Medium risk
///
Medium,
///
/// High risk
///
High,
///
/// Critical risk
///
Critical
}
///
/// Risk decision result
///
public class RiskDecision
{
///
/// Whether order is allowed
///
public bool Allow { get; set; }
///
/// Rejection reason if not allowed
///
public string RejectReason { get; set; }
///
/// Modified intent if changes required
///
public StrategyIntent ModifiedIntent { get; set; }
///
/// Risk level assessment
///
public RiskLevel RiskLevel { get; set; }
///
/// Risk metrics
///
public Dictionary RiskMetrics { get; set; }
///
/// Constructor for RiskDecision
///
public RiskDecision(
bool allow,
string rejectReason,
StrategyIntent modifiedIntent,
RiskLevel riskLevel,
Dictionary riskMetrics)
{
Allow = allow;
RejectReason = rejectReason;
ModifiedIntent = modifiedIntent;
RiskLevel = riskLevel;
RiskMetrics = riskMetrics ?? new Dictionary();
}
}
///
/// Risk status information
///
public class RiskStatus
{
///
/// Whether trading is enabled
///
public bool TradingEnabled { get; set; }
///
/// Daily profit/loss
///
public double DailyPnL { get; set; }
///
/// Daily loss limit
///
public double DailyLossLimit { get; set; }
///
/// Maximum drawdown
///
public double MaxDrawdown { get; set; }
///
/// Number of open positions
///
public int OpenPositions { get; set; }
///
/// Last update timestamp
///
public DateTime LastUpdate { get; set; }
///
/// Active alerts
///
public List ActiveAlerts { get; set; }
///
/// Constructor for RiskStatus
///
public RiskStatus(
bool tradingEnabled,
double dailyPnL,
double dailyLossLimit,
double maxDrawdown,
int openPositions,
DateTime lastUpdate,
List activeAlerts)
{
TradingEnabled = tradingEnabled;
DailyPnL = dailyPnL;
DailyLossLimit = dailyLossLimit;
MaxDrawdown = maxDrawdown;
OpenPositions = openPositions;
LastUpdate = lastUpdate;
ActiveAlerts = activeAlerts ?? new List();
}
}
///
/// Position sizing result
///
public class SizingResult
{
///
/// Number of contracts
///
public int Contracts { get; set; }
///
/// Risk amount in dollars
///
public double RiskAmount { get; set; }
///
/// Sizing method used
///
public SizingMethod Method { get; set; }
///
/// Calculation details
///
public Dictionary Calculations { get; set; }
///
/// Constructor for SizingResult
///
public SizingResult(
int contracts,
double riskAmount,
SizingMethod method,
Dictionary calculations)
{
Contracts = contracts;
RiskAmount = riskAmount;
Method = method;
Calculations = calculations ?? new Dictionary();
}
}
///
/// Sizing metadata
///
public class SizingMetadata
{
///
/// Sizer name
///
public string Name { get; set; }
///
/// Sizer description
///
public string Description { get; set; }
///
/// Required parameters
///
public List RequiredParameters { get; set; }
///
/// Constructor for SizingMetadata
///
public SizingMetadata(
string name,
string description,
List requiredParameters)
{
Name = name;
Description = description;
RequiredParameters = requiredParameters ?? new List();
}
}
///
/// Order fill information
///
public class OrderFill
{
///
/// Order ID
///
public string OrderId { get; set; }
///
/// Symbol
///
public string Symbol { get; set; }
///
/// Fill quantity
///
public int Quantity { get; set; }
///
/// Fill price
///
public double FillPrice { get; set; }
///
/// Fill timestamp
///
public DateTime FillTime { get; set; }
///
/// Commission paid
///
public double Commission { get; set; }
///
/// Execution ID
///
public string ExecutionId { get; set; }
///
/// Constructor for OrderFill
///
public OrderFill(
string orderId,
string symbol,
int quantity,
double fillPrice,
DateTime fillTime,
double commission,
string executionId)
{
OrderId = orderId;
Symbol = symbol;
Quantity = quantity;
FillPrice = fillPrice;
FillTime = fillTime;
Commission = commission;
ExecutionId = executionId;
}
}
}