Add pricing fetches. Add unit test.
Some checks failed
Build .NET Project / build (push) Has been cancelled

This commit is contained in:
2026-03-19 18:07:52 -04:00
parent 22f30466bc
commit 230e2b931f
3 changed files with 136 additions and 19 deletions

View File

@@ -41,6 +41,8 @@ namespace MarketData.Services
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEFINANCIALSTATEMENTS");
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEFUNDAMENTALS");
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEHISTORICAL");
MDTrace.WriteLine(LogLevel.DEBUG,"LOADALLPRICESSYMBOL /SYMBOL: Loads all available prices from Yahoo for symbol ");
MDTrace.WriteLine(LogLevel.DEBUG,"LOADPRICESYMBOLDATE /SYMBOL: /DATE: {optional} - reloads all prices from Yahoo for specified SYMBOL for DATE");
MDTrace.WriteLine(LogLevel.DEBUG,"CALCSTICKER /WAITFORCOMPLETION:{argument1,argument2,...} For example CALCSTICKER /WAITFORCOMPLETION:UPDATEFINANCIALSTATEMENTS,UPDATEFUNDAMENTALS,UPDATEHISTORICAL");
MDTrace.WriteLine(LogLevel.DEBUG,"MGSHSESSION /SESSIONFILE:");
MDTrace.WriteLine(LogLevel.DEBUG,"MGSHRUNBACKTEST /USEHEDGING: /HEDGEINITIALCASH: /USESTOPLIMITS: /KEEPSLOTPOSITIONS: /STARTDATE: /MAXPOSITIONS: /INITIALCASH: /HOLDINGPERIOD: /{ENDDATE}: /SESSIONFILE: ");
@@ -101,6 +103,8 @@ namespace MarketData.Services
tasks.Add("CALCBETAS",TaskCalcBetas);
tasks.Add("OPTIMIZEDB",TaskOptimizeDatabase);
tasks.Add("UPDATEPRICESBARCHARTSWEEP", TaskUpdatePricesBarChartSweep);
tasks.Add("LOADALLPRICESSYMBOL", TaskLoadAllPricesSymbol);
tasks.Add("LOADPRICESYMBOLDATE",TaskLoadPriceSymbolDate);
tasks.Add("ECHO",TaskEcho);
GlobalConfig.Instance.Configuration = configuration; // This call sets up configuration stuff so it needs to be first.
@@ -189,7 +193,6 @@ namespace MarketData.Services
await Task.FromResult(true);
}
public async Task TaskUpdateFundamentals(CommandArgs commandArgs)
{
UpdateFundamentalsFinViz();
@@ -464,6 +467,102 @@ namespace MarketData.Services
await Task.FromResult(true);
}
/// <summary>
/// TaskLoadAllPricesSymbol - Load price from Yahoo for SYMBOL
/// </summary>
/// <param name="commandArgs"></param>
/// <returns></returns>
public async Task TaskLoadAllPricesSymbol(CommandArgs commandArgs)
{
MDTrace.WriteLine(LogLevel.DEBUG,ConsoleColor.Red,String.Format("Loading/Deleting prices can change the pricing of positions... please confirm Y/N:?"));
String result=Console.ReadLine();
if(null==result || !(result.ToUpper().Equals("Y") || result.ToUpper().Equals("YES")))
{
return;
}
if(!commandArgs.Has("SYMBOL"))
{
MDTrace.WriteLine(LogLevel.DEBUG,"LOADALLPRICESSYMBOL REQUIRES SYMBOL");
return;
}
String symbol = commandArgs.Coalesce<String>("SYMBOL").Trim().ToUpper();
if(String.IsNullOrEmpty(symbol))
{
MDTrace.WriteLine(LogLevel.DEBUG,"LOADALLPRICESSYMBOLDATE Invalid arguments, please try again.");
return;
}
DateTime startDate =Constants.MIN_PRICING_DATE;
DateTime endDate = DateTime.Now;
Prices prices=MarketDataHelper.GetDailyPrices(symbol,startDate,endDate); // use the Yahoo JSON bulk feed
if(null==prices||0==prices.Count)
{
if(!Utility.GetVerificationToProceed(String.Format("No prices from Yahoo for symbol{0}. Would you like to try BigCharts?",symbol)))
{
return;
}
}
if (null == prices || 0==prices.Count)
{
MDTrace.WriteLine(LogLevel.DEBUG,"No prices for '" + symbol + "'");
return;
}
for (int secIndex = 0; secIndex < prices.Count; secIndex++)
{
MDTrace.WriteLine(LogLevel.DEBUG,prices[secIndex].ToString());
}
MDTrace.WriteLine(LogLevel.DEBUG,"Inserting....");
PricingDA.InsertPrices(prices);
MDTrace.WriteLine(LogLevel.DEBUG,"Done.");
await Task.CompletedTask;
}
/// <summary>
/// TaskLoadAllPricesSymbolDate - Load price from Yahoo for SYMBOL and DATE
/// </summary>
/// <param name="commandArgs"></param>
/// <returns></returns>
public async Task TaskLoadPriceSymbolDate(CommandArgs commandArgs)
{
MDTrace.WriteLine(LogLevel.DEBUG,ConsoleColor.Red,String.Format("Loading/Deleting prices can change the pricing of positions... please confirm Y/N:?"));
String result=Console.ReadLine();
if(null==result || !(result.ToUpper().Equals("Y") || result.ToUpper().Equals("YES")))
{
return;
}
if(!commandArgs.Has("SYMBOL"))
{
MDTrace.WriteLine(LogLevel.DEBUG,"LOADALLPRICESSYMBOLDATE REQUIRES SYMBOL");
return;
}
if(!commandArgs.Has("DATE"))
{
MDTrace.WriteLine(LogLevel.DEBUG,"LOADALLPRICESSYMBOLDATE REQUIRES DATE");
return;
}
String symbol = commandArgs.Coalesce<String>("SYMBOL").Trim().ToUpper();
DateTime startDate = commandArgs.Coalesce<DateTime>("DATE");
if(String.IsNullOrEmpty(symbol) || Utility.IsEpoch(startDate))
{
MDTrace.WriteLine(LogLevel.DEBUG,"LOADALLPRICESSYMBOLDATE Invalid arguments, please try again.");
return;
}
Prices prices=MarketDataHelper.GetDailyPrices(symbol,startDate,startDate); // use the Yahoo JSON bulk feed
if (null == prices || 0==prices.Count)
{
MDTrace.WriteLine(LogLevel.DEBUG,"No prices for '" + symbol + "'");
return;
}
for (int secIndex = 0; secIndex < prices.Count; secIndex++)
{
MDTrace.WriteLine(LogLevel.DEBUG,prices[secIndex].ToString());
}
MDTrace.WriteLine(LogLevel.DEBUG,"Inserting....");
PricingDA.InsertPrices(prices);
MDTrace.WriteLine(LogLevel.DEBUG,"Done.");
await Task.CompletedTask;
}
// *********************************************************************************************************************************************************
// ******************************************************************* E N D T A S K S ********************************************************************
// *********************************************************************************************************************************************************

