Updates to support calculated betas in the fundamental feed.

This commit is contained in:
2025-05-06 19:07:18 -04:00
parent 664a3f3271
commit 59ba764ae2
8 changed files with 259 additions and 128 deletions

Binary file not shown.

View File

@@ -394,6 +394,8 @@ CREATE TABLE Fundamentals
source VARCHAR(15),
next_earnings_date DATE,
beta NUMERIC(19,2),
beta_calc_36 NUMERIC(19,2),
beta_calc_06 NUMERIC(19,2),
low52 NUMERIC(19,2),
high52 NUMERIC(19,2),
volume BIGINT,

View File

@@ -1,7 +1,11 @@
REM I wrote this specifically to dump the entire database including SQL to the backupdb.sql for the purpose
REM of importing it into MariaDb running on the Andrastea machine which is a Pi 4 B.
REM If this works out nicely then I am considering purchasing another Pi 5 16Gig
ECHO STARTING DUMP FOR MARIADB
REM "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump" --hex-blob --max_allowed_packet=64M --default-character-set=utf8mb4 --all-databases --user=root --password=dbas --master-data > backupdb.sql
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump" --hex-blob --max_allowed_packet=64M --default-character-set=utf8mb4 --all-databases --user=root --password=dbas --master-data > backupdb.sql
IF EXIST backupdb.sql (
ECHO REMOVING backupdb.sql
DEL backupdb.sql
)
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump" --hex-blob --max_allowed_packet=64M --default-character-set=utf8mb4 --databases market_data portfolio_data user_data --user=root --password=dbas --master-data > backupdb.sql

View File

@@ -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(",");

View File

@@ -829,7 +829,7 @@ namespace MarketData.Generator.MGSHMomentum
}
else
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("[UpdateStopLimitsForActivePositions] No stop adjustment for {0} on {1} because low price {2} is less then or equal to the purchase price {3}.",
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("[UpdateStopLimitsForActivePositions] No stop adjustment for {0} on {1} because low price {2} is less than or equal to the purchase price {3}.",
position.Symbol,
analysisDate.ToShortDateString(),
Utility.FormatCurrency(price.Low),

View File

@@ -6,6 +6,7 @@ using System.Threading;
using MarketData.MarketDataModel;
using MarketData.DataAccess;
using MarketData.Utils;
using MarketData.Numerical;
namespace MarketData.Helper
{
@@ -219,6 +220,8 @@ namespace MarketData.Helper
{
Fundamental priorFundamental=FundamentalDA.GetFundamental(symbol);
fundamental.MergeFrom(priorFundamental); // if any fields are missing on this run then carry forward fields from previous run
fundamental.BetaCalc36=BetaGenerator.Beta(fundamental.Symbol,fundamental.AsOf,36);
fundamental.BetaCalc06=BetaGenerator.Beta(fundamental.Symbol,fundamental.AsOf,6);
FundamentalDA.InsertFundamental(fundamental);
MDTrace.WriteLine(LogLevel.DEBUG,Fundamental.Header);
MDTrace.WriteLine(LogLevel.DEBUG,fundamental.ToString());
@@ -243,6 +246,8 @@ namespace MarketData.Helper
if(null!=nextEarningsDate)fundamental.NextEarningsDate=nextEarningsDate.Value;
Fundamental priorFundamental=FundamentalDA.GetFundamental(symbol);
fundamental.MergeFrom(priorFundamental); // if any fields are missing on this run then carry forward fields from previous run
fundamental.BetaCalc36=BetaGenerator.Beta(fundamental.Symbol,fundamental.AsOf,36);
fundamental.BetaCalc06=BetaGenerator.Beta(fundamental.Symbol,fundamental.AsOf,6);
FundamentalDA.InsertFundamental(fundamental);
MDTrace.WriteLine(LogLevel.DEBUG,Fundamental.Header);
MDTrace.WriteLine(LogLevel.DEBUG,fundamental.ToString());

View File

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Text;
using MarketData.Utils;
namespace MarketData.MarketDataModel
{
public class FundamentalsV2 : Dictionary<String,FundamentalV2>
{
public FundamentalsV2()
{
}
}
public class FundamentalV2
{
private String symbol;
private DateTime asOf;
private double marketCap;
private double pe;
private double ebitda;
private double revenuePerShare;
private double beta;
private double betaCalc36;
private double betaCalc06;
public FundamentalV2()
{
}
public String Symbol
{
get { return symbol; }
set { symbol = value; }
}
public DateTime AsOf
{
get { return asOf; }
set { asOf = value; }
}
public double MarketCap
{
get { return marketCap; }
set { marketCap = value; }
}
public double PE
{
get { return pe; }
set { pe = value; }
}
public double RevenuePerShare
{
get { return revenuePerShare; }
set { revenuePerShare = value; }
}
public double EBITDA
{
get { return ebitda; }
set { ebitda = value; }
}
public double Beta
{
get { return beta; }
set { beta = value; }
}
public double BetaCalc36
{
get { return betaCalc36; }
set { betaCalc36 = value; }
}
public double BetaCalc06
{
get { return betaCalc06; }
set { betaCalc06 = value; }
}
}
}

View File

@@ -18,6 +18,8 @@ namespace MarketData.MarketDataModel
private DateTime asOf;
private DateTime nextEarningsDate;
private double beta;
private double betaCalc36;
private double betaCalc06;
private double low52;
private double high52;
private Int64 volume;
@@ -74,6 +76,16 @@ namespace MarketData.MarketDataModel
get { return beta; }
set { beta = value; }
}
public double BetaCalc36
{
get { return betaCalc36; }
set { betaCalc36 = value; }
}
public double BetaCalc06
{
get { return betaCalc06; }
set { betaCalc06 = value; }
}
public double Low52
{
get { return low52; }
@@ -329,6 +341,8 @@ namespace MarketData.MarketDataModel
sb.Append("Source,");
sb.Append("NextEarningsDate").Append(",");
sb.Append("Beta").Append(",");
sb.Append("BetaCalc36").Append(",");
sb.Append("BetaCalc06").Append(",");
sb.Append("Low52").Append(",");
sb.Append("High52").Append(",");
sb.Append("Volume").Append(",");
@@ -366,6 +380,8 @@ namespace MarketData.MarketDataModel
sb.Append(null == Source ? "" : Source).Append(",");
sb.Append(Utility.DateTimeToStringMMSDDSYYYY(NextEarningsDate)).Append(",");
sb.Append(String.Format("{0:0.00}",Beta )).Append(",");
sb.Append(String.Format("{0:0.00}",BetaCalc36 )).Append(",");
sb.Append(String.Format("{0:0.00}",BetaCalc06 )).Append(",");
sb.Append(String.Format("{0:0.00}",Low52)).Append(",");
sb.Append(String.Format("{0:0.00}",High52)).Append(",");
sb.Append(String.Format("{0:0.00}", Volume)).Append(",");