diff --git a/MarketDataLib/DataAccess/AnalystPriceTargetDA.cs b/MarketDataLib/DataAccess/AnalystPriceTargetDA.cs index 5bc970f..98cc374 100644 --- a/MarketDataLib/DataAccess/AnalystPriceTargetDA.cs +++ b/MarketDataLib/DataAccess/AnalystPriceTargetDA.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Text; using MySql.Data.MySqlClient; using MarketData.MarketDataModel; using MarketData.Utils; +using System; namespace MarketData.DataAccess { @@ -43,7 +42,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -83,7 +82,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/AnalystRatingsDA.cs b/MarketDataLib/DataAccess/AnalystRatingsDA.cs index 81e9ef7..5513201 100644 --- a/MarketDataLib/DataAccess/AnalystRatingsDA.cs +++ b/MarketDataLib/DataAccess/AnalystRatingsDA.cs @@ -1,9 +1,9 @@ using System; -using System.Collections.Generic; using System.Text; using MySql.Data.MySqlClient; using MarketData.MarketDataModel; using MarketData.Utils; +using System.Collections.Generic; namespace MarketData.DataAccess { @@ -59,7 +59,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -88,17 +88,6 @@ namespace MarketData.DataAccess sb.Append(" where A.date>=@minDate and A.date<=@maxDate "); sb.Append(" order by date "); - - //sb.Append(" select A.* from "); - //sb.Append(" (select date,symbol,upper(company),brokerage_firm,type,ratings_change,price_target from analystratings where symbol=").Append(SqlUtils.ToSqlString(symbol)); - //sb.Append(" union "); - //sb.Append(" select zr.date,zr.symbol,upper(sm.company) as company,'Zacks' as brokerage_firm,zr.type,zr.zacks_rank as ratings_change,null as price_target from zacksrank zr "); - //sb.Append(" left join securitymaster sm on sm.symbol=zr.symbol "); - //sb.Append(" where zr.symbol=").Append(SqlUtils.ToSqlString(symbol)).Append(" and zr.type is not null "); - //sb.Append(" )A "); - //sb.Append(" where A.date>=").Append(SqlUtils.SqlDate(minDate,true)).Append(" and A.date<=").Append(SqlUtils.SqlDate(maxDate,true)); - //sb.Append(" order by date "); - strQuery = sb.ToString(); ; sqlCommand = new MySqlCommand(strQuery, sqlConnection); sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; @@ -126,7 +115,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -157,7 +146,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -204,7 +193,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -220,31 +209,6 @@ namespace MarketData.DataAccess { StringBuilder sb = new StringBuilder(); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); -// sb.Append("set @symbol='").Append(symbol).Append("' COLLATE utf8mb4_unicode_ci ;"); - //sb.Append("set @symbol='").Append(symbol).Append("';"); - //sb.Append("set @maxDate='").Append(Utility.DateTimeToStringYYYYHMMHDD(maxDate)).Append("';"); - //sb.Append(" select A.* from "); - //sb.Append(" (select date,symbol,upper(company),brokerage_firm,type,ratings_change,price_target from analystratings where symbol=@symbol "); - //sb.Append(" union "); - //sb.Append(" select zr.date,zr.symbol,upper(sm.company) as company,'Zacks' as brokerage_firm,zr.type,zr.zacks_rank as ratings_change,null as price_target from zacksrank zr "); - //sb.Append(" left join securitymaster sm on sm.symbol=zr.symbol "); - //sb.Append(" where zr.symbol=@symbol and zr.type is not null "); - //sb.Append(" )A "); - //sb.Append(" where A.date<=@maxDate "); - //sb.Append(" order by date"); - - - - //sb.Append(" select A.* from "); - //sb.Append(" (select date,symbol,upper(company),brokerage_firm,type,ratings_change,price_target from analystratings where symbol=").Append(SqlUtils.ToSqlString(symbol)); - //sb.Append(" union "); - //sb.Append(" select zr.date,zr.symbol,upper(sm.company) as company,'Zacks' as brokerage_firm,zr.type,zr.zacks_rank as ratings_change,null as price_target from zacksrank zr "); - //sb.Append(" left join securitymaster sm on sm.symbol=zr.symbol "); - //sb.Append(" where zr.symbol=").Append(SqlUtils.ToSqlString(symbol)).Append(" and zr.type is not null "); - //sb.Append(" )A "); - //sb.Append(" where A.date<=").Append(SqlUtils.SqlDate(maxDate,true)); - //sb.Append(" order by date"); - sb.Append("set @symbol='").Append(symbol).Append("';"); sb.Append("set @maxDate='").Append(Utility.DateTimeToStringYYYYHMMHDD(maxDate)).Append("';"); sb.Append(" select A.* from "); @@ -257,8 +221,6 @@ namespace MarketData.DataAccess sb.Append(" where A.date<=@maxDate "); sb.Append(" order by date"); - - strQuery = sb.ToString(); ; sqlCommand = new MySqlCommand(strQuery, sqlConnection); sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; @@ -286,7 +248,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -302,7 +264,6 @@ namespace MarketData.DataAccess { StringBuilder sb = new StringBuilder(); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); -// sb.Append("set @symbol='").Append(symbol).Append("' COLLATE utf8mb4_unicode_ci ;"); sb.Append("set @symbol='").Append(symbol).Append("';"); sb.Append("set @date='").Append(Utility.DateTimeToStringYYYYHMMHDD(date)).Append("';"); sb.Append(" select A.* from "); @@ -315,16 +276,6 @@ namespace MarketData.DataAccess sb.Append(" where A.date=@date "); sb.Append(" order by A.symbol"); - //sb.Append(" select A.* from "); - //sb.Append(" (select date,symbol,upper(company),brokerage_firm,type,ratings_change,price_target from analystratings where symbol=").Append(SqlUtils.ToSqlString(symbol)); - //sb.Append(" union "); - //sb.Append(" select zr.date,zr.symbol,upper(sm.company) as company,'Zacks' as brokerage_firm,zr.type,zr.zacks_rank as ratings_change,null as price_target from zacksrank zr "); - //sb.Append(" left join securitymaster sm on sm.symbol=zr.symbol "); - //sb.Append(" where zr.symbol=@symbol and zr.type is not null "); - //sb.Append(" )A "); - //sb.Append(" where A.date=").Append(SqlUtils.SqlDate(date,true)); - //sb.Append(" order by A.symbol"); - strQuery = sb.ToString(); ; sqlCommand = new MySqlCommand(strQuery, sqlConnection); sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; @@ -352,7 +303,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -368,18 +319,6 @@ namespace MarketData.DataAccess { StringBuilder sb = new StringBuilder(); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); - //sb.Append("set @date='").Append(Utility.DateTimeToStringYYYYHMMHDD(date)).Append("';"); - //sb.Append(" select A.* from "); - //sb.Append(" (select date,symbol,upper(company),brokerage_firm,type,ratings_change,price_target from analystratings "); - //sb.Append(" union "); - //sb.Append(" select zr.date,zr.symbol,upper(sm.company) as company,'Zacks' as brokerage_firm,zr.type,zr.zacks_rank as ratings_change,null as price_target from zacksrank zr "); - //sb.Append(" left join securitymaster sm on sm.symbol=zr.symbol "); - //sb.Append(" where zr.type is not null "); - //sb.Append(" )A "); - //sb.Append(" where A.date=@date "); - //sb.Append(" order by A.symbol; "); - - //sb.Append("set @date='").Append(Utility.DateTimeToStringYYYYHMMHDD(date)).Append("';"); sb.Append(" select A.* from "); sb.Append(" (select date,symbol,upper(company),brokerage_firm,type,ratings_change,price_target from analystratings "); sb.Append(" union "); @@ -417,7 +356,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -434,25 +373,6 @@ namespace MarketData.DataAccess StringBuilder sb = new StringBuilder(); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); - //sb.Append(" set @symbol='").Append(symbol).Append("';"); - //sb.Append(" select A.* from "); - //sb.Append(" (select date,symbol,upper(company),brokerage_firm,type,ratings_change,price_target from analystratings where symbol=@symbol "); - //sb.Append(" union "); - //sb.Append(" select zr.date,zr.symbol,upper(sm.company) as company,'Zacks' as brokerage_firm,zr.type,zr.zacks_rank as ratings_change,null as price_target from zacksrank zr "); - //sb.Append(" left join securitymaster sm on sm.symbol=zr.symbol "); - //sb.Append(" where zr.symbol=@symbol and zr.type is not null "); - //sb.Append(" )A "); - //sb.Append(" order by date desc "); - - //sb.Append(" select A.* from "); - //sb.Append(" (select date,symbol,upper(company),brokerage_firm,type,ratings_change,price_target from analystratings where symbol=").Append(SqlUtils.ToSqlString(symbol)); - //sb.Append(" union "); - //sb.Append(" select zr.date,zr.symbol,upper(sm.company) as company,'Zacks' as brokerage_firm,zr.type,zr.zacks_rank as ratings_change,null as price_target from zacksrank zr "); - //sb.Append(" left join securitymaster sm on sm.symbol=zr.symbol "); - //sb.Append(" where zr.symbol=").Append(SqlUtils.ToSqlString(symbol)).Append(" and zr.type is not null "); - //sb.Append(" )A "); - //sb.Append(" order by date desc "); - sb.Append(" set @symbol='").Append(symbol).Append("';"); sb.Append(" select A.* from "); sb.Append(" (select date,symbol,upper(company),brokerage_firm,type,ratings_change,price_target from analystratings where symbol=@symbol "); @@ -463,7 +383,6 @@ namespace MarketData.DataAccess sb.Append(" )A "); sb.Append(" order by date desc "); - strQuery = sb.ToString(); ; sqlCommand = new MySqlCommand(strQuery, sqlConnection); sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; @@ -491,7 +410,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -528,7 +447,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/BalanceSheetDA.cs b/MarketDataLib/DataAccess/BalanceSheetDA.cs index 81fc315..5327443 100644 --- a/MarketDataLib/DataAccess/BalanceSheetDA.cs +++ b/MarketDataLib/DataAccess/BalanceSheetDA.cs @@ -48,7 +48,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -87,7 +87,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -145,7 +145,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -181,7 +181,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -219,7 +219,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -257,7 +257,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -314,7 +314,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -369,7 +369,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -411,7 +411,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -453,7 +453,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -495,7 +495,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/CashDA.cs b/MarketDataLib/DataAccess/CashDA.cs index 7f5d833..d6cc73c 100644 --- a/MarketDataLib/DataAccess/CashDA.cs +++ b/MarketDataLib/DataAccess/CashDA.cs @@ -82,7 +82,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -98,7 +98,6 @@ namespace MarketData.DataAccess { StringBuilder sb = new StringBuilder(); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("portfolio_data")); -// sb.Append("select sum(a.balance) from (select account,balance,date from cash b group by account desc) a"); sb.Append("select sum(balance) from cash"); strQuery = sb.ToString(); sqlCommand = new MySqlCommand(strQuery, sqlConnection); @@ -116,7 +115,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/CashflowStatementDA.cs b/MarketDataLib/DataAccess/CashflowStatementDA.cs index dae5e13..7b73369 100644 --- a/MarketDataLib/DataAccess/CashflowStatementDA.cs +++ b/MarketDataLib/DataAccess/CashflowStatementDA.cs @@ -59,7 +59,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -95,7 +95,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -133,7 +133,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -171,7 +171,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -221,7 +221,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -269,7 +269,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/CompanyProfileDA.cs b/MarketDataLib/DataAccess/CompanyProfileDA.cs index f7e9910..c18a9b7 100644 --- a/MarketDataLib/DataAccess/CompanyProfileDA.cs +++ b/MarketDataLib/DataAccess/CompanyProfileDA.cs @@ -3,6 +3,7 @@ using System.Text; using MySql.Data.MySqlClient; using MarketData.MarketDataModel; using MarketData.Utils; +using System.Collections.Generic; namespace MarketData.DataAccess { @@ -69,6 +70,55 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + + public static Dictionary GetCompanyProfiles(List symbols) + { + Dictionary companyProfiles=new Dictionary(); + MySqlConnection sqlConnection = null; + MySqlDataReader sqlDataReader = null; + MySqlCommand sqlCommand=null; + String strQuery = null; + + try + { + StringBuilder sb = new StringBuilder(); + sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); + sb.Append("select sm.symbol,sm.sector,sm.industry,sm.security_type,sm.company,cp.description,cp.pricing_source,cp.can_roll_previous,cp.freeze_pricing from securitymaster sm left outer join companyprofile cp on sm.symbol=cp.symbol").Append(" "); + sb.Append("where sm.symbol in ").Append(SqlUtils.CreateInClause(symbols)); + strQuery = sb.ToString(); + sqlCommand = new MySqlCommand(strQuery, sqlConnection); + sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; + sqlDataReader = sqlCommand.ExecuteReader(); + while(sqlDataReader.Read()) + { + CompanyProfile companyProfile = new CompanyProfile(); + companyProfile.Symbol=sqlDataReader.GetString(0); + if (!sqlDataReader.IsDBNull(1)) companyProfile.Sector = sqlDataReader.GetString(1); + if (!sqlDataReader.IsDBNull(2)) companyProfile.Industry = sqlDataReader.GetString(2); + if (!sqlDataReader.IsDBNull(3)) companyProfile.SecurityType = sqlDataReader.GetString(3); + if (!sqlDataReader.IsDBNull(4)) companyProfile.CompanyName = sqlDataReader.GetString(4); + if (!sqlDataReader.IsDBNull(5)) companyProfile.Description = sqlDataReader.GetString(5); + if (!sqlDataReader.IsDBNull(6)) companyProfile.PricingSource = sqlDataReader.GetString(6).ToUpper(); + if (!sqlDataReader.IsDBNull(7)) companyProfile.CanRollPrevious = sqlDataReader.GetBoolean(7); + if (!sqlDataReader.IsDBNull(8)) companyProfile.FreezePricing = sqlDataReader.GetBoolean(8); + if(!companyProfiles.ContainsKey(companyProfile.Symbol))companyProfiles.Add(companyProfile.Symbol, companyProfile); + } + return companyProfiles; + } + catch (Exception exception) + { + MDTrace.WriteLine(LogLevel.DEBUG,exception); + return null; + } + finally + { + if(null!=sqlCommand)sqlCommand.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} + if (null != sqlConnection) sqlConnection.Close(); + } + } + + public static CompanyProfiles GetCompanyProfiles() { CompanyProfiles companyProfiles=new CompanyProfiles(); @@ -110,10 +160,11 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } + public static CompanyProfile GetCompanyProfile(String symbol) { MySqlConnection sqlConnection = null; @@ -152,7 +203,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -187,6 +238,7 @@ namespace MarketData.DataAccess if(null!=sqlDataReader){sqlDataReader.Close();sqlDataReader.Dispose();} } } + private static bool InsertCompanyProfileDescription(CompanyProfile companyProfile,MySqlConnection sqlConnection,MySqlTransaction sqlTransaction) { MySqlCommand sqlCommand=null; @@ -216,6 +268,7 @@ namespace MarketData.DataAccess if(null!=sqlCommand)sqlCommand.Dispose(); } } + private static bool UpdateCompanyProfileDescription(CompanyProfile companyProfile,MySqlConnection sqlConnection,MySqlTransaction sqlTransaction) { MySqlCommand sqlCommand=null; diff --git a/MarketDataLib/DataAccess/CompositeDA.cs b/MarketDataLib/DataAccess/CompositeDA.cs index ffd36e8..55e2aa9 100644 --- a/MarketDataLib/DataAccess/CompositeDA.cs +++ b/MarketDataLib/DataAccess/CompositeDA.cs @@ -38,7 +38,6 @@ namespace MarketData.DataAccess sb.Append("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;select 'Splits' description,count(*), modified from splits group by 3 order by modified desc"); break; case FeedStatistic.FeedStatisticType.SECURITY_MASTER: -// sb.Append("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;select 'Security Master' description,count(*), date(create_date) from securitymaster group by 3 order by create_date desc"); sb.Append("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;select 'Security Master' description,count(*), date(create_date) from securitymaster group by 3 order by 3 desc"); break; case FeedStatistic.FeedStatisticType.SEC_FILINGS: @@ -189,7 +188,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -242,7 +241,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -289,7 +288,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -349,7 +348,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/CurrencyConversionDA.cs b/MarketDataLib/DataAccess/CurrencyConversionDA.cs index 076d8ea..3f90157 100644 --- a/MarketDataLib/DataAccess/CurrencyConversionDA.cs +++ b/MarketDataLib/DataAccess/CurrencyConversionDA.cs @@ -49,7 +49,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -166,7 +166,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/DictionaryDA.cs b/MarketDataLib/DataAccess/DictionaryDA.cs index 9f95c8e..bfcc110 100644 --- a/MarketDataLib/DataAccess/DictionaryDA.cs +++ b/MarketDataLib/DataAccess/DictionaryDA.cs @@ -133,7 +133,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -221,6 +221,7 @@ namespace MarketData.DataAccess } finally { + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlCommand)sqlCommand.Dispose(); if (null != sqlConnection) sqlConnection.Close(); } @@ -264,6 +265,7 @@ namespace MarketData.DataAccess { if(null!=sqlCommand)sqlCommand.Dispose(); if (null != sqlConnection) sqlConnection.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} } } public static DictionaryCollection GetDictionaryCollection() @@ -304,6 +306,7 @@ namespace MarketData.DataAccess { if(null!=sqlCommand)sqlCommand.Dispose(); if (null != sqlConnection) sqlConnection.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} } } private static bool DeleteDictionaryCollection(DictionaryCollection dictionaryCollection, MySqlConnection sqlConnection, MySqlTransaction sqlTransaction) diff --git a/MarketDataLib/DataAccess/DividendHistoryDA.cs b/MarketDataLib/DataAccess/DividendHistoryDA.cs index a24638e..ec019cf 100644 --- a/MarketDataLib/DataAccess/DividendHistoryDA.cs +++ b/MarketDataLib/DataAccess/DividendHistoryDA.cs @@ -231,7 +231,6 @@ namespace MarketData.DataAccess if (null == dividendHistoryItem.PaymentDate) sb.Append("null").Append(","); else sb.Append(SqlUtils.AddQuotes(Utility.DateTimeToStringYYYYHMMHDD(dividendHistoryItem.PaymentDate.Value))).Append(","); -// sb.Append(SqlUtils.AddQuotes(Utility.DateTimeToStringYYYYHMMHDD(modified))); sb.Append(SqlUtils.AddQuotes(SqlUtils.ToSqlDateTime(modified))); sb.Append(")"); strQuery = sb.ToString(); diff --git a/MarketDataLib/DataAccess/DividendPaymentDA.cs b/MarketDataLib/DataAccess/DividendPaymentDA.cs index 6814451..64de83e 100644 --- a/MarketDataLib/DataAccess/DividendPaymentDA.cs +++ b/MarketDataLib/DataAccess/DividendPaymentDA.cs @@ -50,7 +50,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if(null!=sqlDataReader)sqlDataReader.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -94,7 +94,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if(null!=sqlDataReader)sqlDataReader.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -144,7 +144,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -194,7 +194,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -239,7 +239,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if(null!=sqlDataReader)sqlDataReader.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -278,7 +278,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -316,7 +316,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -360,7 +360,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/ETFHoldingsDA.cs b/MarketDataLib/DataAccess/ETFHoldingsDA.cs index 2a43f97..d01e6dc 100644 --- a/MarketDataLib/DataAccess/ETFHoldingsDA.cs +++ b/MarketDataLib/DataAccess/ETFHoldingsDA.cs @@ -45,7 +45,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -79,7 +79,7 @@ namespace MarketData.DataAccess } finally { - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -129,11 +129,20 @@ namespace MarketData.DataAccess ETFHolding etfHolding = etfHoldings[index]; StringBuilder sb = new StringBuilder(); sb.Append("insert into ETFHoldings(etf_symbol,holding_symbol,holding_symbol_sc,pcnt_of_assets,company,modified)values("); + sb.Append(SqlUtils.ToSqlString(etfHolding.ETFSymbol)).Append(","); + sb.Append(SqlUtils.ToSqlString(etfHolding.HoldingSymbol)).Append(","); - sb.Append(SqlUtils.ToSqlString(etfHolding.HoldingSymbolShareClass)).Append(","); - sb.Append(etfHolding.PercentOfAssets).Append(","); - sb.Append(SqlUtils.ToSqlString(etfHolding.HoldingCompanyName)).Append(","); + + if(null==etfHolding.HoldingSymbolShareClass)sb.Append("null").Append(","); + else sb.Append(SqlUtils.ToSqlString(etfHolding.HoldingSymbolShareClass)).Append(","); + + if(double.IsNaN(etfHolding.PercentOfAssets))sb.Append("null").Append(","); + else sb.Append(etfHolding.PercentOfAssets).Append(","); + + if(null==etfHolding.HoldingCompanyName)sb.Append("null").Append(","); + else sb.Append(SqlUtils.ToSqlString(etfHolding.HoldingCompanyName)).Append(","); + sb.Append(SqlUtils.ToSqlString(Utility.DateTimeToStringYYYYHMMHDD(modified))); sb.Append(")"); strQuery = sb.ToString(); @@ -147,7 +156,8 @@ namespace MarketData.DataAccess } catch (Exception exception) { - MDTrace.WriteLine(LogLevel.DEBUG,exception); + MDTrace.WriteLine(LogLevel.DEBUG,$"Exception: {exception.ToString()}"); + if(null!=strQuery)MDTrace.WriteLine(LogLevel.DEBUG,$"Query was {strQuery}"); return false; } finally @@ -196,7 +206,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -240,7 +250,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -284,7 +294,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/EarningsAnnouncementsDA.cs b/MarketDataLib/DataAccess/EarningsAnnouncementsDA.cs index 12e1dd0..ad3a84e 100644 --- a/MarketDataLib/DataAccess/EarningsAnnouncementsDA.cs +++ b/MarketDataLib/DataAccess/EarningsAnnouncementsDA.cs @@ -52,7 +52,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -96,7 +96,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -138,7 +138,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/FundamentalDA.cs b/MarketDataLib/DataAccess/FundamentalDA.cs index 702c7c0..04a64e4 100644 --- a/MarketDataLib/DataAccess/FundamentalDA.cs +++ b/MarketDataLib/DataAccess/FundamentalDA.cs @@ -43,7 +43,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -79,7 +79,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if(null!=sqlDataReader)sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null != sqlConnection) sqlConnection.Close(); } } @@ -122,7 +122,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -165,24 +165,35 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } - public static TimeSeriesCollection GetEPS(String symbol,DateTime? maxDate=null) + + /// + /// Retrieves a collection of timeseries for the given symbols with each symbol having the specified max asof and no more than maxSeries elements in the series + /// + /// + /// + /// + /// + public static Dictionary GetEPS(List symbols, DateTime maxDate,int maxSeries) { MySqlConnection sqlConnection = null; MySqlDataReader sqlDataReader = null; MySqlCommand sqlCommand = null; - TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); + Dictionary timeSeriesCollection = new Dictionary(); String strQuery = null; try { StringBuilder sb = new StringBuilder(); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); - if(null==maxDate)sb.Append("select symbol,asof,eps from fundamentals where symbol='").Append(symbol).Append("' order by asof desc"); - else sb.Append("select symbol,asof,eps from fundamentals where symbol='").Append(symbol).Append("'").Append(" and asof<=").Append(SqlUtils.AddQuotes(SqlUtils.ToSqlDateTime(maxDate.Value))).Append(" order by asof desc"); + + sb.Append("SELECT B.symbol, B.asof, B.eps FROM "); + sb.Append("(SELECT symbol, asof, eps, ROW_NUMBER() OVER(PARTITION BY symbol ORDER BY asof desc) AS rownum FROM fundamentals "); + sb.Append($"WHERE symbol IN {SqlUtils.CreateInClause(symbols)} AND asof<={SqlUtils.ToSqlDate(maxDate,true)} )B "); + sb.Append($"WHERE B.rownum<={maxSeries}"); strQuery = sb.ToString(); ; sqlCommand = new MySqlCommand(strQuery, sqlConnection); sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; @@ -197,7 +208,11 @@ namespace MarketData.DataAccess timeSeriesElement.Type = TimeSeriesElement.ElementType.OTHER; timeSeriesElement.OtherType = "EPS"; if (double.IsNaN(timeSeriesElement.Value)) continue; - timeSeriesCollection.Add(timeSeriesElement); + if(!timeSeriesCollection.ContainsKey(timeSeriesElement.Symbol)) + { + timeSeriesCollection.Add(timeSeriesElement.Symbol,new TimeSeriesCollection()); + } + timeSeriesCollection[timeSeriesElement.Symbol].Add(timeSeriesElement); } return timeSeriesCollection; } @@ -209,10 +224,11 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } - } + } + public static Fundamental GetFundamental(String symbol) { MySqlConnection sqlConnection = null; @@ -275,7 +291,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -344,7 +360,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -382,10 +398,69 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } + + + /// + /// Retrieve latest MarketCap, PE, EBITDA, RevenuePerShare for all symbols with aasof being no more recent than the provided date + /// Given a tradeDate of 04/18/2025 this method might return a collection similar to below. The model returned is a subset of the fundamental + /// 07/15/2018 ^FTSE + /// 03/13/2019 ^GSPC + /// 04/17/2025 AA + /// + /// The as of date + /// + public static FundamentalsV2 GetFundamentalsMaxDateV2(DateTime tradeDate) + { + MySqlConnection sqlConnection = null; + MySqlDataReader sqlDataReader = null; + MySqlCommand sqlCommand=null; + String strQuery = null; + FundamentalsV2 fundamentals = new FundamentalsV2(); + + try + { + StringBuilder sb = new StringBuilder(); + sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); + sb.Append("SELECT A.asof,A.symbol, A.market_cap,A.ebitda,A.pe,A.revenue_per_share FROM fundamentals A JOIN "); + sb.Append("(SELECT MAX(asof) asof,symbol FROM fundamentals WHERE asof<=").Append("'"); + sb.Append(Utility.DateTimeToStringYYYYHMMHDD(tradeDate.Date)); + sb.Append("'"); + sb.Append(" GROUP BY symbol ORDER BY symbol ASC)B "); + sb.Append(" ON A.asof=B.asof AND A.symbol=B.symbol "); + strQuery = sb.ToString(); ; + sqlCommand = new MySqlCommand(strQuery, sqlConnection); + sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; + sqlDataReader = sqlCommand.ExecuteReader(); + while(sqlDataReader.Read()) + { + FundamentalV2 fundamental = new FundamentalV2(); + fundamental.AsOf = sqlDataReader.GetDateTime(0); + fundamental.Symbol = sqlDataReader.GetString(1); + if(!sqlDataReader.IsDBNull(2)) fundamental.MarketCap = sqlDataReader.GetDouble(2); + if(!sqlDataReader.IsDBNull(3)) fundamental.EBITDA = sqlDataReader.GetDouble(3); + if(!sqlDataReader.IsDBNull(4)) fundamental.PE = sqlDataReader.GetDouble(4); + if(!sqlDataReader.IsDBNull(5)) fundamental.RevenuePerShare = sqlDataReader.GetDouble(5); + if(!fundamentals.ContainsKey(fundamental.Symbol))fundamentals.Add(fundamental.Symbol,fundamental); + } + return fundamentals; + } + catch (Exception exception) + { + MDTrace.WriteLine(LogLevel.DEBUG,exception); + return null; + } + finally + { + if(null!=sqlCommand)sqlCommand.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} + if (null != sqlConnection) sqlConnection.Close(); + } + } + public static Fundamental GetFundamentalMaxDate(String symbol, DateTime asof) { MySqlConnection sqlConnection = null; @@ -455,7 +530,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -535,7 +610,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/HeadlinesDA.cs b/MarketDataLib/DataAccess/HeadlinesDA.cs index fec7ebf..fdf8a95 100644 --- a/MarketDataLib/DataAccess/HeadlinesDA.cs +++ b/MarketDataLib/DataAccess/HeadlinesDA.cs @@ -45,7 +45,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -80,7 +80,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -123,7 +123,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -166,7 +166,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -211,7 +211,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -255,7 +255,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -298,7 +298,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -399,36 +399,5 @@ namespace MarketData.DataAccess if(null!=sqlDataReader){sqlDataReader.Close();sqlDataReader.Dispose();} } } - //private static bool HeadlineExists(Headline headline,MySqlConnection sqlConnection,MySqlTransaction sqlTransaction) - //{ - // MySqlDataReader sqlDataReader=null; - // MySqlCommand sqlCommand=null; - // String strQuery = null; - - // try - // { - // if (null == headline || null == headline.Symbol) return false; - // StringBuilder sb = new StringBuilder(); - // sb.Append("select count(*) from headlines where symbol=").Append(SqlUtils.AddQuotes(headline.Symbol)).Append(" and "); - // sb.Append(" asof=").Append(SqlUtils.AddQuotes(SqlUtils.SqlDate(headline.Date))).Append(" and "); - // sb.Append(" headline=").Append(SqlUtils.AddQuotes(SqlUtils.SqlString(headline.Entry))); - // strQuery = sb.ToString(); - // sqlCommand = new MySqlCommand(strQuery, sqlConnection, sqlTransaction); - // sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; - // sqlDataReader=sqlCommand.ExecuteReader(); - // if(!sqlDataReader.Read())return false; - // return 0==sqlDataReader.GetInt32(0)?false:true; - // } - // catch (Exception exception) - // { - // MDTrace.WriteLine(LogLevel.DEBUG,exception); - // return false; - // } - // finally - // { - // if(null!=sqlCommand)sqlCommand.Dispose(); - // if(null!=sqlDataReader){sqlDataReader.Close();sqlDataReader.Dispose();} - // } - //} } } diff --git a/MarketDataLib/DataAccess/HistoricalDA.cs b/MarketDataLib/DataAccess/HistoricalDA.cs index 3812ddc..ac1d1ee 100644 --- a/MarketDataLib/DataAccess/HistoricalDA.cs +++ b/MarketDataLib/DataAccess/HistoricalDA.cs @@ -56,7 +56,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -101,7 +101,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/HolidayDA.cs b/MarketDataLib/DataAccess/HolidayDA.cs index f31a255..a242bd2 100644 --- a/MarketDataLib/DataAccess/HolidayDA.cs +++ b/MarketDataLib/DataAccess/HolidayDA.cs @@ -44,7 +44,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } @@ -79,7 +79,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } @@ -115,7 +115,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } @@ -151,7 +151,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/IncomeStatementDA.cs b/MarketDataLib/DataAccess/IncomeStatementDA.cs index 78a2d39..9b99616 100644 --- a/MarketDataLib/DataAccess/IncomeStatementDA.cs +++ b/MarketDataLib/DataAccess/IncomeStatementDA.cs @@ -42,10 +42,11 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } + public static List GetIncomeStatementDates(String symbol,IncomeStatement.PeriodType periodType) { List incomeStatementDates = new List(); @@ -80,10 +81,11 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } + public static DateTime? GetLatestIncomeStatementDate(String symbol,IncomeStatement.PeriodType periodType) { MySqlConnection sqlConnection = null; @@ -118,10 +120,11 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } + public static IncomeStatement GetIncomeStatement(String symbol,IncomeStatement.PeriodType periodType) { MySqlConnection sqlConnection = null; @@ -170,12 +173,14 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } + public static TimeSeriesCollection GetRevenue(String symbol,IncomeStatement.PeriodType period) { + Profiler profiler = new Profiler(); TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); MySqlConnection sqlConnection = null; MySqlDataReader sqlDataReader = null; @@ -212,10 +217,11 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } + // Profit Margin is calculated as a percentage. public static TimeSeriesCollection GetProfitMargin(String symbol,IncomeStatement.PeriodType period=IncomeStatement.PeriodType.Annual) { @@ -260,14 +266,14 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } - // Profit Margin is calculated as a percentage. - public static TimeSeriesCollection GetProfitMarginMaxAsOf(String symbol,DateTime maxDate, IncomeStatement.PeriodType period = IncomeStatement.PeriodType.Annual) + + public static Dictionary GetProfitMarginMaxAsOf(List symbols, DateTime maxDate,int maxSeries,IncomeStatement.PeriodType period = IncomeStatement.PeriodType.Annual) { - TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); + Dictionary timeSeriesCollection = new Dictionary(); MySqlConnection sqlConnection = null; MySqlDataReader sqlDataReader = null; MySqlCommand sqlCommand = null; @@ -277,9 +283,11 @@ namespace MarketData.DataAccess { StringBuilder sb = new StringBuilder(); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); - sb.Append("select symbol,asof,total_revenue,gross_profit from incomestatement where symbol='").Append(symbol).Append("'").Append(" "); - sb.Append(" and asof<='").Append(SqlUtils.SqlDate(maxDate)).Append("' "); - sb.Append(" and period=").Append(period.Equals(IncomeStatement.PeriodType.Annual) ? 0 : 1).Append(" order by asof desc;"); + sb.Append("SELECT B.symbol, B.asof, B.total_revenue, B.gross_profit FROM "); + sb.Append("(SELECT symbol, asof, total_revenue, gross_profit, period , ROW_NUMBER() OVER(PARTITION BY symbol ORDER BY asof desc) AS rownum FROM incomestatement "); + sb.Append($" WHERE symbol IN {SqlUtils.CreateInClause(symbols)} AND asof<={SqlUtils.ToSqlDate(maxDate.Date,true)}"); + sb.Append($" AND period={(period.Equals(IncomeStatement.PeriodType.Annual) ? 0 : 1)} )B "); + sb.Append($" WHERE B.rownum<={maxSeries} "); strQuery = sb.ToString(); sqlCommand = new MySqlCommand(strQuery, sqlConnection); sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; @@ -289,15 +297,19 @@ namespace MarketData.DataAccess TimeSeriesElement timeSeriesElement = new TimeSeriesElement(); timeSeriesElement.Symbol = sqlDataReader.GetString(0); timeSeriesElement.AsOf = sqlDataReader.GetDateTime(1); - timeSeriesElement.Type = period.Equals(IncomeStatement.PeriodType.Quarterly) ? TimeSeriesElement.ElementType.QuarterlyRevenue : TimeSeriesElement.ElementType.Revenue; - + timeSeriesElement.Type = TimeSeriesElement.ElementType.OTHER; + timeSeriesElement.OtherType = "Profit Margin %"; if (sqlDataReader.IsDBNull(2)) continue; double total_revenue = sqlDataReader.GetDouble(2); if (sqlDataReader.IsDBNull(3)) continue; double gross_profit = sqlDataReader.GetDouble(3); if (0 == gross_profit) continue; timeSeriesElement.Value = (gross_profit / total_revenue) * 100.00; - timeSeriesCollection.Add(timeSeriesElement); + if(!timeSeriesCollection.ContainsKey(timeSeriesElement.Symbol)) + { + timeSeriesCollection.Add(timeSeriesElement.Symbol, new TimeSeriesCollection()); + } + timeSeriesCollection[timeSeriesElement.Symbol].Add(timeSeriesElement); } return timeSeriesCollection; } @@ -309,10 +321,11 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } - } + } + public static IncomeStatement GetIncomeStatement(String symbol,DateTime asof,IncomeStatement.PeriodType periodType) { MySqlConnection sqlConnection = null; @@ -359,10 +372,11 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } + public static IncomeStatement GetIncomeStatementMaxAsOf(String symbol,DateTime asof,IncomeStatement.PeriodType periodType) { MySqlConnection sqlConnection = null; @@ -410,10 +424,11 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } + public static bool InsertIncomeStatements(List incomeStatements) { MySqlConnection sqlConnection = null; @@ -480,6 +495,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + private static bool DeleteIncomeStatements(List incomeStatements, MySqlConnection sqlConnection, MySqlTransaction sqlTransaction) { for (int index = 0; index < incomeStatements.Count; index++) @@ -488,6 +504,7 @@ namespace MarketData.DataAccess } return true; } + private static bool DeleteIncomeStatement(IncomeStatement incomeStatement, MySqlConnection sqlConnection, MySqlTransaction sqlTransaction) { StringBuilder sb = new StringBuilder(); diff --git a/MarketDataLib/DataAccess/InsiderTransactionDA.cs b/MarketDataLib/DataAccess/InsiderTransactionDA.cs index 04e8fef..ad1e546 100644 --- a/MarketDataLib/DataAccess/InsiderTransactionDA.cs +++ b/MarketDataLib/DataAccess/InsiderTransactionDA.cs @@ -50,7 +50,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -102,7 +102,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -155,7 +155,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/LexicalDA.cs b/MarketDataLib/DataAccess/LexicalDA.cs index daa51d1..c6d2ba8 100644 --- a/MarketDataLib/DataAccess/LexicalDA.cs +++ b/MarketDataLib/DataAccess/LexicalDA.cs @@ -132,7 +132,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -223,6 +223,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -264,6 +265,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/MStarSecurityDA.cs b/MarketDataLib/DataAccess/MStarSecurityDA.cs index eff08ea..f556093 100644 --- a/MarketDataLib/DataAccess/MStarSecurityDA.cs +++ b/MarketDataLib/DataAccess/MStarSecurityDA.cs @@ -46,7 +46,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -173,7 +173,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/OptionsDA.cs b/MarketDataLib/DataAccess/OptionsDA.cs index 209d621..d429c6e 100644 --- a/MarketDataLib/DataAccess/OptionsDA.cs +++ b/MarketDataLib/DataAccess/OptionsDA.cs @@ -44,7 +44,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -98,7 +98,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -153,7 +153,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -204,7 +204,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -257,7 +257,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -304,7 +304,6 @@ namespace MarketData.DataAccess sb.Append(" and strike=").Append(Utility.FormatNumber(option.Strike,2)); sb.Append(" and option_type=").Append(SqlUtils.AddQuotes(option.Type.Equals(OptionTypeEnum.CallOption) ? "C" : "P")); strQuery = sb.ToString(); -// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("DeleteOption {0},{1},{2},{3}",option.Symbol,Utility.DateTimeToStringMMHDDHYYYY(option.Expiration),option.Type.Equals(OptionTypeEnum.CallOption)?"Call":"Put",option.Strike)); sqlCommand = new MySqlCommand(strQuery, sqlConnection, sqlTransaction); sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; sqlCommand.ExecuteNonQuery(); @@ -323,43 +322,6 @@ namespace MarketData.DataAccess if (null != sqlConnection) { sqlConnection.Close(); sqlConnection = null; } } } -// private static bool DeleteOption(Option option) -// { -// MySqlConnection sqlConnection = null; -// MySqlCommand sqlCommand = null; -// MySqlTransaction sqlTransaction=null; -// String strQuery = null; -// try -// { -// StringBuilder sb = new StringBuilder(); -// sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); -// sqlTransaction = sqlConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); -// sb.Append("delete from options where symbol=").Append(SqlUtils.AddQuotes(option.Symbol)); -// sb.Append(" and expiration_date=").Append(SqlUtils.AddQuotes(Utility.DateTimeToStringYYYYHMMHDD(option.Expiration))); -// sb.Append(" and strike=").Append(Utility.FormatNumber(option.Strike,2)); -// sb.Append(" and option_type=").Append(SqlUtils.AddQuotes(option.Type.Equals(OptionTypeEnum.CallOption) ? "C" : "P")); -// strQuery = sb.ToString(); -//// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("DeleteOption {0},{1},{2},{3}",option.Symbol,Utility.DateTimeToStringMMHDDHYYYY(option.Expiration),option.Type.Equals(OptionTypeEnum.CallOption)?"Call":"Put",option.Strike)); -// sqlCommand = new MySqlCommand(strQuery, sqlConnection, sqlTransaction); -// sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; -// sqlCommand.ExecuteNonQuery(); -// sqlTransaction.Commit(); -// sqlCommand.Dispose(); -// sqlCommand = null; -// return true; -// } -// catch (Exception exception) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,exception); -// return false; -// } -// finally -// { -// if (null != sqlCommand) { sqlCommand.Dispose(); sqlCommand = null; } -// if (null != sqlConnection) { sqlConnection.Close(); sqlConnection.Dispose();sqlConnection = null; } -// if(null!=sqlTransaction){sqlTransaction.Dispose();sqlTransaction=null;} -// } -// } public static bool AddOptions(Options options) { foreach (Option option in options) @@ -377,10 +339,8 @@ namespace MarketData.DataAccess try { -// MDTrace.WriteLine(LogLevel.DEBUG,"[AddOption]Enter"); DateTime modified = DateTime.Now; if (null == option) return false; -// DeleteOption(option); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); sqlTransaction = sqlConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); DeleteOption(option,sqlTransaction); @@ -406,7 +366,6 @@ namespace MarketData.DataAccess sb.Append(SqlUtils.AddQuotes(Utility.DateTimeToStringYYYYHMMHDD(modified))); sb.Append(")"); strQuery = sb.ToString(); -// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("AddOption {0},{1},{2},{3}",option.Symbol,Utility.DateTimeToStringMMHDDHYYYY(option.Expiration),option.Type.Equals(OptionTypeEnum.CallOption)?"Call":"Put",option.Strike)); sqlCommand = new MySqlCommand(strQuery, sqlConnection, sqlTransaction); sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT; sqlCommand.ExecuteNonQuery(); @@ -425,7 +384,6 @@ namespace MarketData.DataAccess if(null!=sqlCommand)sqlCommand.Dispose(); if (null != sqlConnection) sqlConnection.Close(); if (null != sqlTransaction) sqlTransaction.Dispose(); -// MDTrace.WriteLine(LogLevel.DEBUG,"[AddOption]LEAVE"); } } } diff --git a/MarketDataLib/DataAccess/PortfolioDA.cs b/MarketDataLib/DataAccess/PortfolioDA.cs index 087a459..c229b6a 100644 --- a/MarketDataLib/DataAccess/PortfolioDA.cs +++ b/MarketDataLib/DataAccess/PortfolioDA.cs @@ -52,7 +52,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } @@ -149,7 +149,7 @@ namespace MarketData.DataAccess try { - if(null==symbols || 0==symbols.Count)return hasStopLimit; + if(null == symbols || 0==symbols.Count)return hasStopLimit; StringBuilder sb=new StringBuilder(); if(null==symbols) return null; sqlConnection=SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("portfolio_data")); @@ -177,7 +177,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } @@ -213,7 +213,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } @@ -384,7 +384,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -435,7 +435,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -486,7 +486,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -537,7 +537,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -606,7 +606,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -660,7 +660,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -712,7 +712,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -763,10 +763,17 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } + + /// + /// If the trade is open then we only get a single BUY side for the position + /// If the trade is closed then we produce a buy lot and a sell lot. + /// + /// + /// PortfolioTrades private static PortfolioTrades BreakoutTrades(PortfolioTrades portfolioTrades) { PortfolioTrades allTrades = new PortfolioTrades(); @@ -858,7 +865,7 @@ namespace MarketData.DataAccess finally { if (null != sqlCommand) sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -890,7 +897,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } @@ -955,7 +962,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand)sqlCommand.Dispose(); - if (null != sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if (null != sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/PremarketDA.cs b/MarketDataLib/DataAccess/PremarketDA.cs index 3d28058..bc6e721 100644 --- a/MarketDataLib/DataAccess/PremarketDA.cs +++ b/MarketDataLib/DataAccess/PremarketDA.cs @@ -10,12 +10,11 @@ namespace MarketData.DataAccess { public class PremarketDA { +// SELECT market, change_value,change_percent,timestamp, STR_TO_DATE(SUBSTRING(TIMESTAMP,12,11),'%h:%i:%s %p') time_of_day,CONVERT(TIMESTAMP,DATE) AS the_day +// FROM premarket WHERE market='S&P' ORDER BY the_day DESC, time_of_day DESC private PremarketDA() { } -//SELECT market, change_value,change_percent,timestamp, STR_TO_DATE(SUBSTRING(TIMESTAMP,12,11),'%h:%i:%s %p') time_of_day,CONVERT(TIMESTAMP,DATE) AS the_day -//FROM premarket WHERE market='S&P' ORDER BY the_day DESC, time_of_day DESC - public static bool AddElements(PremarketElements premarketElements) { MySqlConnection sqlConnection=null; @@ -118,7 +117,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } @@ -153,7 +152,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } @@ -191,7 +190,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } @@ -237,7 +236,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } @@ -272,7 +271,7 @@ namespace MarketData.DataAccess finally { if(null!=sqlCommand) sqlCommand.Dispose(); - if(null!=sqlDataReader) sqlDataReader.Close(); + if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} if(null!=sqlConnection) sqlConnection.Close(); } } diff --git a/MarketDataLib/DataAccess/PricingDA.cs b/MarketDataLib/DataAccess/PricingDA.cs index 680b322..6b93c90 100644 --- a/MarketDataLib/DataAccess/PricingDA.cs +++ b/MarketDataLib/DataAccess/PricingDA.cs @@ -10,9 +10,11 @@ namespace MarketData.DataAccess public class PricingDA { public static readonly int ForwardLookingDays = 90; + private PricingDA() { } + public static bool AddSecurity(String symbol,String companyName) { MySqlConnection sqlConnection = null; @@ -53,6 +55,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + public static bool SecurityExists(String symbol) { MySqlConnection sqlConnection = null; @@ -90,6 +93,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + public static List GetSymbolsNotIn(List symbols) { MySqlConnection sqlConnection = null; @@ -132,6 +136,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + public static int GetPriceCountOn(DateTime date) { MySqlConnection sqlConnection=null; @@ -287,7 +292,6 @@ namespace MarketData.DataAccess if(null!=sqlConnection) sqlConnection.Close(); } } - public static Dictionary GetLatestDates(List symbols) { MySqlConnection sqlConnection = null; @@ -298,7 +302,7 @@ namespace MarketData.DataAccess try { - if(null == symbols || 0==symbols.Count)return latestDates; + if(null ==symbols || 0==symbols.Count)return latestDates; StringBuilder sb = new StringBuilder(); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); sb.Append(" select symbol, max(date) as date "); @@ -684,6 +688,7 @@ namespace MarketData.DataAccess try { + if(null == symbols || 0==symbols.Count)return dictionary; StringBuilder sb = new StringBuilder(); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); sb.Append("select symbol, company from securitymaster where symbol in "); @@ -1208,7 +1213,6 @@ 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; @@ -1258,9 +1262,9 @@ namespace MarketData.DataAccess if(null!=sqlCommand) sqlCommand.Dispose(); if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();} 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) { MySqlConnection sqlConnection = null; @@ -1368,6 +1372,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + public static Prices GetPrices(String symbol, DateTime endDate) { MySqlConnection sqlConnection = null; @@ -1418,6 +1423,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + public static bool InsertPrice(Price price) { Prices prices = new Prices(); @@ -1425,6 +1431,7 @@ namespace MarketData.DataAccess DeletePrice(price.Symbol, price.Date); return InsertPrices(prices); } + public static bool InsertPrices(Prices prices) { MySqlConnection sqlConnection=null; @@ -1483,6 +1490,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + public static bool DeletePrice(String symbol, DateTime date) { MySqlConnection sqlConnection = null; @@ -1512,6 +1520,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + public static bool DeletePriceOnOrAfter(String symbol, DateTime date) { MySqlConnection sqlConnection = null; @@ -1541,6 +1550,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + public static bool DeletePriceOnOrBefore(String symbol, DateTime date) { MySqlConnection sqlConnection = null; @@ -1570,6 +1580,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + private static bool DeletePrices(Prices prices, MySqlConnection sqlConnection, MySqlTransaction sqlTransaction) { for(int index=0;index symbolsHeld=null) + public static CMTCandidate GenerateCandidate( + String symbol, + DateTime tradeDate, + CMTParams cmtParams, + FundamentalV2 fundamental, + CompanyProfile companyProfile, + List historicalDates, + TimeSeriesCollection epsTimeSeries, + TimeSeriesCollection profitMarginTimeSeries, + List symbolsHeld=null) { CMTCandidate cmtCandidate=new CMTCandidate(); try { // Check MarketCap - Fundamental fundamental=FundamentalDA.GetFundamentalMaxDate(symbol,tradeDate); if(null==fundamental) { cmtCandidate.Violation=true; @@ -54,7 +63,6 @@ namespace MarketData.Generator.CMTrend return cmtCandidate; } // Equity check - CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol); if(null==companyProfile) { cmtCandidate.Violation=true; @@ -93,7 +101,7 @@ namespace MarketData.Generator.CMTrend cmtCandidate.Reason=String.Format("Insufficient pricing history, {0} days required.",PRICING_DAYS); return cmtCandidate; } -// Current Price Check +// Current Price Check. The current price must be equal to the trade date Price currentPrice=prices[0]; if(currentPrice.Date.Date!=tradeDate.Date) { @@ -205,10 +213,7 @@ namespace MarketData.Generator.CMTrend // generate a 14 day standard RSI with 30 days of pricing data Prices rsiPrices=GBPriceCache.GetInstance().GetPrices(symbol,currentPrice.Date,30); RSICollection rsiCollection=RSIGenerator.GenerateRSI(rsiPrices); - double rsi=rsiCollection[rsiCollection.Count-1].RSI; - - // RSICollection rsiCollection=RSIGenerator.GenerateRSI(symbol,currentPrice.Date,30); - // double rsi=rsiCollection[rsiCollection.Count-1].RSI; + double rsi=rsiCollection[rsiCollection.Count-1].RSI; if(null==rsiCollection||0==rsiCollection.Count||rsi dma200List=new List(); - DateTime historicalDate=dateGenerator.GenerateHistoricalDate(currentPrice.Date,cmtParams.DMA200Horizon+10); - List historicalDates=PricingDA.GetPricingDatesBetween(historicalDate,currentPrice.Date); historicalDates=historicalDates.Take(cmtParams.DMA200Horizon).ToList(); if(historicalDates.Count x.AsOf); maxDate=profitMarginTimeSeries.Max(x => x.AsOf); values=profitMarginTimeSeries.ToFloat(); - values=Numerics.Reverse(ref values); + values=Numerics.Reverse(ref values); // because most recent date is in the lowest valued index bucket. profitMarginSlope=Numerics.Slope(values); if(profitMarginSlope<=0) { diff --git a/MarketDataLib/Generator/CMTrend/CMTTrendGenerator.cs b/MarketDataLib/Generator/CMTrend/CMTTrendGenerator.cs index 550949a..6b05830 100644 --- a/MarketDataLib/Generator/CMTrend/CMTTrendGenerator.cs +++ b/MarketDataLib/Generator/CMTrend/CMTTrendGenerator.cs @@ -1,4 +1,5 @@ -using MarketData.DataAccess; +using Axiom.Interpreter; +using MarketData.DataAccess; using MarketData.MarketDataModel; using MarketData.Utils; using System; @@ -20,13 +21,58 @@ namespace MarketData.Generator.CMTrend try { List symbols=PricingDA.GetSymbols(); + +// Filter out symbols where we do not have a price on trade date + Profiler profiler = new Profiler(); Dictionary latestDates = PricingDA.GetLatestDates(symbols); symbols=symbols.Where(x => latestDates.ContainsKey(x) && latestDates[x].Date>=tradeDate.Date).ToList(); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded pricing dates in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + +// Prefetch a subset of fundamentals where each fundamental.asof is no greater than tradeDate + profiler.Reset(); + FundamentalsV2 fundamentals = FundamentalDA.GetFundamentalsMaxDateV2(tradeDate); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded fundamentals in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + +// Prefetch the Company Profiles + profiler.Reset(); + Dictionary companyProfiles = CompanyProfileDA.GetCompanyProfiles(symbols); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded company profiles in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + +// Prefetch the pricing dates required for 200 day moving average. + profiler.Reset(); + DateGenerator dateGenerator = new DateGenerator(); + DateTime historicalDate=dateGenerator.GenerateHistoricalDate(tradeDate,cmtParams.DMA200Horizon+10); + List historicalDates=PricingDA.GetPricingDatesBetween(historicalDate,tradeDate); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded moving average dates in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + +// Prefetch the EPS time series + profiler.Reset(); + Dictionary epsTimeSeriesCollectionDictionary = FundamentalDA.GetEPS(symbols,tradeDate,3); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded EPS Time Series in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + +// Prefetch the profit margin time series + profiler.Reset(); + Dictionary profitMarginTimeSeriesCollectionDictionary = IncomeStatementDA.GetProfitMarginMaxAsOf(symbols,tradeDate,3,IncomeStatement.PeriodType.Quarterly); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Profit Margin Time Series in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + for(int index=0;index violations=new List(); List candidates=new List(); +// Filter out symbols where we do not have a price on trade date + Profiler profiler = new Profiler(); + Dictionary latestDates = PricingDA.GetLatestDates(symbols); + symbols=symbols.Where(x => latestDates.ContainsKey(x) && latestDates[x].Date>=analysisDate.Value.Date).ToList(); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded pricing dates in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + + +// Prefetch a subset of fundamentals where each fundamental.asof is no greater than tradeDate + profiler.Reset(); + FundamentalsV2 fundamentals = FundamentalDA.GetFundamentalsMaxDateV2(analysisDate.Value); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded fundamentals in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + +// Prefetch the company profiles + profiler.Reset(); + Dictionary companyProfiles = CompanyProfileDA.GetCompanyProfiles(symbols); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded company profiles in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + +// Prefetch the pricing dates required for 200 day moving average. + profiler.Reset(); + DateGenerator dateGenerator = new DateGenerator(); + DateTime historicalDate=dateGenerator.GenerateHistoricalDate(analysisDate.Value,cmtParams.DMA200Horizon+10); + List historicalDates=PricingDA.GetPricingDatesBetween(historicalDate,analysisDate.Value); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded moving average dates in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + +// Prefetch the EPS time series + profiler.Reset(); + Dictionary epsTimeSeriesCollectionDictionary = FundamentalDA.GetEPS(symbols,analysisDate.Value,3); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded EPS Time Series in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + +// Prefetch the profit margin time series + profiler.Reset(); + Dictionary profitMarginTimeSeriesCollectionDictionary = IncomeStatementDA.GetProfitMarginMaxAsOf(symbols,analysisDate.Value,3,IncomeStatement.PeriodType.Quarterly); + MDTrace.WriteLine(LogLevel.DEBUG,$"Loaded Profit Margin Time Series in {Utility.FormatNumber(profiler.End(),2)} (ms)"); + for(int index=0;index + @@ -200,7 +201,6 @@ - @@ -247,6 +247,7 @@ + diff --git a/MarketDataLib/Utility/SQLUtils.cs b/MarketDataLib/Utility/SQLUtils.cs index 3bd0b0c..04fe54a 100644 --- a/MarketDataLib/Utility/SQLUtils.cs +++ b/MarketDataLib/Utility/SQLUtils.cs @@ -221,6 +221,10 @@ namespace MarketData.Utils if (Utility.IsEpoch(dateTime)) return null; return addQuotes?AddQuotes(Utility.DateTimeToStringYYYYHMMHDD(dateTime)):Utility.DateTimeToStringYYYYHMMHDD(dateTime); } + public static String ToSqlDate(DateTime dateTime, bool addQuotes=false) + { + return SqlDate(dateTime, addQuotes); + } public static String ToSqlDateTime(DateTime dateTime, bool addQuotes=false) { return addQuotes?AddQuotes(Utility.DateTimeToStringYYYYHMMHDDHHMMSS(dateTime)):Utility.DateTimeToStringYYYYHMMHDDHHMMSS(dateTime);