Optimizations

This commit is contained in:
2025-03-31 15:40:02 -04:00
parent d169d481e7
commit 30c90cb56c
13 changed files with 213 additions and 171 deletions

View File

@@ -139,6 +139,48 @@ namespace MarketData.DataAccess
if(null!=sqlTransaction) sqlTransaction.Dispose();
}
}
public static Dictionary<String,bool> HasStopLimit(List<String> symbols)
{
MySqlConnection sqlConnection=null;
MySqlDataReader sqlDataReader=null;
MySqlCommand sqlCommand=null;
Dictionary<String,bool> hasStopLimit = new Dictionary<String,bool>();
try
{
StringBuilder sb=new StringBuilder();
if(null==symbols) return null;
sqlConnection=SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("portfolio_data"));
sb.Append("select symbol, count(*) from stoplimits ");
sb.Append("where symbol in ");
sb.Append(SqlUtils.CreateInClause(symbols));
sb.Append(" and active=1 group by 1");
String strQuery=sb.ToString();
sqlCommand=new MySqlCommand(strQuery,sqlConnection);
sqlCommand.CommandTimeout=SqlUtils.COMMAND_TIMEOUT;
sqlDataReader=sqlCommand.ExecuteReader();
while(sqlDataReader.Read())
{
String symbol = sqlDataReader.GetString(0);
symbol = symbol.ToUpper();
hasStopLimit.Add(symbol, true);
}
return hasStopLimit;
}
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,exception);
return null;
}
finally
{
if(null!=sqlCommand) sqlCommand.Dispose();
if(null!=sqlDataReader) sqlDataReader.Close();
if(null!=sqlConnection) sqlConnection.Close();
}
}
public static bool HasStopLimit(String symbol)
{
MySqlConnection sqlConnection=null;
@@ -153,6 +195,7 @@ namespace MarketData.DataAccess
sqlConnection=SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("portfolio_data"));
sb.Append("select count(*) from stoplimits ");
sb.Append("where symbol='").Append(symbol).Append("'");
sb.Append(" and active=1");
strQuery=sb.ToString();
sqlCommand=new MySqlCommand(strQuery,sqlConnection);
sqlCommand.CommandTimeout=SqlUtils.COMMAND_TIMEOUT;

View File

@@ -10,6 +10,7 @@ namespace MarketData.DataAccess
{
public class PricingDA
{
public static readonly int ForwardLookingDays = 90;
private PricingDA()
{
}
@@ -628,6 +629,52 @@ namespace MarketData.DataAccess
if (null != sqlConnection) sqlConnection.Close();
}
}
public static Dictionary<String,String> GetNamesForSymbols(List<String> symbols)
{
MySqlConnection sqlConnection = null;
MySqlDataReader sqlDataReader = null;
MySqlCommand sqlCommand=null;
String strQuery = null;
Dictionary<String,String> dictionary = new Dictionary<String,String>();
try
{
StringBuilder sb = new StringBuilder();
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
sb.Append("select symbol, company from securitymaster where symbol in ");
sb.Append(SqlUtils.CreateInClause(symbols));
sb.Append(";");
strQuery = sb.ToString(); ;
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
String symbol = sqlDataReader.GetString(0);
String companyName = sqlDataReader.GetString(1);
if(null==companyName || null==symbol)continue;
companyName=companyName.ToUpper();
symbol = symbol.ToUpper();
if(dictionary.ContainsKey(symbol))continue;
dictionary.Add(symbol,companyName);
}
return dictionary;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,exception);
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Query was {0}",strQuery));
return null;
}
finally
{
if(null!=sqlCommand)sqlCommand.Dispose();
if (null != sqlDataReader) sqlDataReader.Close();
if (null != sqlConnection) sqlConnection.Close();
}
}
public static String GetNameForSymbol(String symbol)
{
MySqlConnection sqlConnection = null;
@@ -1117,6 +1164,7 @@ namespace MarketData.DataAccess
// Get prices starting at "startDate" and "days" number of days going into future
public static Prices GetPricesForward(String symbol,DateTime startDate,int days)
{
Profiler profiler = new Profiler();
MySqlConnection sqlConnection=null;
MySqlDataReader sqlDataReader=null;
MySqlCommand sqlCommand=null;
@@ -1166,6 +1214,7 @@ namespace MarketData.DataAccess
if(null!=sqlCommand) sqlCommand.Dispose();
if(null!=sqlDataReader) sqlDataReader.Close();
if(null!=sqlConnection) sqlConnection.Close();
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[GetPricesForward] Done, took {0}(ms)",profiler.End()));
}
}
public static Prices GetPricesOnOrBefore(String symbol,DateTime startDate)