View File

@@ -5375,7 +5375,12 @@ namespace MarketData.Helper
//********************************************************************************************************************************************************************************************************
// ******************************************************************************** H I S T O R I C A L P R I C I N G Y A H O O *********************************************************************
//********************************************************************************************************************************************************************************************************
/// <summary>
/// GetDailyPrice - This feed returns a single price for the given pricing date.
/// </summary>
/// <param name="symbol"></param>
/// <param name="pricingDate"></param>
/// <returns></returns>
public static Price GetDailyPrice(String symbol, DateTime pricingDate)
{
if (null == symbol) return null;
@@ -5396,6 +5401,13 @@ namespace MarketData.Helper
return price;
}
/// <summary>
/// GetDailyPrices - Retrieve prices from Yahoo. This feed can retrieve historical prices from Yahoo as well as current day price
/// </summary>
/// <param name="symbol"></param>
/// <param name="startDate"></param>
/// <param name="endDate"></param>
/// <returns></returns>
public static Prices GetDailyPrices(String symbol, DateTime startDate, DateTime endDate)
{
HttpNetResponse httpNetResponse=null;

View File

@@ -130,6 +130,9 @@ public class MarketDataUnitTestClass
Assert.IsTrue(price.IsValid || !double.IsNaN(price.PrevClose), "The feed is not working.");
}
/// <summary>
/// DailyPricesYahoo - This test confirms if we are able to retrieve a current (last business day) price from Yahoo.
/// </summary>
[TestMethod]
public void DailyPricesYahoo()
{
@@ -146,26 +149,29 @@ public class MarketDataUnitTestClass
Assert.IsTrue(null != prices, "No Price from DailyPricesYahoo");
}
// [TestMethod]
// public void CNNPredictionTest()
// {
// String cnnHostName = "10.0.0.240";
// CMCandidate cmCandidate = new CMCandidate();
// CMParams cmParams = new CMParams();
/// <summary>
/// HistoricalPricesYahoo - This test confirms if we are able to retrieve historical dates from Yahoo
/// </summary>
[TestMethod]
public void HistoricalPricesYahoo()
{
String symbol = "AAPL";
DateGenerator dateGenerator = new DateGenerator();
DateTime lastBusinessDate = DateTime.Now;
DateTime historicalDate = Utility.Epoch;
// cmParams.UseCNN = true;
// cmParams.UseCNNHost = "http://" + cnnHostName + ":5000";
// cmParams.UseCNNDayCount = 270;
// cmParams.UseCNNRewardPercentDecimal = 0.25;
lastBusinessDate = dateGenerator.GetPrevBusinessDay(lastBusinessDate);
List<DateTime> historicalDates = dateGenerator.GenerateHistoricalDates(lastBusinessDate,30);
DateTime minDate = historicalDates.Min();
// cmCandidate.Symbol = "MIDD";
// cmCandidate.TradeDate = DateTime.Parse("07-01-2024");
// bool result = CMMomentumGenerator.PredictCandidate(cmCandidate, cmParams);
// Assert.IsTrue(result);
// }
Prices prices = MarketDataHelper.GetDailyPrices(symbol, lastBusinessDate, minDate);
Assert.IsTrue(null != prices, "No Price from DailyPricesYahoo");
Assert.IsTrue(prices.Count>1, "No Historical Prices from DailyPricesYahoo");
}
/// <summary>
/// CNNPredictionTest - This runs the Prediction using the CMMMomentumGenerator
/// </summary>
[TestMethod]
public void CNNPredictionTest()
{