|
|
|
|
@@ -12,6 +12,134 @@ namespace MarketData.DataAccess
|
|
|
|
|
private FundamentalDA()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a distinct list of asof dates from the fundamentals
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static List<DateTime> GetDistinctAsOf()
|
|
|
|
|
{
|
|
|
|
|
MySqlConnection sqlConnection = null;
|
|
|
|
|
MySqlDataReader sqlDataReader = null;
|
|
|
|
|
MySqlCommand sqlCommand =null;
|
|
|
|
|
List<DateTime> dates = new List<DateTime>();
|
|
|
|
|
String strQuery = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
|
|
|
|
sb.Append("select distinct(asof) from fundamentals order by 1 desc");
|
|
|
|
|
strQuery = sb.ToString(); ;
|
|
|
|
|
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
|
|
|
|
|
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
|
|
|
|
|
sqlDataReader = sqlCommand.ExecuteReader();
|
|
|
|
|
while (sqlDataReader.Read())
|
|
|
|
|
{
|
|
|
|
|
dates.Add(sqlDataReader.GetDateTime(0));
|
|
|
|
|
}
|
|
|
|
|
return dates;
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the symbols for a particular asof date
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static List<String> GetSymbolsAsOf(DateTime asof)
|
|
|
|
|
{
|
|
|
|
|
MySqlConnection sqlConnection = null;
|
|
|
|
|
MySqlDataReader sqlDataReader = null;
|
|
|
|
|
MySqlCommand sqlCommand =null;
|
|
|
|
|
List<String> symbols = new List<String>();
|
|
|
|
|
String strQuery = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
|
|
|
|
sb.Append("select symbol from fundamentals where asof =").Append(SqlUtils.ToSqlDate(asof,true)).Append(" order by 1 asc");
|
|
|
|
|
strQuery = sb.ToString(); ;
|
|
|
|
|
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
|
|
|
|
|
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
|
|
|
|
|
sqlDataReader = sqlCommand.ExecuteReader();
|
|
|
|
|
while (sqlDataReader.Read())
|
|
|
|
|
{
|
|
|
|
|
symbols.Add(sqlDataReader.GetString(0));
|
|
|
|
|
}
|
|
|
|
|
return symbols;
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the beta36 and bet6 for a symbol for a specific date
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool UpdateBeta(String symbol,DateTime asof,double beta36, double beta06)
|
|
|
|
|
{
|
|
|
|
|
MySqlConnection sqlConnection = null;
|
|
|
|
|
MySqlTransaction sqlTransaction = null;
|
|
|
|
|
MySqlCommand sqlCommand =null;
|
|
|
|
|
|
|
|
|
|
List<String> symbols = new List<String>();
|
|
|
|
|
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("update fundamentals set ");
|
|
|
|
|
sb.Append("beta_calc_36=");
|
|
|
|
|
if (!Double.IsNaN(beta36)) sb.Append(beta36).Append(",");
|
|
|
|
|
else sb.Append("null").Append(",");
|
|
|
|
|
sb.Append("beta_calc_06=");
|
|
|
|
|
if (!Double.IsNaN(beta06)) sb.Append(beta06);
|
|
|
|
|
else sb.Append("null");
|
|
|
|
|
sb.Append(" where ");
|
|
|
|
|
sb.Append("symbol='").Append(symbol).Append("' and asof =").Append(SqlUtils.ToSqlDate(asof,true));
|
|
|
|
|
strQuery = sb.ToString();
|
|
|
|
|
sqlCommand = new MySqlCommand(strQuery, sqlConnection, sqlTransaction);
|
|
|
|
|
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
|
|
|
|
|
sqlCommand.ExecuteNonQuery();
|
|
|
|
|
sqlTransaction.Commit();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
MDTrace.WriteLine(LogLevel.DEBUG,exception);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if(null != sqlTransaction)sqlTransaction.Dispose();
|
|
|
|
|
if(null != sqlCommand)sqlCommand.Dispose();
|
|
|
|
|
if(null != sqlConnection) sqlConnection.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool CheckFundamentalModifiedOn(String symbol,DateTime modified)
|
|
|
|
|
{
|
|
|
|
|
MySqlConnection sqlConnection = null;
|
|
|
|
|
@@ -47,42 +175,6 @@ namespace MarketData.DataAccess
|
|
|
|
|
if (null != sqlConnection) sqlConnection.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static DateTime GetLatestDate(String symbol)
|
|
|
|
|
{
|
|
|
|
|
MySqlConnection sqlConnection = null;
|
|
|
|
|
MySqlDataReader sqlDataReader = null;
|
|
|
|
|
MySqlCommand sqlCommand=null;
|
|
|
|
|
String strQuery = null;
|
|
|
|
|
DateTime maxDate = DateTime.Parse("01-01-0001");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
|
|
|
|
sb.Append("select max(asof) from fundamentals").Append(" ");
|
|
|
|
|
sb.Append("where symbol='").Append(symbol).Append("'");
|
|
|
|
|
strQuery = sb.ToString(); ;
|
|
|
|
|
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
|
|
|
|
|
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
|
|
|
|
|
sqlDataReader = sqlCommand.ExecuteReader();
|
|
|
|
|
if (sqlDataReader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (!sqlDataReader.IsDBNull(0))maxDate=sqlDataReader.GetDateTime(0);
|
|
|
|
|
}
|
|
|
|
|
return maxDate;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
MDTrace.WriteLine(LogLevel.DEBUG,exception);
|
|
|
|
|
return maxDate;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if(null!=sqlCommand)sqlCommand.Dispose();
|
|
|
|
|
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
|
|
|
|
|
if(null != sqlConnection) sqlConnection.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static TimeSeriesCollection GetTotalCashMils(String symbol)
|
|
|
|
|
{
|
|
|
|
|
MySqlConnection sqlConnection = null;
|
|
|
|
|
@@ -240,7 +332,7 @@ namespace MarketData.DataAccess
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
|
|
|
|
sb.Append("select symbol,asof,next_earnings_date,beta,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,book_value_per_share*shares_outstanding as equity,trailing_pe,ebit,enterprise_value,source from fundamentals where symbol=");
|
|
|
|
|
sb.Append("select symbol,asof,next_earnings_date,beta,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,book_value_per_share*shares_outstanding as equity,trailing_pe,ebit,enterprise_value,source,beta_calc_36,beta_calc_06 from fundamentals where symbol=");
|
|
|
|
|
sb.Append("'").Append(symbol).Append("'").Append(" ");
|
|
|
|
|
sb.Append("and asof=(select max(asof) from fundamentals where symbol='").Append(symbol).Append("')");
|
|
|
|
|
strQuery = sb.ToString(); ;
|
|
|
|
|
@@ -279,6 +371,8 @@ namespace MarketData.DataAccess
|
|
|
|
|
if (!sqlDataReader.IsDBNull(27)) fundamental.EBIT = sqlDataReader.GetDouble(27);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(28)) fundamental.EnterpriseValue = sqlDataReader.GetDouble(28);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(29)) fundamental.Source = sqlDataReader.GetString(29);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(30)) fundamental.BetaCalc36 = sqlDataReader.GetDouble(30);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(31)) fundamental.BetaCalc06 = sqlDataReader.GetDouble(31);
|
|
|
|
|
BalanceSheet balanceSheet=BalanceSheetDA.GetBalanceSheetOnOrBefore(symbol,fundamental.AsOf,BalanceSheet.PeriodType.Annual);
|
|
|
|
|
if(null!=balanceSheet&&!double.IsNaN(balanceSheet.TotalStockHolderEquity)&&!double.IsNaN(fundamental.TotalDebt)&&0!=fundamental.TotalDebt)fundamental.DebtToEquity=fundamental.TotalDebt/balanceSheet.TotalStockHolderEquity;
|
|
|
|
|
return fundamental;
|
|
|
|
|
@@ -306,7 +400,7 @@ namespace MarketData.DataAccess
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
|
|
|
|
sb.Append("select symbol,asof,next_earnings_date,beta,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,book_value_per_share*shares_outstanding as equity,trailing_pe,ebit,enterprise_value,source from fundamentals where symbol=");
|
|
|
|
|
sb.Append("select symbol,asof,next_earnings_date,beta,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,book_value_per_share*shares_outstanding as equity,trailing_pe,ebit,enterprise_value,source,beta_calc_36,beta_calc_06 from fundamentals where symbol=");
|
|
|
|
|
sb.Append("'").Append(symbol).Append("'").Append(" ");
|
|
|
|
|
sb.Append("and asof=").Append("'").Append(Utility.DateTimeToStringYYYYHMMHDD(asof)).Append("'").Append(";");
|
|
|
|
|
strQuery = sb.ToString(); ;
|
|
|
|
|
@@ -346,6 +440,8 @@ namespace MarketData.DataAccess
|
|
|
|
|
if (!sqlDataReader.IsDBNull(27)) fundamental.EBIT = sqlDataReader.GetDouble(27);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(28)) fundamental.EnterpriseValue = sqlDataReader.GetDouble(28);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(29)) fundamental.Source = sqlDataReader.GetString(29);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(30)) fundamental.BetaCalc36 = sqlDataReader.GetDouble(30);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(3)) fundamental.BetaCalc06 = sqlDataReader.GetDouble(31);
|
|
|
|
|
if (null != balanceSheet && !double.IsNaN(balanceSheet.TotalStockHolderEquity) && !double.IsNaN(fundamental.TotalDebt) && 0 != fundamental.TotalDebt)
|
|
|
|
|
{
|
|
|
|
|
fundamental.DebtToEquity=fundamental.TotalDebt/balanceSheet.TotalStockHolderEquity;
|
|
|
|
|
@@ -403,7 +499,6 @@ namespace MarketData.DataAccess
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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
|
|
|
|
|
@@ -425,7 +520,7 @@ namespace MarketData.DataAccess
|
|
|
|
|
{
|
|
|
|
|
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 A.asof,A.symbol, A.market_cap,A.ebitda,A.pe,A.revenue_per_share,A.beta,A.beta_calc_36,A.beta_calc_06 FROM fundamentals A JOIN ");
|
|
|
|
|
sb.Append("(SELECT MAX(asof) asof,symbol FROM fundamentals WHERE asof<=").Append("'");
|
|
|
|
|
sb.Append(Utility.DateTimeToStringYYYYHMMHDD(tradeDate.Date));
|
|
|
|
|
sb.Append("'");
|
|
|
|
|
@@ -444,6 +539,9 @@ namespace MarketData.DataAccess
|
|
|
|
|
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(!sqlDataReader.IsDBNull(6)) fundamental.Beta = sqlDataReader.GetDouble(6);
|
|
|
|
|
if(!sqlDataReader.IsDBNull(7)) fundamental.BetaCalc36 = sqlDataReader.GetDouble(7);
|
|
|
|
|
if(!sqlDataReader.IsDBNull(8)) fundamental.BetaCalc06 = sqlDataReader.GetDouble(8);
|
|
|
|
|
if(!fundamentals.ContainsKey(fundamental.Symbol))fundamentals.Add(fundamental.Symbol,fundamental);
|
|
|
|
|
}
|
|
|
|
|
return fundamentals;
|
|
|
|
|
@@ -474,7 +572,7 @@ namespace MarketData.DataAccess
|
|
|
|
|
if(null==maxDate)return null;
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
|
|
|
|
sb.Append("select symbol,asof,next_earnings_date,beta,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,book_value_per_share*shares_outstanding as equity,trailing_pe,ebit,enterprise_value,source from fundamentals where symbol=");
|
|
|
|
|
sb.Append("select symbol,asof,next_earnings_date,beta,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,book_value_per_share*shares_outstanding as equity,trailing_pe,ebit,enterprise_value,source,beta_calc_36,beta_calc_06 from fundamentals where symbol=");
|
|
|
|
|
sb.Append("'").Append(symbol).Append("'").Append(" ");
|
|
|
|
|
sb.Append("and asof=").Append("'").Append(Utility.DateTimeToStringYYYYHMMHDD(maxDate.Value)).Append("'");
|
|
|
|
|
sb.Append(" limit 1");
|
|
|
|
|
@@ -515,6 +613,8 @@ namespace MarketData.DataAccess
|
|
|
|
|
if (!sqlDataReader.IsDBNull(27)) fundamental.EBIT = sqlDataReader.GetDouble(27);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(28)) fundamental.EnterpriseValue = sqlDataReader.GetDouble(28);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(29)) fundamental.Source = sqlDataReader.GetString(29);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(30)) fundamental.BetaCalc36 = sqlDataReader.GetDouble(30);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(31)) fundamental.BetaCalc06 = sqlDataReader.GetDouble(31);
|
|
|
|
|
if (!double.IsNaN(totalStockHolderEquity) && !double.IsNaN(fundamental.TotalDebt))
|
|
|
|
|
{
|
|
|
|
|
if(0.00==totalStockHolderEquity)fundamental.TotalDebt=0.00;
|
|
|
|
|
@@ -535,86 +635,6 @@ namespace MarketData.DataAccess
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Fundamentals GetFundamentalMaxDateTop(String symbol, DateTime asof, int top)
|
|
|
|
|
{
|
|
|
|
|
MySqlConnection sqlConnection = null;
|
|
|
|
|
MySqlDataReader sqlDataReader = null;
|
|
|
|
|
MySqlCommand sqlCommand=null;
|
|
|
|
|
String strQuery = null;
|
|
|
|
|
Fundamentals fundamentals = new Fundamentals();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DateTime? maxDate=GetMaxDateFromFundamental(symbol,asof); // get the maximum date on record on or before max date
|
|
|
|
|
if(null==maxDate)return null;
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
|
|
|
|
sb.Append("select symbol,asof,next_earnings_date,beta,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,book_value_per_share*shares_outstanding as equity,trailing_pe,ebit,enterprise_value,source from fundamentals where symbol=");
|
|
|
|
|
sb.Append("'").Append(symbol).Append("'").Append(" ");
|
|
|
|
|
sb.Append("and asof<=").Append("'").Append(Utility.DateTimeToStringYYYYHMMHDD(maxDate.Value)).Append("'");
|
|
|
|
|
sb.Append(" order by asof desc ");
|
|
|
|
|
sb.Append(" limit ").Append(top);
|
|
|
|
|
strQuery = sb.ToString();
|
|
|
|
|
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
|
|
|
|
|
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
|
|
|
|
|
sqlDataReader = sqlCommand.ExecuteReader();
|
|
|
|
|
while(sqlDataReader.Read())
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
double totalStockHolderEquity=BalanceSheetDA.GetTotalStockHolderEquityOnOrBefore(symbol,asof,BalanceSheet.PeriodType.Annual);
|
|
|
|
|
Fundamental fundamental = new Fundamental();
|
|
|
|
|
fundamental.Symbol = sqlDataReader.GetString(0);
|
|
|
|
|
fundamental.AsOf = sqlDataReader.GetDateTime(1);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(2)) fundamental.NextEarningsDate = sqlDataReader.GetDateTime(2);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(3)) fundamental.Beta = sqlDataReader.GetDouble(3);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(4)) fundamental.Low52 = sqlDataReader.GetDouble(4);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(5)) fundamental.High52 = sqlDataReader.GetDouble(5);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(6)) fundamental.Volume = sqlDataReader.GetInt64(6);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(7)) fundamental.MarketCap = sqlDataReader.GetDouble(7);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(8)) fundamental.PE = sqlDataReader.GetDouble(8);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(9)) fundamental.EPS = sqlDataReader.GetDouble(9);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(10)) fundamental.PEG = sqlDataReader.GetDouble(10);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(11)) fundamental.ReturnOnAssets = sqlDataReader.GetDouble(11);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(12)) fundamental.ReturnOnEquity = sqlDataReader.GetDouble(12);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(13)) fundamental.TotalCash = sqlDataReader.GetDouble(13);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(14)) fundamental.TotalDebt = sqlDataReader.GetDouble(14);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(15)) fundamental.SharesOutstanding = sqlDataReader.GetDouble(15);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(16)) fundamental.Revenue = sqlDataReader.GetDouble(16);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(17)) fundamental.RevenuePerShare = sqlDataReader.GetDouble(17);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(18)) fundamental.QtrlyRevenueGrowth = sqlDataReader.GetDouble(18);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(19)) fundamental.GrossProfit = sqlDataReader.GetDouble(19);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(20)) fundamental.EBITDA = sqlDataReader.GetDouble(20);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(21)) fundamental.NetIncomeAvailableToCommon = sqlDataReader.GetDouble(21);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(22)) fundamental.BookValuePerShare = sqlDataReader.GetDouble(22);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(23)) fundamental.OperatingCashflow = sqlDataReader.GetDouble(23);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(24)) fundamental.LeveragedFreeCashflow = sqlDataReader.GetDouble(24);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(25)) fundamental.Equity = sqlDataReader.GetDouble(25);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(26)) fundamental.TrailingPE = sqlDataReader.GetDouble(26);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(27)) fundamental.EBIT = sqlDataReader.GetDouble(27);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(28)) fundamental.EnterpriseValue = sqlDataReader.GetDouble(28);
|
|
|
|
|
if (!sqlDataReader.IsDBNull(29)) fundamental.Source = sqlDataReader.GetString(29);
|
|
|
|
|
if (!double.IsNaN(totalStockHolderEquity) && !double.IsNaN(fundamental.TotalDebt))
|
|
|
|
|
{
|
|
|
|
|
if(0.00==totalStockHolderEquity)fundamental.TotalDebt=0.00;
|
|
|
|
|
else fundamental.DebtToEquity=fundamental.TotalDebt/totalStockHolderEquity;
|
|
|
|
|
}
|
|
|
|
|
fundamentals.Add(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 bool InsertFundamentals(Fundamentals fundamentals)
|
|
|
|
|
{
|
|
|
|
|
MySqlConnection sqlConnection = null;
|
|
|
|
|
@@ -630,7 +650,7 @@ namespace MarketData.DataAccess
|
|
|
|
|
{
|
|
|
|
|
Fundamental fundamental = fundamentals[index];
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.Append("insert into fundamentals (symbol,asof,next_earnings_date,beta,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,trailing_pe,ebit,enterprise_value,source) ");
|
|
|
|
|
sb.Append("insert into fundamentals (symbol,asof,next_earnings_date,beta,beta_calc_36,beta_calc_06,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,trailing_pe,ebit,enterprise_value,source) ");
|
|
|
|
|
sb.Append("values(");
|
|
|
|
|
sb.Append("'").Append(fundamental.Symbol).Append("'").Append(",");
|
|
|
|
|
sb.Append("'").Append(Utility.DateTimeToStringYYYYHMMHDD(fundamental.AsOf)).Append("'").Append(",");
|
|
|
|
|
@@ -638,6 +658,10 @@ namespace MarketData.DataAccess
|
|
|
|
|
else sb.Append("'").Append(Utility.DateTimeToStringYYYYHMMHDD(fundamental.NextEarningsDate)).Append("'").Append(",");
|
|
|
|
|
if (!Double.IsNaN(fundamental.Beta)) sb.Append(fundamental.Beta).Append(",");
|
|
|
|
|
else sb.Append("null").Append(",");
|
|
|
|
|
if (!Double.IsNaN(fundamental.BetaCalc36)) sb.Append(fundamental.BetaCalc36).Append(",");
|
|
|
|
|
else sb.Append("null").Append(",");
|
|
|
|
|
if (!Double.IsNaN(fundamental.BetaCalc06)) sb.Append(fundamental.BetaCalc06).Append(",");
|
|
|
|
|
else sb.Append("null").Append(",");
|
|
|
|
|
if (!Double.IsNaN(fundamental.Low52)) sb.Append(fundamental.Low52).Append(",");
|
|
|
|
|
else sb.Append("null").Append(",");
|
|
|
|
|
if (!Double.IsNaN(fundamental.High52)) sb.Append(fundamental.High52).Append(",");
|
|
|
|
|
@@ -722,7 +746,7 @@ namespace MarketData.DataAccess
|
|
|
|
|
sqlTransaction = sqlConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
|
|
|
|
|
DeleteFundamental(fundamental, sqlConnection, sqlTransaction);
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.Append("insert into fundamentals (symbol,asof,next_earnings_date,beta,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,trailing_pe,ebit,enterprise_value,source) ");
|
|
|
|
|
sb.Append("insert into fundamentals (symbol,asof,next_earnings_date,beta,beta_calc_36,beta_calc_06,low52,high52,volume,market_cap,pe,eps,peg,return_on_assets,return_on_equity,total_cash,total_debt,shares_outstanding,revenue,revenue_per_share,qtrly_revenue_growth,gross_profit,ebitda,net_income_available_to_common,book_value_per_share,operating_cashflow,leveraged_free_cashflow,trailing_pe,ebit,enterprise_value,source) ");
|
|
|
|
|
sb.Append("values(");
|
|
|
|
|
sb.Append("'").Append(fundamental.Symbol).Append("'").Append(",");
|
|
|
|
|
sb.Append("'").Append(Utility.DateTimeToStringYYYYHMMHDD(fundamental.AsOf)).Append("'").Append(",");
|
|
|
|
|
@@ -730,6 +754,10 @@ namespace MarketData.DataAccess
|
|
|
|
|
else sb.Append("'").Append(Utility.DateTimeToStringYYYYHMMHDD(fundamental.NextEarningsDate)).Append("'").Append(",");
|
|
|
|
|
if (!Double.IsNaN(fundamental.Beta)) sb.Append(fundamental.Beta).Append(",");
|
|
|
|
|
else sb.Append("null").Append(",");
|
|
|
|
|
if (!Double.IsNaN(fundamental.BetaCalc36)) sb.Append(fundamental.BetaCalc36).Append(",");
|
|
|
|
|
else sb.Append("null").Append(",");
|
|
|
|
|
if (!Double.IsNaN(fundamental.BetaCalc06)) sb.Append(fundamental.BetaCalc06).Append(",");
|
|
|
|
|
else sb.Append("null").Append(",");
|
|
|
|
|
if (!Double.IsNaN(fundamental.Low52)) sb.Append(fundamental.Low52).Append(",");
|
|
|
|
|
else sb.Append("null").Append(",");
|
|
|
|
|
if (!Double.IsNaN(fundamental.High52)) sb.Append(fundamental.High52).Append(",");
|
|
|
|
|
|