View File

@@ -116,28 +116,6 @@ namespace MarketData.Generator.CMMomentum
{
if(null==sessionParams)return null;
MarketData.Generator.CMMomentum.Positions combinedPositions=sessionParams.GetCombinedPositions();
// Fix purchase date/sell date fall on weekend
//foreach(MarketData.Generator.CMMomentum.Position position in combinedPositions)
//{
// if(dateGenerator.IsWeekend(position.PurchaseDate))
// {
// while(true)
// {
// position.PurchaseDate=dateGenerator.GetPrevBusinessDay(position.PurchaseDate);
// if(!HolidayDA.IsMarketHoliday(position.PurchaseDate)) break;
// }
// }
// if(dateGenerator.IsWeekend(position.SellDate))
// {
// while(true)
// {
// position.SellDate=dateGenerator.GetNextBusinessDay(position.SellDate);
// if(!HolidayDA.IsMarketHoliday(position.SellDate)) break;
// }
// }
//}
// ********************************************************
DateTime minDate=combinedPositions.Min(x => x.PurchaseDate);
DateTime maxDate=PricingDA.GetLatestDate();
double prevGainLoss=double.NaN;
@@ -153,14 +131,14 @@ namespace MarketData.Generator.CMMomentum
double gainLossClosedPositions=0.00;
double exposure=0.00;
double marketValue=0.00;
if(HolidayDA.IsMarketHoliday(currentDate)) continue;
// if(HolidayDA.IsMarketHoliday(currentDate)) continue;
ModelPerformanceItem performanceItem=new ModelPerformanceItem();
foreach(MarketData.Generator.CMMomentum.Position openPosition in openPositions)
{
exposure+=openPosition.Shares*openPosition.PurchasePrice;
if(!LocalPriceCache.GetInstance().ContainsPrice(openPosition.Symbol,currentDate))
{
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,90);
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,PricingDA.ForwardLookingDays);
LocalPriceCache.GetInstance().Add(prices);
}
Price price=LocalPriceCache.GetInstance().GetPrice(openPosition.Symbol,currentDate);

View File

@@ -122,28 +122,6 @@ namespace MarketData.Generator.CMTrend
{
if(null==sessionParams) return null;
MarketData.Generator.CMTrend.Positions combinedPositions=sessionParams.GetCombinedPositions();
// Fix purchase date/sell date fall on weekend
//foreach(MarketData.Generator.CMTrend.Position position in combinedPositions)
//{
// if(dateGenerator.IsWeekend(position.PurchaseDate))
// {
// while(true)
// {
// position.PurchaseDate=dateGenerator.GetPrevBusinessDay(position.PurchaseDate);
// if(!HolidayDA.IsMarketHoliday(position.PurchaseDate)) break;
// }
// }
// if(dateGenerator.IsWeekend(position.SellDate))
// {
// while(true)
// {
// position.SellDate=dateGenerator.GetNextBusinessDay(position.SellDate);
// if(!HolidayDA.IsMarketHoliday(position.SellDate)) break;
// }
// }
//}
// ********************************************************
DateTime minDate=combinedPositions.Min(x => x.PurchaseDate);
DateTime maxDate=PricingDA.GetLatestDate();
double prevGainLoss=double.NaN;
@@ -159,14 +137,14 @@ namespace MarketData.Generator.CMTrend
double gainLossClosedPositions=0.00;
double exposure=0.00;
double marketValue=0.00;
if(HolidayDA.IsMarketHoliday(currentDate)) continue;
// if(HolidayDA.IsMarketHoliday(currentDate)) continue;
ModelPerformanceItem performanceItem=new ModelPerformanceItem();
foreach(MarketData.Generator.CMTrend.Position openPosition in openPositions)
{
exposure+=openPosition.Shares*openPosition.PurchasePrice;
if(!LocalPriceCache.GetInstance().ContainsPrice(openPosition.Symbol,currentDate))
{
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,90);
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,PricingDA.ForwardLookingDays);
LocalPriceCache.GetInstance().Add(prices);
}
Price price=LocalPriceCache.GetInstance().GetPrice(openPosition.Symbol,currentDate);

