Point database to Adrastea. Fix MGSHBacktest.cs PerformanceStatistics. Provide an optimized PricingDA.GetLatestPrices() for use with the UI TradeBlotter.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="market_data" value="Database=market_data;Datasource=localhost;Username=root;Password=dbas"/>
|
||||
<add key="portfolio_data" value="Database=portfolio_data;Datasource=localhost;Username=root;Password=dbas"/>
|
||||
<add key="user_data" value="Database=user_data;Datasource=localhost;Username=root;Password=dbas"/>
|
||||
<add key="market_data" value="Database=market_data;Datasource=adrastea;Username=root;Password=dbas"/>
|
||||
<add key="portfolio_data" value="Database=portfolio_data;Datasource=adrastea;Username=root;Password=dbas"/>
|
||||
<add key="user_data" value="Database=user_data;Datasource=adrastea;Username=root;Password=dbas"/>
|
||||
<add key="sms_smtpaddress" value="smtp.gmail.com"/>
|
||||
<add key="sms_smsusername" value="skessler1964@gmail.com"/>
|
||||
<add key="sms_smspassword" value="xjfo isnf gmyi zovr"/>
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace MarketData.DataAccess
|
||||
}
|
||||
public static bool InsertUpdateStopLimit(StopLimit stopLimit)
|
||||
{
|
||||
if(null==stopLimit||null==stopLimit.Symbol||double.IsNaN(stopLimit.StopPrice))return false;
|
||||
if(null==stopLimit || null==stopLimit.Symbol || double.IsNaN(stopLimit.StopPrice))return false;
|
||||
if(!HasStopLimit(stopLimit.Symbol))return InsertStopLimit(stopLimit);
|
||||
return UpdateStopLimit(stopLimit);
|
||||
}
|
||||
|
||||
@@ -1046,6 +1046,66 @@ namespace MarketData.DataAccess
|
||||
if (null != sqlConnection) sqlConnection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<String, Price> GetLatestPrices(List<String> symbols)
|
||||
{
|
||||
MySqlConnection sqlConnection = null;
|
||||
MySqlDataReader sqlDataReader = null;
|
||||
MySqlCommand sqlCommand=null;
|
||||
String strQuery = null;
|
||||
Dictionary<String, Price> latestPrices = new Dictionary<String, Price>();
|
||||
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
||||
sb.Append($"SELECT B.date, B.symbol,B.open,B.high,B.low,B.close,B.volume,B.adjclose,B.source from ");
|
||||
sb.Append($"(SELECT date, symbol, open, high, low, close, volume, adjclose, SOURCE, ROW_NUMBER() OVER (");
|
||||
sb.Append($"PARTITION BY symbol ORDER BY DATE DESC) AS rownum from prices ");
|
||||
sb.Append($"WHERE symbol IN {SqlUtils.CreateInClause(symbols)})B where B.rownum=1");
|
||||
strQuery = sb.ToString(); ;
|
||||
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
|
||||
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
|
||||
sqlDataReader = sqlCommand.ExecuteReader();
|
||||
while(sqlDataReader.Read())
|
||||
{
|
||||
Price price = new Price();
|
||||
if(!sqlDataReader.IsDBNull(0))price.Date = sqlDataReader.GetDateTime(0);
|
||||
else throw new Exception("Date cannot be null");
|
||||
if(!sqlDataReader.IsDBNull(1))price.Symbol = sqlDataReader.GetString(1);
|
||||
else throw new Exception("Symbol cannot be null");
|
||||
if(!sqlDataReader.IsDBNull(2))price.Open = sqlDataReader.GetDouble(2);
|
||||
else price.Open=double.NaN;
|
||||
if(!sqlDataReader.IsDBNull(3))price.High = sqlDataReader.GetDouble(3);
|
||||
else price.High=double.NaN;
|
||||
if(!sqlDataReader.IsDBNull(4))price.Low = sqlDataReader.GetDouble(4);
|
||||
else price.Low=double.NaN;
|
||||
if(!sqlDataReader.IsDBNull(5))price.Close = sqlDataReader.GetDouble(5);
|
||||
else price.Close=double.NaN;
|
||||
if(!sqlDataReader.IsDBNull(6))price.Volume = sqlDataReader.GetInt64(6);
|
||||
else price.Volume=0;
|
||||
if(!sqlDataReader.IsDBNull(7))price.AdjClose = sqlDataReader.GetDouble(7);
|
||||
else price.AdjClose=double.NaN;
|
||||
if(!sqlDataReader.IsDBNull(8))price.Source = (Price.PriceSource)Utility.CharToNum(sqlDataReader.GetChar(8));
|
||||
else price.Source=Price.PriceSource.Other;
|
||||
if(!latestPrices.ContainsKey(price.Symbol))latestPrices.Add(price.Symbol, price);
|
||||
}
|
||||
return latestPrices;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Query was {0}",strQuery));
|
||||
return latestPrices;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(null!=sqlCommand)sqlCommand.Dispose();
|
||||
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
|
||||
if (null != sqlConnection) sqlConnection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static Prices GetPrices(String symbol)
|
||||
{
|
||||
MySqlConnection sqlConnection = null;
|
||||
|
||||
@@ -197,8 +197,13 @@ namespace MarketData.Generator.MGSHMomentum
|
||||
double totalTrades=sessionParams.AllPositions.Count;
|
||||
double winningTrades=sessionParams.AllPositions.Where(x => x.GainLoss>=0.00).Count();
|
||||
double losingTrades=sessionParams.AllPositions.Where(x => x.GainLoss<0.00).Count();
|
||||
double averageWinningTrade=sessionParams.AllPositions.Where(x => x.GainLoss>=0.00).Average(x => x.GainLossPcnt)*100.00;
|
||||
double averageLosingTrade=sessionParams.AllPositions.Where(x => x.GainLoss<0.00).Average(x => x.GainLossPcnt)*100.00;
|
||||
MGSHPositions winningTradeList = new MGSHPositions(sessionParams.AllPositions.Where(x => x.GainLoss>=0.00).ToList());
|
||||
double averageWinningTrade = winningTradeList.Count>0?winningTradeList.Average(x => x.GainLossPcnt)*100.00:0.00;
|
||||
// double averageWinningTrade=sessionParams.AllPositions.Where(x => x.GainLoss>=0.00).Average(x => x.GainLossPcnt)*100.00;
|
||||
MGSHPositions losingTradeList = new MGSHPositions(sessionParams.AllPositions.Where(x => x.GainLoss<0.00).ToList());
|
||||
double averageLosingTrade = losingTradeList.Count>0?losingTradeList.Average(x => x.GainLossPcnt)*100.00:0.00;
|
||||
// double averageLosingTrade=sessionParams.AllPositions.Where(x => x.GainLoss<0.00).Average(x => x.GainLossPcnt)*100.00;
|
||||
|
||||
double percentWinningTrades=(winningTrades/(double)sessionParams.AllPositions.Count)*100.00;
|
||||
double percentLosingTrades=(losingTrades/(double)sessionParams.AllPositions.Count)*100.00;
|
||||
double expectation=(percentWinningTrades*averageWinningTrade)/(percentLosingTrades*Math.Abs(averageLosingTrade));
|
||||
|
||||
Reference in New Issue
Block a user