Testing
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<StartArguments>UPDATEPRICES 08-21-2023</StartArguments>
|
||||
<StartArguments>RUNBACKTEST /STARTDATE:01-31-2018 /MAXPOSITIONS:3 /INITIALCASH:10000 /HOLDINGPERIOD:3 /INTRADAYMODE:FALSE /SESSIONFILE:MG20180131.TXT</StartArguments>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
Binary file not shown.
72
Program.cs
72
Program.cs
@@ -534,33 +534,36 @@ namespace MarketData
|
||||
// ****************************************************************** C U M U L A T I V E G A I N L O S S *************************************************************
|
||||
// ******************************************************************************************************************************************************************************
|
||||
// This is a test of a new model to calculate the cumulate gain loss for the GainLoss Window
|
||||
private static void RunModelPerformance()
|
||||
private static void RunModelPerformance(String symbol=null, bool useDividends=false)
|
||||
{
|
||||
GainLossGeneratorCum gainLossGeneratorCum=new GainLossGeneratorCum();
|
||||
GainLossGenerator gainLossGenerator=new GainLossGenerator();
|
||||
PortfolioTrades portfolioTrades=PortfolioDA.GetTrades();
|
||||
DividendPayments dividendPayments=null;
|
||||
|
||||
String strPathFileNameCumulative=String.Format("model_performance_dividends_cumulative_{0}.csv",null==symbol?"ALL":symbol);
|
||||
String strPathFileNameNonCumulative=String.Format("model_performance_dividends_non_cumulative_{0}.csv",null==symbol?"ALL":symbol);
|
||||
|
||||
String symbol="ANF"; // SPY
|
||||
portfolioTrades = PortfolioDA.GetTrades(symbol);
|
||||
if(null==symbol)portfolioTrades = PortfolioDA.GetTrades();
|
||||
else portfolioTrades = PortfolioDA.GetTrades(symbol);
|
||||
|
||||
// dividendPayments=DividendPaymentDA.GetDividendPayments();
|
||||
// portfolioTrades = new PortfolioTrades(portfolioTrades.Where(x => x.Symbol.Equals(symbol)).ToList());
|
||||
|
||||
String strPathFileNameCumulative=String.Format("model_performance_dividends_cumulative_{0}.csv",symbol);
|
||||
String strPathFileNameNonCumulative=String.Format("model_performance_dividends_non_cumulative_{0}.csv",symbol);
|
||||
if(useDividends)
|
||||
{
|
||||
if(null!=symbol)dividendPayments=DividendPaymentDA.GetDividendPaymentsForSymbol(symbol);
|
||||
else dividendPayments=DividendPaymentDA.GetDividendPayments();
|
||||
}
|
||||
|
||||
// Run the cumulative version
|
||||
TotalGainLossCollection totalGainLossCollectionCum=null;
|
||||
if(null!=dividendPayments)gainLossGeneratorCum.GenerateTotalGainLossWithDividends(portfolioTrades,dividendPayments);
|
||||
else gainLossGeneratorCum.GenerateTotalGainLoss(portfolioTrades);
|
||||
if(null!=dividendPayments)totalGainLossCollectionCum=gainLossGeneratorCum.GenerateTotalGainLossWithDividends(portfolioTrades,dividendPayments);
|
||||
else totalGainLossCollectionCum=gainLossGeneratorCum.GenerateTotalGainLoss(portfolioTrades);
|
||||
Console.WriteLine(String.Format("Writing Cumulative Model to {0}",strPathFileNameCumulative));
|
||||
SaveCollection(strPathFileNameCumulative, "CUMULATIVE", totalGainLossCollectionCum);
|
||||
|
||||
// Run the regular version
|
||||
TotalGainLossCollection totalGainLossCollection=null;
|
||||
if(null!=dividendPayments)gainLossGenerator.GenerateTotalGainLossWithDividends(portfolioTrades,dividendPayments);
|
||||
else gainLossGenerator.GenerateTotalGainLoss(portfolioTrades);
|
||||
if(null!=dividendPayments)totalGainLossCollection=gainLossGenerator.GenerateTotalGainLossWithDividends(portfolioTrades,dividendPayments);
|
||||
else totalGainLossCollection=gainLossGenerator.GenerateTotalGainLoss(portfolioTrades);
|
||||
Console.WriteLine(String.Format("Writing Non-Cumulative Model to {0}",strPathFileNameNonCumulative));
|
||||
SaveCollection(strPathFileNameNonCumulative, "NON-CUMULATIVE",totalGainLossCollection);
|
||||
}
|
||||
@@ -619,15 +622,15 @@ namespace MarketData
|
||||
Trace.Listeners.Add(new TextWriterTraceListener(strLogFile));
|
||||
DateTime currentDate=DateTime.Now;
|
||||
|
||||
RunModelPerformance();
|
||||
Console.ReadLine();
|
||||
return 0;
|
||||
//RunModelPerformance("SPY");
|
||||
//Console.ReadLine();
|
||||
//return 0;
|
||||
|
||||
|
||||
// Price price=MarketDataHelper.GetLatestPriceFidelity("AAPL");
|
||||
// Price price=MarketDataHelper.GetLatestPriceFidelity("AAPL");
|
||||
|
||||
|
||||
DateTime maxHolidayDate=HolidayDA.GetMaxHolidayDate();
|
||||
|
||||
DateTime maxHolidayDate =HolidayDA.GetMaxHolidayDate();
|
||||
if(currentDate>maxHolidayDate)
|
||||
{
|
||||
Console.WriteLine(String.Format("There are no holidays defined in the system. Add holidays for year {0} into marketholidays table",currentDate.Year));
|
||||
@@ -2242,9 +2245,10 @@ namespace MarketData
|
||||
{
|
||||
try
|
||||
{
|
||||
List<String> symbols = WatchListDA.GetWatchList(watchListName);
|
||||
PricingMarketDataHelper pricingMarketDataHelper=new PricingMarketDataHelper();
|
||||
pricingMarketDataHelper.UpdateLatestPrices(symbols);
|
||||
if(!CheckRunCriteria())return;
|
||||
List<String> symbols = WatchListDA.GetWatchList(watchListName);
|
||||
PricingMarketDataHelper pricingMarketDataHelper=new PricingMarketDataHelper();
|
||||
pricingMarketDataHelper.UpdateLatestPrices(symbols);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -2255,6 +2259,7 @@ namespace MarketData
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!CheckRunCriteria())return;
|
||||
PortfolioTrades portfolioTrades=PortfolioDA.GetOpenTrades();
|
||||
List<String> symbols=(from PortfolioTrade portfolioTrade in portfolioTrades select portfolioTrade.Symbol).Distinct().ToList();
|
||||
if(symbols.Any(x=>x.Equals("SPY")))symbols.Add("SH");
|
||||
@@ -3678,6 +3683,7 @@ namespace MarketData
|
||||
int sleepTime=2000;
|
||||
PremarketElements premarketElements=null;
|
||||
|
||||
if(!CheckRunCriteria())return;
|
||||
for(int retry=0;retry<retries && (null==premarketElements || 0==premarketElements.Count);retry++,Thread.Sleep(sleepTime))
|
||||
{
|
||||
premarketElements=MarketDataHelper.GetPremarketData();
|
||||
@@ -3694,8 +3700,32 @@ namespace MarketData
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckRunCriteria()
|
||||
{
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
DateTime currentDate = DateTime.Now;
|
||||
|
||||
if(!dateGenerator.IsMarketOpen(currentDate))
|
||||
{
|
||||
String description="";
|
||||
if(HolidayDA.IsMarketHoliday(currentDate)) description=HolidayDA.GetHolidayDescription(currentDate);
|
||||
else description=Utility.DayOfWeekToString(currentDate.DayOfWeek);
|
||||
Console.WriteLine(String.Format("Market is closed today {0} ({1}), please confirm Y/N:?",currentDate.ToShortDateString(),description));
|
||||
String result=Console.ReadLine();
|
||||
if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES"))) return false;
|
||||
}
|
||||
if(!NetworkStatus.IsInternetConnected())
|
||||
{
|
||||
Console.WriteLine(String.Format("The internet is not connected, continue anyway Y/N:?"));
|
||||
String result=Console.ReadLine();
|
||||
if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES")))return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void LoadHeadlinesWatchList(String watchList)
|
||||
{
|
||||
if(!CheckRunCriteria())return;
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("LoadHeadlinesWatchList {0}",watchList));
|
||||
List<String> symbols = WatchListDA.GetWatchList(watchList);
|
||||
HeadlinesMarketDataHelper headlinesMarketDataHelper= new HeadlinesMarketDataHelper();
|
||||
|
||||
Reference in New Issue
Block a user