View File

@@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
//using System.Runtime.Remoting.Messaging;
using System.Text;
using MarketData.MarketDataModel;
using MarketData.DataAccess;

View File

@@ -229,28 +229,6 @@ namespace MarketData.Generator.MGSHMomentum
{
if(null==sessionParams)return null;
MGSHPositions combinedPositions=sessionParams.GetCombinedPositions();
// Fix purchase date/sell date fall on weekend
//foreach(MGSHPosition position in combinedPositions)
//{
// if(dateGenerator.IsWeekend(position.PurchaseDate))
// {
// while(true)
// {
// position.PurchaseDate=dateGenerator.GetPrevBusinessDay(position.PurchaseDate);
// if(!HolidayDA.IsMarketHoliday(position.PurchaseDate)) break;
// }
// }
// if(dateGenerator.IsWeekend(position.SellDate))
// {
// while(true)
// {
// position.SellDate=dateGenerator.GetNextBusinessDay(position.SellDate);
// if(!HolidayDA.IsMarketHoliday(position.SellDate)) break;
// }
// }
//}
// ********************************************************
DateTime minDate=combinedPositions.Min(x => x.PurchaseDate);
DateTime maxDate=PricingDA.GetLatestDate();
double prevGainLoss=double.NaN;
@@ -266,14 +244,14 @@ namespace MarketData.Generator.MGSHMomentum
double gainLossClosedPositions=0.00;
double exposure=0.00;
double marketValue=0.00;
if(HolidayDA.IsMarketHoliday(currentDate)) continue;
// if(HolidayDA.IsMarketHoliday(currentDate)) continue;
ModelPerformanceItem performanceItem=new ModelPerformanceItem();
foreach(MGSHPosition openPosition in openPositions)
{
exposure+=openPosition.Shares*openPosition.PurchasePrice;
if(!LocalPriceCache.GetInstance().ContainsPrice(openPosition.Symbol,currentDate))
{
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,90);
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,PricingDA.ForwardLookingDays);
LocalPriceCache.GetInstance().Add(prices);
}
Price price=LocalPriceCache.GetInstance().GetPrice(openPosition.Symbol,currentDate);

View File

@@ -107,27 +107,6 @@ namespace MarketData.Generator.Momentum
if(null==sessionParams)return null;
MarketData.Generator.Momentum.Positions combinedPositions=sessionParams.GetCombinedPositions();
// Fix purchase date/sell date fall on weekend
//foreach(MarketData.Generator.Momentum.Position position in combinedPositions)
//{
// if(dateGenerator.IsWeekend(position.PurchaseDate))
// {
// while(true)
// {
// position.PurchaseDate=dateGenerator.GetPrevBusinessDay(position.PurchaseDate);
// if(!HolidayDA.IsMarketHoliday(position.PurchaseDate)) break;
// }
// }
// if(dateGenerator.IsWeekend(position.SellDate))
// {
// while(true)
// {
// position.SellDate=dateGenerator.GetNextBusinessDay(position.SellDate);
// if(!HolidayDA.IsMarketHoliday(position.SellDate)) break;
// }
// }
//}
// ********************************************************
DateTime minDate=combinedPositions.Min(x => x.PurchaseDate);
DateTime maxDate=PricingDA.GetLatestDate();
double prevGainLoss=double.NaN;
@@ -142,14 +121,14 @@ namespace MarketData.Generator.Momentum
double gainLossClosedPositions=0.00;
double exposure=0.00;
double marketValue=0.00;
if(HolidayDA.IsMarketHoliday(currentDate)) continue;
// if(HolidayDA.IsMarketHoliday(currentDate)) continue;
ModelPerformanceItem performanceItem=new ModelPerformanceItem();
foreach(MarketData.Generator.Momentum.Position openPosition in openPositions)
{
exposure+=openPosition.Shares*openPosition.PurchasePrice;
if(!LocalPriceCache.GetInstance().ContainsPrice(openPosition.Symbol,currentDate))
{
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,90);
Prices prices=PricingDA.GetPricesForward(openPosition.Symbol,currentDate,PricingDA.ForwardLookingDays);
LocalPriceCache.GetInstance().Add(prices);
}
Price price=LocalPriceCache.GetInstance().GetPrice(openPosition.Symbol,currentDate);

View File

@@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
//using System.Runtime.Remoting.Messaging;
using System.Text;
using MarketData.MarketDataModel;

View File

@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using MarketData.MarketDataModel;
using MarketData.MarketDataModel;
using MarketData.DataAccess;
using MarketData.Utils;
using System.Net;
using System;
using System.Linq;
using System.Threading;
using System.Collections.Generic;
namespace MarketData.Helper
{

View File

@@ -98,6 +98,14 @@ namespace MarketData.MarketDataModel
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Error extracting economic indicators from zip file {0}, error was {1}",strPathZipFile,exception.ToString()));
return null;
}
finally
{
if(File.Exists(strPathZipFile))
{
try{File.Delete(strPathZipFile);}
finally{;}
}
}
}
public static EconomicIndicators FromDataTable(DataTable dataTable)
{

View File

@@ -19,66 +19,89 @@ namespace MarketData.MarketDataModel.GainLoss
}
public GainLossSummaryItemCollection(PortfolioTrades portfolioTrades,ITotalGainLossGenerator gainLossGenerator,IActiveGainLossGenerator activeGainLossGenerator,DateTime? maxDateRef=null)
{
List<String> symbols=portfolioTrades.Symbols;
Profiler profiler = new Profiler();
if(null==gainLossGenerator || null==activeGainLossGenerator)return;
foreach(String symbol in symbols)
try
{
PortfolioTrades portfolioTradesSymbol=portfolioTrades.FilterSymbol(symbol);
GainLossCollection gainLossCollection=activeGainLossGenerator.GenerateGainLoss(portfolioTradesSymbol,maxDateRef);
List<String> symbols=portfolioTrades.Symbols;
if(null==gainLossGenerator || null==activeGainLossGenerator)return;
TotalGainLossCollection totalGainLossCollection=gainLossGenerator.GenerateTotalGainLoss(portfolioTradesSymbol,maxDateRef);
GainLossCompoundModelCollection gainLossCompoundModelCollection=new GainLossCompoundModelCollection(gainLossCollection,totalGainLossCollection);
Dictionary<String,String> companyNames = PricingDA.GetNamesForSymbols(symbols);
Dictionary<String,bool> stopLimits = PortfolioDA.HasStopLimit(symbols);
if(1>gainLossCompoundModelCollection.Count) continue;
GainLossSummaryItem gainLossSummaryItem=new GainLossSummaryItem();
gainLossSummaryItem.Date=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].Date;
gainLossSummaryItem.Symbol=symbol;
gainLossSummaryItem.CompanyName=PricingDA.GetNameForSymbol(symbol);
gainLossSummaryItem.CurrentGainLoss=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].ActiveGainLoss;
double previousGainLoss=1==gainLossCompoundModelCollection.Count?0.00:gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-2].ActiveGainLoss;
gainLossSummaryItem.PreviousGainLoss=previousGainLoss;
gainLossSummaryItem.Change=gainLossSummaryItem.CurrentGainLoss-gainLossSummaryItem.PreviousGainLoss;
if(1==gainLossCollection.Count) gainLossSummaryItem.ChangePercent=0.00;
else
foreach(String symbol in symbols)
{
double currentMarketValue=gainLossCollection[gainLossCollection.Count-1].Exposure+gainLossCollection[gainLossCollection.Count-1].GainLoss;
double previousMarketValue=gainLossCollection[gainLossCollection.Count-2].Exposure+gainLossCollection[gainLossCollection.Count-2].GainLoss;
if(0.00==previousMarketValue) gainLossSummaryItem.ChangePercent=0.00;
else gainLossSummaryItem.ChangePercent=((currentMarketValue-previousMarketValue)/previousMarketValue)*100;
if(gainLossSummaryItem.CurrentGainLoss<0&&gainLossSummaryItem.PreviousGainLoss<0)
{ // if current gainloss is negative and previous gainloss is negative then show change percent as a further dip into negative (i.e.) make sure sign is negative
if(Math.Abs(gainLossSummaryItem.CurrentGainLoss)>Math.Abs(gainLossSummaryItem.PreviousGainLoss)) gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
}
else if(gainLossSummaryItem.CurrentGainLoss<0&&gainLossSummaryItem.PreviousGainLoss>0)
PortfolioTrades portfolioTradesSymbol=portfolioTrades.FilterSymbol(symbol);
GainLossCollection gainLossCollection=activeGainLossGenerator.GenerateGainLoss(portfolioTradesSymbol,maxDateRef);
TotalGainLossCollection totalGainLossCollection=gainLossGenerator.GenerateTotalGainLoss(portfolioTradesSymbol,maxDateRef);
GainLossCompoundModelCollection gainLossCompoundModelCollection=new GainLossCompoundModelCollection(gainLossCollection,totalGainLossCollection);
if(1>gainLossCompoundModelCollection.Count) continue;
GainLossSummaryItem gainLossSummaryItem=new GainLossSummaryItem();
gainLossSummaryItem.Date=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].Date;
gainLossSummaryItem.Symbol=symbol;
if(companyNames.ContainsKey(symbol))
{
gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
gainLossSummaryItem.CompanyName=companyNames[symbol];
}
else if(gainLossSummaryItem.CurrentGainLoss>0&&gainLossSummaryItem.PreviousGainLoss>0)
// gainLossSummaryItem.CompanyName=PricingDA.GetNameForSymbol(symbol);
gainLossSummaryItem.CurrentGainLoss=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].ActiveGainLoss;
double previousGainLoss=1==gainLossCompoundModelCollection.Count?0.00:gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-2].ActiveGainLoss;
gainLossSummaryItem.PreviousGainLoss=previousGainLoss;
gainLossSummaryItem.Change=gainLossSummaryItem.CurrentGainLoss-gainLossSummaryItem.PreviousGainLoss;
if(1==gainLossCollection.Count) gainLossSummaryItem.ChangePercent=0.00;
else
{
if(gainLossSummaryItem.CurrentGainLoss<gainLossSummaryItem.PreviousGainLoss) gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
double currentMarketValue=gainLossCollection[gainLossCollection.Count-1].Exposure+gainLossCollection[gainLossCollection.Count-1].GainLoss;
double previousMarketValue=gainLossCollection[gainLossCollection.Count-2].Exposure+gainLossCollection[gainLossCollection.Count-2].GainLoss;
if(0.00==previousMarketValue) gainLossSummaryItem.ChangePercent=0.00;
else gainLossSummaryItem.ChangePercent=((currentMarketValue-previousMarketValue)/previousMarketValue)*100;
if(gainLossSummaryItem.CurrentGainLoss<0&&gainLossSummaryItem.PreviousGainLoss<0)
{ // if current gainloss is negative and previous gainloss is negative then show change percent as a further dip into negative (i.e.) make sure sign is negative
if(Math.Abs(gainLossSummaryItem.CurrentGainLoss)>Math.Abs(gainLossSummaryItem.PreviousGainLoss)) gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
}
else if(gainLossSummaryItem.CurrentGainLoss<0&&gainLossSummaryItem.PreviousGainLoss>0)
{
gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
}
else if(gainLossSummaryItem.CurrentGainLoss>0&&gainLossSummaryItem.PreviousGainLoss>0)
{
if(gainLossSummaryItem.CurrentGainLoss<gainLossSummaryItem.PreviousGainLoss) gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
}
}
// here we need to check maxDateRef for null and then call appropriate HasOpenPositions() / HasOpenPositionsOn(date) method
if(null!=maxDateRef)
{
if(!portfolioTrades.HasOpenPositionsOn(symbol,maxDateRef.Value)) continue;
}
else
{
if(!portfolioTrades.HasOpenPositions(symbol)) continue;
}
// gainLossSummaryItem.HasStopLimit=PortfolioDA.HasStopLimit(symbol);
gainLossSummaryItem.HasStopLimit=stopLimits.ContainsKey(symbol);
Add(gainLossSummaryItem);
}
// here we need to check maxDateRef for null and then call appropriate HasOpenPositions() / HasOpenPositionsOn(date) method
if(null!=maxDateRef)
{
if(!portfolioTrades.HasOpenPositionsOn(symbol,maxDateRef.Value)) continue;
}
else
{
if(!portfolioTrades.HasOpenPositions(symbol)) continue;
}
gainLossSummaryItem.HasStopLimit=PortfolioDA.HasStopLimit(symbol);
Add(gainLossSummaryItem);
GainLossSummaryItemCollection gainLossSummaryCollection=new GainLossSummaryItemCollection((from GainLossSummaryItem gainLossSummaryItem in this orderby gainLossSummaryItem.Date descending,gainLossSummaryItem.Change descending,gainLossSummaryItem.Symbol descending select gainLossSummaryItem).ToList());
Clear();
AddRange(gainLossSummaryCollection);
}
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[GainLossSummaryItemCollection] Exception:{0}",exception.ToString()));
}
finally
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[GainLossSummaryItemCollection] Done, took {0}(ms)",profiler.End()));
}
GainLossSummaryItemCollection gainLossSummaryCollection=new GainLossSummaryItemCollection((from GainLossSummaryItem gainLossSummaryItem in this orderby gainLossSummaryItem.Date descending,gainLossSummaryItem.Change descending,gainLossSummaryItem.Symbol descending select gainLossSummaryItem).ToList());
Clear();
AddRange(gainLossSummaryCollection);
}
public GainLossSummaryItemCollection(PortfolioTrades portfolioTrades,DateTime? maxDateRef=null)
{
List<String> symbols=portfolioTrades.Symbols;
Dictionary<String,bool> stopLimits = PortfolioDA.HasStopLimit(symbols);
foreach(String symbol in symbols)
{
PortfolioTrades portfolioTradesSymbol=portfolioTrades.FilterSymbol(symbol);
@@ -125,7 +148,8 @@ namespace MarketData.MarketDataModel.GainLoss
{
if(!portfolioTrades.HasOpenPositions(symbol)) continue;
}
gainLossSummaryItem.HasStopLimit=PortfolioDA.HasStopLimit(symbol);
gainLossSummaryItem.HasStopLimit = stopLimits.ContainsKey(symbol);
// gainLossSummaryItem.HasStopLimit=PortfolioDA.HasStopLimit(symbol);
Add(gainLossSummaryItem);
}
GainLossSummaryItemCollection gainLossSummaryCollection=new GainLossSummaryItemCollection((from GainLossSummaryItem gainLossSummaryItem in this orderby gainLossSummaryItem.Date descending,gainLossSummaryItem.Change descending,gainLossSummaryItem.Symbol descending select gainLossSummaryItem).ToList());

View File

@@ -49,7 +49,7 @@ namespace MarketData.Utils
//SetConnectionCollation(connection);
return connection;
}
catch(SqlException exception)
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
return null;
@@ -84,7 +84,7 @@ namespace MarketData.Utils
connection.Open();
return connection;
}
catch(SqlException exception)
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
return null;