using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Diagnostics; using System.Linq; using System.Threading; using System.Configuration; using MarketData.DataAccess; using MarketData.MarketDataModel; using MarketData.Generator; using MarketData.Generator.GainLoss; using MarketData.Helper; using MarketData.Utils; using MarketData.Numerical; using MarketData.ValueAtRisk; using MarketData.Integration; using MarketData.Generator.Momentum; using MarketData.Generator.CMMomentum; using MarketData.MarketDataModel.GainLoss; using MarketData.Cache; using MarketData.Generator.CMTrend; using Axiom.Interpreter; using System.Data; namespace MarketData { class Program { public static void DisplayUsage() { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("64BIT={0}",Utility.Is64Bit())); MDTrace.WriteLine(LogLevel.DEBUG,"usage {service}"); MDTrace.WriteLine(LogLevel.DEBUG,"****************** T E S T D A T A S O U R C E S E T C .,***************"); MDTrace.WriteLine(LogLevel.DEBUG," RUNTESTS - tests data sources."); MDTrace.WriteLine(LogLevel.DEBUG," RUNPRICECHECKOPENPOSITIONS - lists the latest available price for the open positions"); MDTrace.WriteLine(LogLevel.DEBUG," SENDSMSEMAIL {message} - sends an SMS email to system recipient"); MDTrace.WriteLine(LogLevel.DEBUG,"****************** D A I L Y U P D A T E ***************"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEDAILY - updates prices, yields, and ratings"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEDAILY2 /DATE: - updates prices, yields, and ratings"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEPRICESBIGCHARTS /DATE: - updates prices"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEDAILYPRICES /DATE: - updates prices BIGCHARTS/YAHOO"); MDTrace.WriteLine(LogLevel.DEBUG,"****************** M A S T E R U P D A T E ***************"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEALL - updates prices, loads balance sheet and income, loads fundamentals, loads historical"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEALLNOPRICES - loads balance sheet and income, loads fundamentals, loads historical"); MDTrace.WriteLine(LogLevel.DEBUG,"*************** U P D A T E O P T I O N S C H A I N S **************************"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEOPTIONSCHAINS - updates all options chains"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEOPTIONSCHAINSSYMBOL /SYMBOL: - updates all options chains for symbol"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEOPTIONSCHAINSSYMBOLS /SYMBOLS: - updates all options chains for symbols (i.e.) AAPL,MSFT"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEOPTIONSCHAINSWATCHLIST /WATCHLIST: - updates all options chains for symbols in watchlist"); MDTrace.WriteLine(LogLevel.DEBUG," DISPLAYAVAILABLEOPTIONS /DAYSOUT: /VERBOSE:[TRUE|FALSE] - displays options matching optimal criteria for covered calls"); MDTrace.WriteLine(LogLevel.DEBUG,"*************** U P D A T E C O M P A N Y P R O F I L E **************************"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATECOMPANYPROFILES - updates all profiles for all symbols"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATECOMPANYPROFILE /SYMBOL: - updates all profiles for symbol"); MDTrace.WriteLine(LogLevel.DEBUG," DISPLAYCOMPANYPROFILES - display market data profiles for all symbols"); MDTrace.WriteLine(LogLevel.DEBUG,"***************C E N T R A L I N D E X K E Y (Y A H O O F I N A N C E) **************************"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEALLCIK - updates all CIK for all symbols"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEALLMISSINGCIK - updates all missing CIK for all symbols"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATECIKSYMBOL /SYMBOL: - updates CIK for symbol"); MDTrace.WriteLine(LogLevel.DEBUG,"***************S E C F I L I N G S **************************"); MDTrace.WriteLine(LogLevel.DEBUG," GETSECFILINGSWATCHLIST /WATCHLIST: - get SEC filings for valuation"); MDTrace.WriteLine(LogLevel.DEBUG," GETSECFILINGSSYMBOL /SYMBOL: - get SEC filings for symbol"); MDTrace.WriteLine(LogLevel.DEBUG," GETSECFILINGSOPENPOSITIONS - get SEC filings for for open positions"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATESECFILINGS - updates SEC Filings for symbols already covered"); MDTrace.WriteLine(LogLevel.DEBUG,"***************P R I C E S (Y A H O O F I N A N C E) **************************"); MDTrace.WriteLine(LogLevel.DEBUG," CHECKPRICES : - looks for price gaps > 5 days, checks continuity of prices"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEMISSINGPRICES /DATE: - looks through database for missing prices for all securities and attempts to retrieve price. If date provided will use that date as starting point"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEMISSINGPRICESSYMBOL /SYMBOL: - update missing prices for symbol."); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEPRICEASOFSYMBOL /SYMBOL: /DATE: - updates price for given symbol for given date from BIGCHARTS"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEPRICEASOFSYMBOLYAHOO /SYMBOL: /DATE: - updates price for given symbol for given date from YAHOO"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEPRICESASOF /DATE: - updates prices for all symbols for given date"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATELATESTPRICEALL - brings prices current for all symbols in database"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATELATESTPRICESYMBOL /SYMBOL: - brings prices current for all symbols in database"); MDTrace.WriteLine(LogLevel.DEBUG," DELETELATESTPRICESYMBOL /SYMBOL: - removes latest price for the given symbol"); MDTrace.WriteLine(LogLevel.DEBUG," DELETEPRICE /SYMBOL: /DATE: - delete price for symbol on specified date"); MDTrace.WriteLine(LogLevel.DEBUG," DELETEPRICESASOF /DATE: - delete all price on specified date"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEPRICES - brings prices current for all symbols in database"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEPRICESDATE /DATE: - fetched prices for this date"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEPRICESSYMBOL /SYMBOL: - brings prices current for specified symbol"); MDTrace.WriteLine(LogLevel.DEBUG," LOADALLPRICESSYMBOL /SYMBOL: - reloads all prices for specified symbol from 01-01-2009"); MDTrace.WriteLine(LogLevel.DEBUG," SHOWALLPRICESSYMBOL /SYMBOL: - shows all prices for specified symbol from 01-01-2009"); MDTrace.WriteLine(LogLevel.DEBUG," LOADALLPRICESSYMBOLDATE /SYMBOL: /DATE:{optional} - reloads all prices for specified symbol from DATE"); MDTrace.WriteLine(LogLevel.DEBUG," LOADALLPRICESWATCHLIST /WATCHLIST: - reloads all prices for watchlist from 01-01-2009"); MDTrace.WriteLine(LogLevel.DEBUG," ADDPRICE /SYMBOL: /DATE: /TYPE:[OPEN][HIGH][LOW][CLOSE][VOLUME] - updates symbol with price for specified date"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATELATESTPRICEWATCHLIST /WATCHLIST- updates database with latest price for the symbols in the watchlist"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATELATESTPRICEOPENPOSITIONS - updates database with latest price for the symbols in open positions"); MDTrace.WriteLine(LogLevel.DEBUG," DELETEPRICEWATCHLIST /WATCHLIST: /DATE: - deletes prices for symbols in the watchlist for the specified date"); MDTrace.WriteLine(LogLevel.DEBUG," FINDALLSYMBOLSMISSINGPRICEON /DATE: /ROLLFORWARD:{true}{false} /FILTER:{symbol} - find all symbols that are missing a price on this date. If ROLLFORWARD then roll forward missing price from prior business day (if one found). if FILTER then apply filter to rollforward "); MDTrace.WriteLine(LogLevel.DEBUG," ROLLPRICEFORWARD /SYMBOL: /FROMDATE: /TODATE: Roll price forward from the given date to the specified date."); MDTrace.WriteLine(LogLevel.DEBUG,"*************************************I N S I D E R T R A N S A C T I O N S**********************************"); MDTrace.WriteLine(LogLevel.DEBUG," LOADINSIDERTRANSACTIONSSYMBOL /SYMBOL:"); MDTrace.WriteLine(LogLevel.DEBUG," LOADINSIDERTRANSACTIONS"); MDTrace.WriteLine(LogLevel.DEBUG," LOADINSIDERTRANSACTIONSWATCHLISTS"); MDTrace.WriteLine(LogLevel.DEBUG,"*******B A L A N C E S H E E T A N D I N C O M E (Y A H O O F I N A N C E)*****"); MDTrace.WriteLine(LogLevel.DEBUG," LOADFINANCIALSTATEMENTSSYMBOL /SYMBOL: - load balance sheet, income statement, and cashflow statement for symbol"); MDTrace.WriteLine(LogLevel.DEBUG," LOADFINANCIALSTATEMENTS - load balance sheet, income statement, and cashflow statement for all"); MDTrace.WriteLine(LogLevel.DEBUG,"*********F U N D A M E N T A L D A T A (Y A H O O F I N A N C E - S U M M A R Y)***************"); MDTrace.WriteLine(LogLevel.DEBUG," LOADFUNDAMENTAL /SYMBOL:"); MDTrace.WriteLine(LogLevel.DEBUG," LOADFUNDAMENTALS"); MDTrace.WriteLine(LogLevel.DEBUG," LOADFUNDAMENTALSFINVIZ"); MDTrace.WriteLine(LogLevel.DEBUG," LOADFUNDAMENTALFINVIZ /SYMBOL"); MDTrace.WriteLine(LogLevel.DEBUG,"*********H I S T O R I C A D A T A (M O R N I N G S T A R )***************"); MDTrace.WriteLine(LogLevel.DEBUG," LOADHISTORICAL"); MDTrace.WriteLine(LogLevel.DEBUG," LOADHISTORICALSYMBOL /SYMBOL:"); MDTrace.WriteLine(LogLevel.DEBUG,"*******E C O N O M I C I N D I C A T O R S (W O R L D B A N K ), H E A D L I N E S, M A R K E T I N D I C A T O R S *****"); MDTrace.WriteLine(LogLevel.DEBUG," LOADGDP - loads annual gdp per capita data from world bank"); MDTrace.WriteLine(LogLevel.DEBUG," LOADHEADLINESWATCHLIST /WATCHLIST: - loads headlines for the specified watchlist"); MDTrace.WriteLine(LogLevel.DEBUG," LOADHEADLINESSYMBOL /SYMBOL: - loads headlines for the specified symbol"); MDTrace.WriteLine(LogLevel.DEBUG," LOADPREMARKETDATA loads pre-market data from CNN (i.e.) S&P Futures, DOW, NASDAQ"); MDTrace.WriteLine(LogLevel.DEBUG,"********A N A L Y S I S *********************************"); MDTrace.WriteLine(LogLevel.DEBUG," CALCDCF - calculate discounted cashflows"); MDTrace.WriteLine(LogLevel.DEBUG," CALCSTICKERSYMBOL - calculate sticker price for symbol"); MDTrace.WriteLine(LogLevel.DEBUG," CALCSTICKER - calculate main valuation (sticker price) and store to database"); MDTrace.WriteLine(LogLevel.DEBUG," CALCACQUIRERSMULTIPLE - calculate and display acquirers multiple"); MDTrace.WriteLine(LogLevel.DEBUG," CALCACQUIRERSMULTIPLESYMBOL /SYMBOL: - calculate and display acquirers multiple for symbol"); MDTrace.WriteLine(LogLevel.DEBUG," CALCTLBRANKS - calculate TLBRanks (ROIC & ROC) and display"); MDTrace.WriteLine(LogLevel.DEBUG," CALCSTICKERETF /SYMBOL: - calculate sticker price for all holdings in ETF"); MDTrace.WriteLine(LogLevel.DEBUG," FINDETFMOS - look for ETFs with all holdings within Sticker MOS"); MDTrace.WriteLine(LogLevel.DEBUG," CALCBETA /SYMBOL: /DAYCOUNT: - calculate beta for symbol over daycount"); MDTrace.WriteLine(LogLevel.DEBUG," CALCBETAALL /DAYCOUNT: - calculate beta for all symbols over daycount"); MDTrace.WriteLine(LogLevel.DEBUG," CALCPORTFOLIOBETA /ACCOUNT: - calculate beta for the portfolio or given account"); MDTrace.WriteLine(LogLevel.DEBUG," MAXDIVMINVAR /ANALYSISDATE: /DAYCOUNT: /PERCENTOFEXPOSURE: /EXPOSURE: - picks holdings to add to portfolio which maximize dividends while minimizing VaR"); MDTrace.WriteLine(LogLevel.DEBUG,"**************************** S T O C H A S T I C S**************"); MDTrace.WriteLine(LogLevel.DEBUG," RUNSTOCHASTICSSYMBOL /SYMBOL: runs stochastics signal generator"); MDTrace.WriteLine(LogLevel.DEBUG," RUNSTOCHASTICSSIGNALSYMBOL /SYMBOL: runs stochastics signal generator"); MDTrace.WriteLine(LogLevel.DEBUG,"*********** S W I N G T R A D E A N A L Y S I S **************"); MDTrace.WriteLine(LogLevel.DEBUG," FINDSWINGTRADESSYMBOL /SYMBOL: /DAYCOUNT:"); MDTrace.WriteLine(LogLevel.DEBUG," FINDCURRENTSWINGTRADES"); MDTrace.WriteLine(LogLevel.DEBUG," FINDCURRENTSWINGTRADESBARGAIN"); MDTrace.WriteLine(LogLevel.DEBUG,"*********** M A C D A N D T R A D E A N A L Y S I S **************"); MDTrace.WriteLine(LogLevel.DEBUG," RUNPIVOTS /SYMBOL: /DAYCOUNT:"); MDTrace.WriteLine(LogLevel.DEBUG," RUNMACDSIGNALSYMBOL /SYMBOL: /MACD:[X,Y,Z] (i.e.)(8,17,9) - runs the specified symbol and MACD through the signal generator"); MDTrace.WriteLine(LogLevel.DEBUG," GENERATEMOVINGAVERAGESHEET /STRPATHTEMPLATE: /SYMBOL: - generates 55 day, 21 day, 5 day MA against price."); MDTrace.WriteLine(LogLevel.DEBUG," GENERATESTOCHASTICS /SYMBOL: /DAYCOUNT: /PERIOD-N:[9] /PERIOD-K:[3]"); MDTrace.WriteLine(LogLevel.DEBUG," GENERATESTOCHASTICSSHEET /STRPATHTEMPLATE: /SYMBOL: /DAYCOUNT:[180] /PERIOD-N:[9] /PERIOD-K:[3]"); MDTrace.WriteLine(LogLevel.DEBUG," GENERATEBOLLINGERBANDS /SYMBOL: /MOVINGAVERAGEDAYS:[20] /HISTORICALDAYS:[180]"); MDTrace.WriteLine(LogLevel.DEBUG," GENERATEBOLLINGERBANDSHEET /STRPATHTEMPLATE: /SYMBOL: /MOVINGAVERAGEDAYS:[20] /HISTORICALDAYS:[180]"); MDTrace.WriteLine(LogLevel.DEBUG," TRADESYMBOL /SYMBOL: /SHARES: /STARTDATE: /HOLDINGDAYS - simulate a historical trade."); MDTrace.WriteLine(LogLevel.DEBUG,"*********** G A I N L O S S **************"); MDTrace.WriteLine(LogLevel.DEBUG," SHOWACTIVEGAINLOSS"); MDTrace.WriteLine(LogLevel.DEBUG,"*********** Y I E L D C U R V E **************"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEYIELDCURVE"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEYIELDCURVEHIST /YEARS:"); MDTrace.WriteLine(LogLevel.DEBUG,"*********** E A R N I N G S A N N O U N C E M E N T **************"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEEARNINGSANNOUNCEMENTS"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEEARNINGSANNOUNCEMENTSSYMBOL /SYMBOL:"); MDTrace.WriteLine(LogLevel.DEBUG,"*********** D I V I D E N D H I S T O R Y **************"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEDIVIDENDHISTORY "); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEDIVIDENDHISTORYSYMBOL /SYMBOL:"); MDTrace.WriteLine(LogLevel.DEBUG, "*********** A N A L Y S T R A T I N G S **************"); MDTrace.WriteLine(LogLevel.DEBUG, " UPDATELATESTANALYSTRATINGS /CREATESECURITYMASTER:{TRUE|FALSE}"); MDTrace.WriteLine(LogLevel.DEBUG, " UPDATEMISSINGANALYSTRATINGS"); MDTrace.WriteLine(LogLevel.DEBUG, " UPDATEANALYSTRATINGS /SYMBOL: /MINDATE:"); MDTrace.WriteLine(LogLevel.DEBUG, " UPDATEANALYSTPRICETARGET"); MDTrace.WriteLine(LogLevel.DEBUG,"*********** M I S C E L L A N E O U S **************"); MDTrace.WriteLine(LogLevel.DEBUG," GETETFHOLDINGS"); MDTrace.WriteLine(LogLevel.DEBUG," GETETFHOLDINGSSYMBOL /SYMBOL:"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEZACKSRANK"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATEZACKSRANKSYMBOL /SYMBOL:"); MDTrace.WriteLine(LogLevel.DEBUG,"*********** S P L I T S **************"); MDTrace.WriteLine(LogLevel.DEBUG," UPDATESPLITS gets splits from market feed"); MDTrace.WriteLine(LogLevel.DEBUG," PROCESSSPLIT /SYMBOL: updates the pricing data for the secified split in the splits table"); MDTrace.WriteLine(LogLevel.DEBUG," PROCESSALLSPLITS updates the pricing data for all of the splits in the splits table"); MDTrace.WriteLine(LogLevel.DEBUG, "*********** V A L U E A T R I S K **************"); MDTrace.WriteLine(LogLevel.DEBUG," GETVAR /DAYCOUNT: /CONFIDENCE: /RETURNDAYS: (i.e.) GETVAR 30 95 1 "); MDTrace.WriteLine(LogLevel.DEBUG," GETOPTIMALPOSITIONFROMWATCHLIST /WATCHLIST: /MARKETVALUE: /DAYCOUNT: /CONFIDENCE: /RETURNDAYS: (i.e.) GETOPTIMALPOSITIONFROMWATCHLIST Valuations 10000 90 95 1"); MDTrace.WriteLine(LogLevel.DEBUG,"*********** C O E F F I C I E N T S ************"); MDTrace.WriteLine(LogLevel.DEBUG," FINDCOEFFICIENTS /SYMBOL: /DAYCOUNT: /STARTDATE:"); MDTrace.WriteLine(LogLevel.DEBUG, " DISPLAYVOLATILITY /SYMBOLS: /DAYCOUNT: {/STARTDATE:}"); MDTrace.WriteLine(LogLevel.DEBUG, " DISPLAYSHARPERATIO /SYMBOLS: {/MONTHS:} {/STARTDATE:}"); MDTrace.WriteLine(LogLevel.DEBUG,"*********** (C M T R E N D ) M O M E N T U M G E N E R A T I O N (M A R C M I N E R V I N I & V A N T H A R P E - C A N D I D A T E S E L E C T I O N B Y A N D R E A S C L E N O W ) ************"); MDTrace.WriteLine(LogLevel.DEBUG," RUNCMTREND /MODE:DAILY|BACKTEST|RUNTRENDTEMPLATE|ENTRYTEST /SYMBOL:{for mode ANALYZE,ENTRYTEST} /TRADEDATE:{for mode DAILY,RUNTRENDTEMPLATE) /STARTDATE:(for mode BACKTEST,ENTRYTEST) /ENDDATE:(for mode BACKTEST) /INITIALCASH: /SESSIONFILE: /MAXOPENPOSITIONS: /MAXDAILYPOSITIONS: Runs Mark Minervini trend"); MDTrace.WriteLine(LogLevel.DEBUG," VALID ARGUMENTS FOR /MODE:BACKTEST ARE /SELLATENDOFSIMULATION: /STARTDATE: /ENDDATE: /SESSIONFILE: /MAXDAILYPOSITIONS: /MAXOPENPOSITIONS: /BENCHMARKMOVINGAVERAGEDAYS: /BENCHMARKMOVINGAVERAGEHORIZON"); MDTrace.WriteLine(LogLevel.DEBUG," VALID ARGUMENTS FOR /MODE:BACKTEST CONTD., /POSITIONRISKPERCENTDECIMAL: /ENTRYTYPE:OverExtended,MVP,PriceTrend,VolumeTrend,RVOL /USEPROFITMAXIMIZATION:{TRUE|FALSE} /USEPROFITMAXIMIZATIONEXPRESSION:{string}"); MDTrace.WriteLine(LogLevel.DEBUG," VALID ARGUMENTS FOR /MODE:BACKTEST CONTD., /POSITIONRISKPERCENTDECIMAL: /ENTRYTYPE:OverExtended,MVP,PriceTrend,VolumeTrend,RVOL /USEPROFITMAXIMIZATION:TRUE /USEPROFITMAXIMIZATIONEXPRESSION:\"R_THRESSHOLD=4;MAX_ATR=3;MAX_R=10;FACTOR=MAX_ATR/MAX_R;MULTIPLIER=MAX_ATR;IF(RMultiple>R_THRESSHOLD){MULTIPLIER=FACTOR*RMultiple;}\""); MDTrace.WriteLine(LogLevel.DEBUG," VALID ARGUMENTS FOR /MODE:BACKTEST CONTD., /USEPOSITIONSIZINGSTRATEGY:{TRUE|FALSE} /USEPOSITIONSIZINGSTRATEGYSTRATEGY:{TotalRisk:EqualWeight,Formula} /USEPOSITIONSIZINGSTRATEGYFORMULA:{Formula}"); MDTrace.WriteLine(LogLevel.DEBUG," VALID ARGUMENTS FOR /MODE:BACKTEST CONTD., /USETRADEONLYSECTORS:{TRUE|FALSE} /USETRADEONLYSECTORSSECTORS:Healthcare,Technology,Basic Materials,Consumer Defensive,Industrials"); MDTrace.WriteLine(LogLevel.DEBUG," /BENCHMARKMOVINGAVERAGEDAYS: (i.e.) 200, 100, 55"); MDTrace.WriteLine(LogLevel.DEBUG," /BENCHMARKMOVINGAVERAGEHORIZON: (i.e.) 5"); MDTrace.WriteLine(LogLevel.DEBUG," CMTSESSION /SESSIONFILE:{pathfilename} "); MDTrace.WriteLine(LogLevel.DEBUG,"*********** M G M O M E N T U M (Q U A N T U M M O M E N T U M )************"); MDTrace.WriteLine(LogLevel.DEBUG," MGSESSION /SESSIONFILE:"); MDTrace.WriteLine(LogLevel.DEBUG,@" MGGAINLOSS /SESSIONFILE:{PATHSESSIONFILE} (i.e.) MGGAINLOSS /SESSIONFILE:C:\boneyard\marketdata\bin\Debug\saferun\MG20180131.txt"); MDTrace.WriteLine(LogLevel.DEBUG," MGLIQUIDATE /SESSIONFILE: /TRADEDATE: sells all positions in the session file with either the supplied tradedate or latestpricingdate if trade date omitted."); MDTrace.WriteLine(LogLevel.DEBUG," MGCLOSEPOSITION /SESSIONFILE: /SYMBOL: /PURCHASEDATE: /SELLPRICE: /SELLDATE: sells the specified position in the session file with either the supplied sell date and sell price."); MDTrace.WriteLine(LogLevel.DEBUG," MGUPDATEPRICE /SYMBOL: /TRADEDATE: /PRICE: /SESSIONFILE:"); MDTrace.WriteLine(LogLevel.DEBUG," RUNBACKTEST /STARTDATE: /MAXPOSITIONS: /INITIALCASH: /HOLDINGPERIOD: /{ENDDATE}: /SESSIONFILE: {/RISKALLOCATION:NONE/SHARPERATIO}"); MDTrace.WriteLine(LogLevel.DEBUG, "*********** C L E N O W M O M E N T U M (C M M O M E N T U M )************"); MDTrace.WriteLine(LogLevel.DEBUG, " RUNCMBACKTEST /STARTDATE: /MAXPOSITIONS: /INITIALCASH: /HOLDINGPERIOD: /{USEBINBASEDPOSITIONSIZING}: /{USEBINBASEDPOSITIONSIZINGNUMBINS}: /{TARGETBETA}: /{ENDDATE}: /SESSIONFILE: /{USECNN}: /{USECNNHOST}: /{USECNNDAYCOUNT}:"); MDTrace.WriteLine(LogLevel.DEBUG, " CMSESSION /SESSIONFILE:"); MDTrace.WriteLine(LogLevel.DEBUG, " CMCANDIDATELASTRESORT /TRADEDATE:"); MDTrace.WriteLine(LogLevel.DEBUG, @" CMGAINLOSS /SESSIONFILE:{PATHSESSIONFILE} (i.e.) CMGAINLOSS /SESSIONFILE:C:\boneyard\marketdata\bin\Debug\saferun\CM20191031.txt"); } // *************************************************************************************************************************************************************************** public class Candidate { public Candidate(String symbol,String companyName,double dividendYieldPcnt,double portfolioVaRPcnt,double dividendLoadPcnt,String sector,String industry) { Symbol=symbol; CompanyName=companyName; DividendYieldPcnt=dividendYieldPcnt; PortfolioVaRPcnt=portfolioVaRPcnt; DividendLoadPcnt=dividendLoadPcnt; Sector=sector; Industry=industry; } public String Symbol{get;set;} public String CompanyName{get;set;} public double DividendYieldPcnt{get;set;} public double PortfolioVaRPcnt{get;set;} public double DividendLoadPcnt{get;set;} public String Sector{get;set;} public String Industry{get;set;} } private static void MaximizeDividendMinimizeVaR(int dayCount=180,double exposure=double.NaN,double percentOfExposure=5.00/100.00,double varConfidence=95.00) { String pathOutput="maxdivminvar.csv"; List candidates=new List(); DateGenerator dateGenerator=new DateGenerator(); double investment=double.NaN; if(double.IsNaN(percentOfExposure))percentOfExposure=5.00/100.00; else percentOfExposure/=100.00; if(double.IsNaN(varConfidence))varConfidence=95.00; FileStream outStream=new FileStream(pathOutput,FileMode.Create); StreamWriter streamWriter=new StreamWriter(outStream); streamWriter.WriteLine("Symbol,Company,DividendYieldPcnt,PortfolioVaRPcnt,DividendLoadPcnt,Sector,Industry"); PortfolioTrades portfolioTrades=PortfolioDA.GetOpenTrades(); if(!double.IsNaN(exposure))investment=exposure; else investment=portfolioTrades.Exposure()*percentOfExposure; DateTime lastBusinessDate=dateGenerator.FindPrevBusinessDay(DateTime.Now); DateTime historicalDate=dateGenerator.GenerateHistoricalDate(lastBusinessDate,dayCount); Console.WriteLine(String.Format("MAXDIVMINVAR")); Console.WriteLine(String.Format("LASTBUSINESSDATE:{0}",lastBusinessDate.ToShortDateString())); Console.WriteLine(String.Format("HISTROICALDATE:{0}",historicalDate.ToShortDateString())); Console.WriteLine(String.Format("DAYCOUNT:{0}",dayCount)); Console.WriteLine(String.Format("INVESTMENT:{0}",investment)); Console.WriteLine(String.Format("CONFIDENCE:{0}",varConfidence)); Console.WriteLine(String.Format("OUTPUT:{0}",pathOutput)); List symbols=PricingDA.GetSymbols(); foreach(String symbol in symbols) { double dividendLoadPcnt=double.NaN; String sector=""; String industry=""; String companyName=""; portfolioTrades=PortfolioDA.GetOpenTrades(); List portfolioSymbols=portfolioTrades.Symbols; // if(portfolioSymbols.Any(x=>x.Equals(symbol)))continue; // Historical price check Price historicalPrice=PricingDA.GetPrice(symbol,historicalDate); if(null==historicalPrice)continue; Price currentPrice=PricingDA.GetPrice(symbol); if(null==currentPrice)continue; if(currentPrice.Close<5.00)continue; // Volume check Prices shortTermPrices=PricingDA.GetPrices(symbol,14); if(null==shortTermPrices||shortTermPrices.Count<14)continue; float[] volume=shortTermPrices.GetVolume(); double averageVolume=Numerics.Mean(ref volume); if(averageVolume<500000)continue; // Fundamental check Fundamental fundamental=FundamentalDA.GetFundamental(symbol); if(null==fundamental)continue; if(fundamental.EPS<0)continue; if(fundamental.MarketCap<500000000)continue; // Dividend Yield check double dividendYield=DividendHistoryGenerator.GetDividendYield(symbol,currentPrice); if(double.IsNaN(dividendYield))continue; DividendHistory dividendHistory=DividendHistoryDA.GetDividendHistory(symbol); if(dividendHistory.Count<8)continue; // Company Profile info CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol); if(null!=companyProfile) { if(null!=companyProfile.Sector)sector=companyProfile.Sector; if(null!=companyProfile.Industry)industry=companyProfile.Industry; if(null!=companyProfile.CompanyName)companyName=companyProfile.CompanyName; } if(sector.Equals("Financial Services")||sector.Equals("Capital Markets")||sector.Equals("Savings & Cooperative Banks")||sector.Equals("Banks - Regional - US"))continue; // Analyst Ratings check AnalystRatings analystRatings=AnalystRatingsDA.GetAnalystRatings(symbol); if(null==analystRatings||0==analystRatings.Count)continue; analystRatings=new AnalystRatings(analystRatings.Take(5).ToList()); if(analystRatings.Any(x=>x.RatingsChange.ToUpper().Contains("SELL")))continue; //if(analystRatings.Any(x=>x.Type.ToUpper().Contains("DOWNGRADE")))continue; // Dividend Load check DividendLoadCollection dividendLoadCollection=CompositeDA.GetDividendLoad(symbol); if(null!=dividendLoadCollection&&0!=dividendLoadCollection.Count) { DividendLoadCollection element=new DividendLoadCollection(dividendLoadCollection.Take(1).ToList()); if(element[0].DividendLoadPcnt>65 || element[0].DividendLoadPcnt<0)continue; dividendLoadPcnt=element[0].DividendLoadPcnt; } Console.WriteLine(String.Format("Working on {0}",symbol)); PortfolioTrade portfolioTrade=new PortfolioTrade(); portfolioTrade.Symbol=symbol; portfolioTrade.TradeDate=historicalDate; portfolioTrade.Shares=investment/historicalPrice.Close; portfolioTrade.Price=historicalPrice.Close; portfolioTrade.BuySell="BUY"; portfolioTrade.Status="OPEN"; portfolioTrades.Add(portfolioTrade); PortfolioHoldings portfolioHoldings = PortfolioHoldings.GetPortfolioHoldings(portfolioTrades, dayCount,lastBusinessDate); VaRResult varResult = HistoricalVaR.GetVaR(portfolioHoldings, varConfidence); if(!varResult.Success)continue; candidates.Add(new Candidate(symbol,companyName,dividendYield*100.00,Math.Abs(varResult.VaRPercent)*100.00,dividendLoadPcnt,sector,industry)); } candidates=(from Candidate candidate in candidates orderby candidate.DividendYieldPcnt descending, candidate.PortfolioVaRPcnt ascending select candidate).ToList(); foreach(Candidate candidate in candidates) { streamWriter.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6}",candidate.Symbol,candidate.CompanyName,candidate.DividendYieldPcnt,candidate.PortfolioVaRPcnt,candidate.DividendLoadPcnt,candidate.Sector,candidate.Industry)); } streamWriter.Flush(); streamWriter.Close(); streamWriter.Dispose(); Console.WriteLine(String.Format("output written to :{0}",pathOutput)); } public static void ShowActiveGainLoss() { try { MDTrace.WriteLine(LogLevel.DEBUG,"SHOWACTIVEGAINLOSS"); Dictionary gainLossElements=new Dictionary(); GainLossCollection gainLossCollection=null; PortfolioTrades portfolioTrades=PortfolioDA.GetTrades(); IActiveGainLossGenerator activeReturnGenerator=new ActiveGainLossGenerator(); gainLossCollection=activeReturnGenerator.GenerateGainLoss(portfolioTrades); MDTrace.WriteLine("Date,Exposure,GainLoss,GainLossPercent,Dividends"); for(int index=0;index=5){user_a=1;user_b=1;user_c=1;}"); // sb.Append("MAX_ATR=3;MAX_R=10;FACTOR=0;MULTIPLIER=0;FACTOR=MAX_ATR/MAX_R;MULTIPLIER=MAX_ATR;IF(RMultiple>4){MULTIPLIER=FACTOR*RMultiple;}"); // sb.Append("R_THRESSHOLD=4;MAX_ATR=3;MAX_R=10;FACTOR=MAX_ATR/MAX_R;MULTIPLIER=MAX_ATR;IF(RMultiple>R_THRESSHOLD){MULTIPLIER=FACTOR*RMultiple;}"); String expression=@" R_THRESHHOLD=4; MAX_ATR=3; MAX_R=10; FACTOR=MAX_ATR/MAX_R; MULTIPLIER=MAX_ATR; IF(RMultiple>R_THRESHHOLD) { MULTIPLIER=FACTOR*RMultiple; }"; CodeRunner codeRunner=new CodeRunner(); SymbolTable symbolTable=codeRunner.SymbolTable; symbolTable.AddObjects(new Object[]{position,cmtParams,profitExpression}.ToList()); // inject objects into symbol table. SymbolTable gets populated using "get_"ers codeRunner.Execute(expression); // run the expression double multiplier=codeRunner.GetValue("MULTIPLIER"); // get the result Console.WriteLine(codeRunner.LastMessage); } // public static void Test() // { // DateGenerator dateGenerator=new DateGenerator(); // DateTime startDate=DateTime.Parse("01-02-2018"); // DateTime endDate=DateTime.Parse("06-01-2023"); // DateTime currentDate=startDate; // int dayIncrement=90; // int dayCount=90; // currentDate=dateGenerator.GetPrevQuarterStartDate(startDate); // while(currentDate tradeableDates=new Dictionary(); Dictionary nonTradeableDates=new Dictionary(); DateGenerator dateGenerator=new DateGenerator(); DateTime currentDate=startDate; int tradeableDays=0; int nonTradeableDays=0; int dayCount=90; while(currentDate nonTradeableDatesList=new List(nonTradeableDates.Keys); nonTradeableDatesList.Sort((a,b) => a.CompareTo(b)); foreach(DateTime date in nonTradeableDatesList) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("{0}",date.ToShortDateString())); } Console.WriteLine(String.Format("TradeableDays:{0} Non-TradeableDays:{1}",tradeableDays,nonTradeableDays)); } public static bool IsIncreasingRate(DateTime effectiveDate,int dayCount,YieldCurve.CurveType curveType=YieldCurve.CurveType.Yr1) { DateGenerator dateGenerator=new DateGenerator(); DateTime quarterStartDate=dateGenerator.GetPrevQuarterStartDate(effectiveDate); YieldCurve yieldCurve = YieldCurveDA.GetYieldCurve(quarterStartDate, dayCount); double[] yieldCurveData = yieldCurve.GetYieldCurveDataOrderByDateDescending(YieldCurve.CurveType.Yr1); for(int index=0;index1.00)return true; return false; } // Last added was 2023 - beware the SPAC "Industry=Shell Companies" public static void InsertIPOS() { // paste the symbol and company name's here string[,] ipos={ //{"KVAC","Keen Vision Acquisition Corporation"} }; int items=ipos.Length/2; for(int index=0;index validSectors=Utility.ToList(sessionParams.CMTParams.UseTradeOnlySectorsSectors); // List candidatesToRemove=new List(); // foreach(CMTCandidate candidate in sessionParams.Candidates) // { // CompanyProfile companyProfile = CompanyProfileDA.GetCompanyProfile(candidate.Symbol); // if(null==companyProfile) // { // Console.WriteLine(String.Format("No company profile for {0}",candidate.Symbol)); // candidatesToRemove.Add(candidate); // } // if(!validSectors.Any(x => x.Equals(companyProfile.Sector))) // { // Console.WriteLine(String.Format("Candidate{0} is in an invalid sector. Found {1} expected one of {2}",candidate.Symbol,companyProfile.Sector,Utility.ListToString(validSectors.ToList()))); // candidatesToRemove.Add(candidate); // } // } // sessionParams.Candidates = new CMTCandidates(sessionParams.Candidates.Except(candidatesToRemove).ToList()); // CMTSessionManager.SaveSession(sessionParams,@"C:\boneyard\marketdata\bin\Debug\CMT20200817.txt"); //} // ****************************************************************************************************************************************************************************************** // ****************************************************************************************************************************************************************************************** // **********************************************************************************************************************************************.ToString()******************************************** // ********************************************************************************************************** static int Main(string[] args) { try { MDTrace.LogLevel = LogLevel.DEBUG; String strLogFile = "marketdata.log"; Utility.DeleteFile(strLogFile); Trace.Listeners.Add(new TextWriterTraceListener(strLogFile)); DateTime currentDate=DateTime.Now; //SECFilings secFilings=new SECFilings(); //SECFiling secFiling = new SECFiling(); //secFiling.Symbol="UFPT"; //secFiling.SECAccessionNumber="0001062993-24-002532"; //secFiling.FormText="SEC FORM 4SEC Form 4
FORM 4UNITED STATES SECURITIES AND EXCHANGE COMMISSION
Washington, D.C. 20549

STATEMENT OF CHANGES IN BENEFICIAL OWNERSHIP

Filed pursuant to Section 16(a) of the Securities Exchange Act of 1934
or Section 30(h) of the Investment Company Act of 1940
OMB APPROVAL
OMB Number:3235-0287
Estimated average burden
hours per response:0.5
????
Check this box if no longer subject to Section 16. Form 4 or Form 5 obligations may continue. See Instruction 1(b).
????
Check this box to indicate that a transaction was made pursuant to a contract, instruction or written plan for the purchase or sale of equity securities of the issuer that is intended to satisfy the affirmative defense conditions of Rule 10b5-1(c). See Instruction 10.
1. Name and Address of Reporting Person*
Holt Jason

(Last)(First)(Middle)
C/O UFP TECHNOLOGIES, INC.
100 HALE STREET

(Street)
NEWBURYPORTMA01950

(City)(State)(Zip)
2. Issuer Name and Ticker or Trading Symbol
UFP TECHNOLOGIES INC [ UFPT ]
5. Relationship of Reporting Person(s) to Issuer
(Check all applicable)
Director10% Owner
XOfficer (give title below)Other (specify below)
Vice President
3. Date of Earliest Transaction (Month/Day/Year)
02/06/2024
4. If Amendment, Date of Original Filed (Month/Day/Year)
6. Individual or Joint/Group Filing (Check Applicable Line)
XForm filed by One Reporting Person
Form filed by More than One Reporting Person
Table I - Non-Derivative Securities Acquired, Disposed of, or Beneficially Owned
1. Title of Security (Instr. 3) 2. Transaction Date (Month/Day/Year)2A. Deemed Execution Date, if any (Month/Day/Year)3. Transaction Code (Instr. 8) 4. Securities Acquired (A) or Disposed Of (D) (Instr. 3, 4 and 5) 5. Amount of Securities Beneficially Owned Following Reported Transaction(s) (Instr. 3 and 4) 6. Ownership Form: Direct (D) or Indirect (I) (Instr. 4) 7. Nature of Indirect Beneficial Ownership (Instr. 4)
CodeVAmount(A) or (D)Price
Common Stock, $.01 Par Value02/06/2024A807(1)A$06,932D
Common Stock, $.01 Par Value02/06/2024A584(2)A$07,516D
Table II - Derivative Securities Acquired, Disposed of, or Beneficially Owned
(e.g., puts, calls, warrants, options, convertible securities)
1. Title of Derivative Security (Instr. 3) 2. Conversion or Exercise Price of Derivative Security 3. Transaction Date (Month/Day/Year)3A. Deemed Execution Date, if any (Month/Day/Year)4. Transaction Code (Instr. 8) 5. Number of Derivative Securities Acquired (A) or Disposed of (D) (Instr. 3, 4 and 5) 6. Date Exercisable and Expiration Date (Month/Day/Year)7. Title and Amount of Securities Underlying Derivative Security (Instr. 3 and 4) 8. Price of Derivative Security (Instr. 5) 9. Number of derivative Securities Beneficially Owned Following Reported Transaction(s) (Instr. 4) 10. Ownership Form: Direct (D) or Indirect (I) (Instr. 4) 11. Nature of Indirect Beneficial Ownership (Instr. 4)
CodeV(A)(D)Date ExercisableExpiration DateTitleAmount or Number of Shares
Explanation of Responses:
1. Represents restricted stock units granted on February 6, 2023, under the Issuer's 2003 Incentive Plan subject to satisfaction of performance targets that are to be settled solely in shares of common stock. The transaction date represents the date on which the Issuer's Compensation Committee determined the performance targets were achieved. The units vest with respect to one-third of the shares on March 1, 2024 and with respect to an additional one-third on each of March 1, 2025 and 2026, so long as the recipient is in the continuous employ of the Issuer through each such respective vesting date.
2. Represents stock unit awards granted on February 6, 2024, under the Issuer's 2003 Incentive Plan the vesting under which is solely time-based, that are to be settled solely in shares of common stock. The units vest with respect to one-third of the shares on March 1, 2025 and with respect to an additional one-third on each of March 1, 2026 and 2027, so long as the recipient is in the continuous employ of the Issuer through each such respective vesting date.
Patrick J. Kinney, Jr. as attorney-in-fact for Jason Holt02/08/2024
** Signature of Reporting PersonDate
Reminder: Report on a separate line for each class of securities beneficially owned directly or indirectly.
* If the form is filed by more than one reporting person, see Instruction 4 (b)(v).
** Intentional misstatements or omissions of facts constitute Federal Criminal Violations See 18 U.S.C. 1001 and 15 U.S.C. 78ff(a).
Note: File three copies of this Form, one of which must be manually signed. If space is insufficient, see Instruction 6 for procedure.
Persons who respond to the collection of information contained in this form are not required to respond unless the form displays a currently valid OMB Number.
"; //secFilings.Add(secFiling); //InsiderTransactionsParser.GetInstance().Parse(secFilings); //String symbol = "UFPT"; //InsiderTransactions insiderTransactions = MarketDataHelper.GetInsiderTransactions(symbol, 30); // Fundamental fundamental = MarketDataHelper.GetFundamentalFinViz("MIDD"); // AxiomTest(); //// List indices = ConsumerPriceIndexDA.GetDistinctIndices(); // Headlines headlines=MarketDataHelper.GetCompanyHeadlinesMarketWatch("GE"); // foreach(Headline headline in headlines) // { // Console.WriteLine(headline.Entry); // } // Need to run this and look at the duration .. because it will pull 1,000 equities. // GetSECFilings(); // www.sec.gov This version retrives for watchlist and also coninues to retrieve filings for symbols already in SEC Filings table // PriceIndices priceIndices=ConsumerPriceIndexDA.GetConsumerPriceIndex("cpi-u"); //ConsumerPriceIndexDA.InsertUpdatePriceIndices(priceIndices); // DividendHistory dividendHistory = MarketDataHelper.GetDividendHistory("CSPI"); // AnalystRatings analystRatings = MarketDataHelper.GetAnalystRatingsMarketBeat("MIDD"); //AnalystPriceTarget analystPriceTarget =MarketDataHelper.GetAnalystPriceTargetMarketBeat("ACRE"); //analystPriceTarget =MarketDataHelper.GetAnalystPriceTargetMarketBeat("MIDD"); 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)); return 0; } if (args.Length < 1) { DisplayUsage(); return 1; } string arg = args[0].ToUpper(); if(arg.Equals("RUNMODELPERFORMANCE")) { Program.RunModelPerformance(); } else if(arg.Equals("RUNPRICECHECKOPENPOSITIONS")) { Program.RunPriceCheckOpenPositions(); } else if(arg.Equals("SENDSMSEMAIL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("MESSAGE")){Console.WriteLine("MESSAGE is required");return 0;} Program.SendSMSEmail(commandArgs.Coalesce("MESSAGE")); } else if(arg.Equals("SHOWACTIVEGAINLOSS")) { Program.ShowActiveGainLoss(); } else if(arg.Equals("RUNTESTS")) { Program.RunTests(); } else if (arg.Equals("CHECKPRICES")) { Program.CheckPrices(); } else if(arg.Equals("MAXDIVMINVAR")) { CommandArgs commandArgs=new CommandArgs(args); if(commandArgs.Has("PERCENTOFEXPOSURE")&&commandArgs.Has("EXPOSURE")){Console.WriteLine("Choose either PERCENTOFEXPOSURE or EXPOSURE.");return 0;} if(!commandArgs.Has("PERCENTOFEXPOSURE")&&!commandArgs.Has("EXPOSURE")){Console.WriteLine("Choose either PERCENTOFEXPOSURE or EXPOSURE.");return 0;} if(!commandArgs.Has("DAYCOUNT")){Console.WriteLine("DAYCOUNT is required");return 0;} Program.MaximizeDividendMinimizeVaR(commandArgs.Coalesce("DAYCOUNT"),commandArgs.Coalesce("EXPOSURE",double.NaN),commandArgs.Coalesce("PERCENTOFEXPOSURE",double.NaN),commandArgs.Coalesce("VARCONFIDENCE",double.NaN)); } else if (arg.Equals("UPDATEEARNINGSANNOUNCEMENTS")) { Program.UpdateEarningsAnnouncements(); } else if (arg.Equals("UPDATEEARNINGSANNOUNCEMENTSSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("UPDATEEARNINGSANNOUNCEMENTSSYMBOL MISSING SYMBOL");return 0;} Program.UpdateEarningsAnnouncements(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("UPDATEALL")) { Program.UpdateAll(); } else if (arg.Equals("UPDATEALLNOPRICES")) { Program.UpdateAllNoPrices(); } else if (arg.Equals("UPDATEPRICES")) { Program.UpdatePrices(); } else if (arg.Equals("UPDATEDAILY")) { Program.UpdateDaily(); } else if (arg.Equals("UPDATEDAILY2")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("DATE")){Console.WriteLine("UPDATEDAILY2 MISSING DATE");return 0;} Program.UpdateDaily2(commandArgs.Coalesce("DATE")); } else if (arg.Equals("UPDATEDAILYPRICES")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("DATE")){Console.WriteLine("UPDATEPRICES MISSING DATE");return 0;} Program.UpdateDailyPrices(commandArgs.Coalesce("DATE")); } else if(arg.Equals("UPDATEPRICESBIGCHARTS")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("DATE")){Console.WriteLine("UPDATEPRICESBIGCHARTS MISSING DATE");return 0;} Program.UpdatePricesBigCharts(commandArgs.Coalesce("DATE")); } else if(arg.Equals("UPDATESPLITS")) { Program.UpdateSplits(); } else if(arg.Equals("PROCESSSPLIT")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("PROCESSSPLIT MISSING SYMBOL");return 0;} Program.ProcessSplit(commandArgs.Coalesce("SYMBOL")); } else if(arg.Equals("PROCESSALLSPLITS")) { Program.ProcessAllSplits(); } else if (arg.Equals("UPDATELATESTANALYSTRATINGS")) { CommandArgs commandArgs = new CommandArgs(args); if (commandArgs.Has("UPDATESECURITYMASTER")) Program.UpdateLatestAnalystRatings(commandArgs.Coalesce("UPDATESECURITYMASTER")); else Program.UpdateLatestAnalystRatings(); } else if (arg.Equals("UPDATEANALYSTRATINGS")) { CommandArgs commandArgs = new CommandArgs(args); if (commandArgs.Has("SYMBOL") && commandArgs.Has("MINDATE")) Program.UpdateAnalystRatings(commandArgs.Coalesce("SYMBOL"), commandArgs.Coalesce("MINDATE")); else if (commandArgs.Has("SYMBOL") ) Program.UpdateAnalystRatings(commandArgs.Coalesce("SYMBOL")); else if (commandArgs.Has("MINDATE")) Program.UpdateAnalystRatings(null,commandArgs.Coalesce("MINDATE")); else Program.UpdateAnalystRatings(); } else if (arg.Equals("UPDATEMISSINGANALYSTRATINGS")) { Program.UpdateMissingAnalystRatings(); } else if (arg.Equals("UPDATEZACKSRANK")) { Program.LoadZacksRank(); } else if (arg.Equals("UPDATEZACKSRANKSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("UPDATEZACKSRANKSYMBOL MISSING SYMBOL");return 0;} else Program.LoadZacksRank(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("UPDATEANALYSTPRICETARGET")) { Program.UpdateAnalystPriceTarget(); } else if (arg.Equals("UPDATEPRICESANDYIELD")) { Program.UpdatePricesAndYield(); } else if (arg.Equals("UPDATECOMPANYPROFILES")) { Program.UpdateCompanyProfiles(); } else if (arg.Equals("UPDATECOMPANYPROFILE")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("UPDATECOMPANYPROFILE MISSING SYMBOL");return 0;} Program.UpdateCompanyProfile(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("DISPLAYCOMPANYPROFILES")) { Program.DisplayCompanyProfiles(); } else if (arg.Equals("GETSECFILINGSSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("GETSECFILINGSSYMBOL MISSING SYMBOL");return 0;} Program.GetSECFilingsSymbol(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("GETSECFILINGSWATCHLIST")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("GETSECFILINGSWATCHLIST MISSING WATCHLIST");return 0;} Program.GetSECFilingsWatchList(commandArgs.Coalesce("WATCHLIST")); } else if (arg.Equals("GETSECFILINGSOPENPOSITIONS")) { Program.GetSECFilingsOpenPositions(); } else if (arg.Equals("UPDATESECFILINGS")) { Program.UpdateSECFilings(); } else if (arg.Equals("UPDATEALLCIK")) { Program.UpdateAllCIK(); } else if (arg.Equals("UPDATEALLMISSINGCIK")) { Program.UpdateAllMissingCIK(); } else if (arg.Equals("UPDATECIKSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("UPDATECIKSYMBOL MISSING SYMBOL");return 0;} Program.UpdateCIKSymbol(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("UPDATELATESTPRICEOPENPOSITIONS")) { Program.UpdateLatestPriceOpenPositions(); } else if (arg.Equals("UPDATELATESTPRICEWATCHLIST")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("UPDATELATESTPRICEWATCHLIST MISSING WATCHLIST");return 0;} Program.UpdateLatestPriceWatchList(commandArgs.Coalesce("WATCHLIST")); } else if (arg.Equals("DELETEPRICEWATCHLIST")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("WATCHLIST,DATE")){Console.WriteLine("DELETEPRICEWATCHLIST REQUIRES WATCHLIST,DATE");return 0;} Program.DeletePriceWatchList(commandArgs.Coalesce("WATCHLIST"),commandArgs.Coalesce("DATE")); } else if (arg.Equals("FINDALLSYMBOLSMISSINGPRICEON")) { bool rollForward=false; String strFilter=null; CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("DATE")){Console.WriteLine("FINDALLSYMBOLSMISSINGPRICEON REQUIRES DATE");return 0;} if(commandArgs.Has("ROLLFORWARD"))rollForward=commandArgs.Get("ROLLFORWARD"); if(commandArgs.Has("FILTER"))strFilter=commandArgs.Get("FILTER"); Program.FindAllSymbolsMissingPriceOn(commandArgs.Coalesce("DATE"),rollForward,strFilter); } //MDTrace.WriteLine(LogLevel.DEBUG," ROLLPRICEFORWARD /SYMBOL: /FROMDATE: /TODATE: Roll price forward from the given date to the specified date."); else if(arg.Equals("ROLLPRICEFORWARD")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,FROMDATE,TODATE")){Console.WriteLine("ROLLPRICEFORWARD REQUIRES SYMBOL,FROMDATE,TODATE");return 0;} Program.RollPriceForward(commandArgs.Get("SYMBOL"),commandArgs.Get("FROMDATE"),commandArgs.Get("TODATE")); } else if (arg.Equals("UPDATEPRICESASOF")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("DATE")){Console.WriteLine("UPDATEPRICESASOF REQUIRES DATE");return 0;} Program.UpdatePricesAsOf(commandArgs.Coalesce("DATE")); } else if (arg.Equals("UPDATEPRICEASOFSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,DATE")){Console.WriteLine("UPDATEPRICEASOFSYMBOL REQUIRES SYMBOL,DATE");return 0;} Program.UpdatePricesAsOfSymbol(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DATE")); } else if(arg.Equals("UPDATEPRICEASOFSYMBOLYAHOO")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,DATE")) { Console.WriteLine("UPDATEPRICEASOFSYMBOL REQUIRES SYMBOL,DATE"); return 0; } Program.UpdatePricesAsOfSymbolYahoo(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DATE")); } else if (arg.Equals("UPDATELATESTPRICESYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("UPDATEPRICEASOFSYMBOL REQUIRES SYMBOL");return 0;} Program.UpdateLatestPriceSymbol(commandArgs.Coalesce("SYMBOL").ToUpper()); } else if (arg.Equals("UPDATELATESTPRICESALL")) { Program.UpdateLatestPriceAll(); } else if (arg.Equals("DELETELATESTPRICESYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("DELETELATESTPRICESYMBOL REQUIRES SYMBOL");return 0;} Program.DeleteLatestPriceSymbol(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("DELETEPRICESASOF")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("DATE")){Console.WriteLine("DELETEPRICESASOF REQUIRES DATE");return 0;} Program.DeletePricesAsOf(commandArgs.Coalesce("DATE")); } else if (arg.Equals("UPDATEPRICESDATE")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("DATE")){Console.WriteLine("UPDATEPRICESDATE REQUIRES DATE");return 0;} Program.UpdatePricesDate(commandArgs.Coalesce("DATE")); } else if (arg.Equals("UPDATEPRICESSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("UPDATEPRICESSYMBOL REQUIRES SYMBOL");return 0;} Program.UpdatePricesSymbol(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("LOADALLPRICESWATCHLIST")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("LOADALLPRICESWATCHLIST REQUIRES WATCHLIST");return 0;} Program.LoadAllPricesWatchList(commandArgs.Coalesce("WATCHLIST")); } else if (arg.Equals("LOADALLPRICESSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("LOADALLPRICESSYMBOL REQUIRES SYMBOL");return 0;} Program.LoadAllPricesSymbol(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("SHOWALLPRICESSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("LOADALLPRICESSYMBOL REQUIRES SYMBOL");return 0;} Program.ShowAllPricesSymbol(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("LOADALLPRICESSYMBOLDATE")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("LOADALLPRICESSYMBOLDATE REQUIRES SYMBOL");return 0;} if(!commandArgs.Has("DATE")){Console.WriteLine("LOADALLPRICESSYMBOLDATE REQUIRES DATE");return 0;} Program.LoadAllPricesSymbolDate(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DATE")); } else if (arg.Equals("LOADFINANCIALSTATEMENTSSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("LOADFINANCIALSTATEMENTSSYMBOL REQUIRES SYMBOL");return 0;} Program.LoadFinancialStatementsSymbol(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("LOADFINANCIALSTATEMENTS")) { Program.LoadFinancialStatements(); } else if (arg.Equals("LOADFUNDAMENTAL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("LOADFUNDAMENTAL REQUIRES SYMBOL");return 0;} Program.LoadFundamental(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("LOADFUNDAMENTALS")) { Program.LoadFundamentals(); } else if (arg.Equals("LOADFUNDAMENTALFINVIZ")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("LOADFUNDAMENTALFINVIZ REQUIRES SYMBOL");return 0;} Program.LoadFundamentalFinViz(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("LOADFUNDAMENTALSFINVIZ")) { Program.LoadFundamentalsFinViz(); } else if (arg.Equals("LOADHISTORICAL")) { Program.LoadHistorical(); } else if (arg.Equals("LOADHISTORICALSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("LOADHISTORICALSYMBOL REQUIRES SYMBOL");return 0;} Program.LoadHistorical(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("ADDPRICE")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,DATE,OPEN,HIGH,LOW,CLOSE,VOLUME")){Console.WriteLine("ADDPRICE REQUIRES SYMBOL,DATE,OPEN,HIGH,LOW,CLOSE,VOLUME");return 0;} Program.AddPrice( commandArgs.Coalesce("SYMBOL"), commandArgs.Coalesce("DATE"), commandArgs.Coalesce("OPEN"), commandArgs.Coalesce("HIGH"), commandArgs.Coalesce("LOW"), commandArgs.Coalesce("CLOSE"), commandArgs.Coalesce("VOLUME")); } else if (arg.Equals("DELETEPRICE")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,DATE")){Console.WriteLine("DELETEPRICE REQUIRES SYMBOL,DATE");return 0;} Program.DeletePriceSymbol(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DATE")); } // ****************** A N A L Y S I S else if (arg.Equals("FINDSWINGTRADESSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,DAYCOUNT")){Console.WriteLine("FINDSWINGTRADESSYMBOL REQUIRES SYMBOL,DAYCOUNT");return 0;} Program.FindSwingTrades(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DAYCOUNT")); } else if (arg.Equals("FINDCURRENTSWINGTRADES")) { Program.FindCurrentSwingTrades(false); } else if (arg.Equals("FINDCURRENTSWINGTRADESBARGAIN")) { Program.FindCurrentSwingTrades(true); } else if (arg.Equals("CALCSTICKERSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("CALCSTICKERSYMBOL REQUIRES SYMBOL");return 0;} else Program.CalcStickerSymbol(commandArgs.Coalesce("SYMBOL"),false); } else if (arg.Equals("CALCACQUIRERSMULTIPLE")) { Program.CalcAcquirersMultiple(); } else if (arg.Equals("CALCACQUIRERSMULTIPLESYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); Program.CalcAcquirersMultipleSymbol(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("CALCTLBRANKS")) { Program.CalcTLBRanks(); } else if (arg.Equals("CALCSTICKER")) { Program.CalcSticker(); } else if (arg.Equals("FINDETFMOS")) { Program.FindETFMOS(); } else if (arg.Equals("CALCSTICKERETF")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("CalcStickerETF REQUIRES SYMBOL");return 0;} Program.CalcStickerETF(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("CALCPORTFOLIOBETA")) { CommandArgs commandArgs = new CommandArgs(args); if (commandArgs.Has("ACCOUNT"))Program.CalcPortfolioBeta(commandArgs.Coalesce("ACCOUNT")); else Program.CalcPortfolioBeta(); } else if (arg.Equals("CALCBETA")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("CALCBETA REQUIRES SYMBOL");return 0;} Program.CalcBeta(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("CALCBETAALL")) { CommandArgs commandArgs=new CommandArgs(args); Program.CalcBetaAll(); } else if (arg.Equals("CALCDCF")) { Program.CalcDCF(); } // ****************** I N S I D E R T R A N S A C T I O N S***************** else if (arg.Equals("LOADINSIDERTRANSACTIONS")) { Program.LoadInsiderTransactions(); } else if (arg.Equals("LOADINSIDERTRANSACTIONSSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("LOADINSIDERTRANSACTIONSSYMBOL REQUIRES SYMBOL");return 0;} Program.LoadInsiderTransactionsSymbol(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("LOADINSIDERTRANSACTIONSWATCHLISTS")) { Program.LoadInsiderTransactionsWatchLists(); } // ****************** C H A R T I N G F U N C T I O N A L I T Y ***************** else if (arg.Equals("GENERATESTOCHASTICS")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,DAYCOUNT")){Console.WriteLine("GENERATESTOCHASTICS REQUIRES SYMBOL,DAYCOUNT");return 0;} else if(commandArgs.Has("SYMBOL,DAYCOUNT,PERIOD-N,PERIOD-K"))Program.GenerateStochastics(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DAYCOUNT"),commandArgs.Coalesce("PERIOD-N"),commandArgs.Coalesce("PERIOD-K")); else if(commandArgs.Has("SYMBOL,DAYCOUNT,PERIOD-N"))Program.GenerateStochastics(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DAYCOUNT"),commandArgs.Coalesce("PERIOD-N")); else if(commandArgs.Has("SYMBOL,DAYCOUNT"))Program.GenerateStochastics(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DAYCOUNT")); else if(commandArgs.Has("SYMBOL"))Program.GenerateStochastics(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("GENERATESTOCHASTICSSHEET")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,DAYCOUNT")){Console.WriteLine("GENERATESTOCHASTICS REQUIRES SYMBOL,DAYCOUNT");return 0;} else if(commandArgs.Has("SYMBOL,DAYCOUNT,PERIOD-N,PERIOD-K"))Program.GenerateStochasticsSheet(commandArgs.Coalesce("PATHTEMPLATE"),commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DAYCOUNT"),commandArgs.Coalesce("PERIOD-N"),commandArgs.Coalesce("PERIOD-K")); else if(commandArgs.Has("SYMBOL,DAYCOUNT,PERIOD-N"))Program.GenerateStochasticsSheet(commandArgs.Coalesce("PATHTEMPLATE"),commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DAYCOUNT"),commandArgs.Coalesce("PERIOD-N")); else if(commandArgs.Has("SYMBOL,DAYCOUNT"))Program.GenerateStochasticsSheet(commandArgs.Coalesce("PATHTEMPLATE"),commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DAYCOUNT")); else if(commandArgs.Has("SYMBOL"))Program.GenerateStochasticsSheet(commandArgs.Coalesce("PATHTEMPLATE"),commandArgs.Coalesce("SYMBOL")); else MDTrace.WriteLine(LogLevel.DEBUG,"Insufficient number of arguments."); } else if (arg.Equals("GENERATEBOLLINGERBANDS")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,MOVINGAVERAGEDAYS,HISTORICALDAYS")){Console.WriteLine("GENERATEBOLLINGERBANDS REQUIRES SYMBOL,MOVINGAVERAGEDAYS,HISTORICALDAYS");return 0;} else if(commandArgs.Has("SYMBOL"))Program.GenerateBollingerBands(commandArgs.Coalesce("SYMBOL")); else if(commandArgs.Has("SYMBOL,MOVINGAVERAGEDAYS"))Program.GenerateBollingerBands(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("MOVINGAVERAGEDAYS")); else if(commandArgs.Has("SYMBOL,MOVINGAVERAGEDAYS,HISTORICALDAYS"))Program.GenerateBollingerBands(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("MOVINGAVERAGEDAYS"),commandArgs.Coalesce("HISTORICALDAYS")); else MDTrace.WriteLine(LogLevel.DEBUG,"Insufficient number of arguments."); } else if (arg.Equals("GENERATEBOLLINGERBANDSHEET")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("STRPATHTEMPLATE,SYMBOL,MOVINGAVERAGEDAYS,HISTORICALDAYS")){Console.WriteLine("GENERATEBOLLINGERBANDS REQUIRES STRPATHTEMPLATE,SYMBOL,MOVINGAVERAGEDAYS,HISTORICALDAYS");return 0;} else if(commandArgs.Has("STRPATHTEMPLATE,SYMBOL"))Program.GenerateBollingerBandSheet(commandArgs.Coalesce("STRPATHTEMPLATE"),commandArgs.Coalesce("SYMBOL")); else if(commandArgs.Has("STRPATHTEMPLATE,SYMBOL,MOVINGAVERAGEDAYS"))Program.GenerateBollingerBandSheet(commandArgs.Coalesce("STRPATHTEMPLATE"),commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("MOVINGAVERAGEDAYS")); else if(commandArgs.Has("STRPATHTEMPLATE,SYMBOL,MOVINGAVERAGEDAYS,HISTORICALDAYS"))Program.GenerateBollingerBandSheet(commandArgs.Coalesce("STRPATHTEMPLATE"),commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("MOVINGAVERAGEDAYS"),commandArgs.Coalesce("HISTORICALDAYS")); else MDTrace.WriteLine(LogLevel.DEBUG,"Insufficient number of arguments."); } else if (arg.Equals("GENERATEMOVINGAVERAGESHEET")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("STRPATHTEMPLATE,SYMBOL")){Console.WriteLine("GENERATEMOVINGAVERAGESHEET REQUIRES STRPATHTEMPLATE,SYMBOL");return 0;} else if(commandArgs.Has("STRPATHTEMPLATE,SYMBOL"))Program.GenerateMovingAverageSheet(commandArgs.Coalesce("STRPATHTEMPLATE"),commandArgs.Coalesce("SYMBOL")); } // ************************************* S T O C H A S T I C S *************************** else if (arg.Equals("RUNSTOCHASTICSSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("RUNSTOCHASTICSSYMBOL REQUIRES SYMBOL");return 0;} else if(commandArgs.Has("SYMBOL"))Program.GenerateStochastics(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("RUNSTOCHASTICSSIGNALSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("RUNSTOCHASTICSSIGNALSYMBOL REQUIRES SYMBOL");return 0;} else if(commandArgs.Has("SYMBOL"))Program.GenerateStochasticsSignals(commandArgs.Coalesce("SYMBOL")); } // ************************************* M A C D A N D S I G N A L *************************** else if (arg.Equals("RUNPIVOTS")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,DAYCOUNT")){Console.WriteLine("RUNPIVOTS REQUIRES SYMBOL,DAYCOUNT");return 0;} else if(commandArgs.Has("SYMBOL"))Program.RunPivots(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DAYCOUNT")); } else if (arg.Equals("RUNMACDSIGNALSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(commandArgs.Has("SYMBOL,MACD"))Program.RunMACDSignalSymbol(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("MACD")); else if(commandArgs.Has("SYMBOL"))Program.RunMACDSignalSymbol(commandArgs.Coalesce("SYMBOL")); else {Console.WriteLine("RUNMACDSYMBOL REQUIRES SYMBOL,MACD");return 0;} } else if (arg.Equals("TRADESYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,SHARES,STARTDATE,HOLDINGDAYS")){Console.WriteLine("TRADESYMBOL REQUIRES SYMBOL,SHARES,STARTDATE,HOLDINGDAYS");return 0;} else Program.TradeSymbol( commandArgs.Coalesce("SYMBOL"), commandArgs.Coalesce("SHARES"), commandArgs.Coalesce("STARTDATE"), commandArgs.Coalesce("HOLDINGDAYS")); } // ************************************* Y I E L D C U R V E *************************** else if (arg.Equals("UPDATEYIELDCURVE")) { Program.UpdateYieldCurve(); } else if (arg.Equals("UPDATEYIELDCURVEHIST")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("YEARS")){Console.WriteLine("UPDATEYIELDCURVEHIST REQUIRES YEARS");return 0;} else Program.UpdateYieldCurve(commandArgs.Coalesce("YEARS")); } // ************************************* D I V I D E N D H I S T O R Y *************************** else if (arg.Equals("UPDATEDIVIDENDHISTORY")) { Program.UpdateDividendHistory(); } else if (arg.Equals("UPDATEDIVIDENDHISTORYSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("UPDATEDIVIDENDHISTORYSYMBOL REQUIRES SYMBOL");return 0;} else Program.UpdateDividendHistory(commandArgs.Coalesce("SYMBOL")); } // ************************************* M I S C E L L A N E O U S *************************** else if (arg.Equals("GETETFHOLDINGS")) { Program.GetETFHoldings(); } else if (arg.Equals("GETETFHOLDINGSSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("GETETFHOLDINGSSYMBOL REQUIRES SYMBOL");return 0;} else Program.GetETFHoldingsSymbol(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("UPDATEOPTIONSCHAINS")) { Program.UpdateOptionsChains(); } else if (arg.Equals("UPDATEOPTIONSCHAINSSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("UPDATEOPTIONSCHAINSSYMBOL REQUIRES SYMBOL");return 0;} else Program.UpdateOptionsChains(commandArgs.Coalesce("SYMBOL")); } else if (arg.Equals("UPDATEOPTIONSCHAINSSYMBOLS")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOLS")){Console.WriteLine("UPDATEOPTIONSCHAINSSYMBOLS REQUIRES SYMBOLS");return 0;} else Program.UpdateOptionsChains(commandArgs.Coalesce("SYMBOLS")); } else if (arg.Equals("UPDATEOPTIONSCHAINSWATCHLIST")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("UPDATEOPTIONSCHAINSWATCHLIST REQUIRES WATCHLIST");return 0;} else Program.UpdateOptionsChainsWatchList(commandArgs.Coalesce("WATCHLIST")); } else if (arg.Equals("DISPLAYAVAILABLEOPTIONS")) { CommandArgs commandArgs=new CommandArgs(args); if(commandArgs.Has("DAYSOUT,VERBOSE"))DisplayAvailableOptions(commandArgs.Coalesce("DAYSOUT"),commandArgs.Coalesce("VERBOSE")); else if(commandArgs.Has("DAYSOUT"))Program.DisplayAvailableOptions(commandArgs.Coalesce("DAYSOUT")); else Program.DisplayAvailableOptions(); } else if (arg.Equals("GETVAR")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("DAYCOUNT,CONFIDENCE,RETURNDAYS")){Console.WriteLine("GETVAR REQUIRES DAYCOUNT,CONFIDENCE,RETURNDAYS");return 0;} else Program.GetVaR(commandArgs.Coalesce("DAYCOUNT"),commandArgs.Coalesce("CONFIDENCE"),commandArgs.Coalesce("RETURNDAYS")); } else if (arg.Equals("GETOPTIMALPOSITIONFROMWATCHLIST")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("WATCHLIST,MARKETVALUE,DAYCOUNT,CONFIDENCE,RETURNDAYS")){Console.WriteLine("GETOPTIMALPOSITIONFROMWATCHLIST REQUIRES WATCHLIST,MARKETVALUE,DAYCOUNT,CONFIDENCE,RETURNDAYS");return 0;} else Program.GetOptimalPositionFromWatchList( commandArgs.Coalesce("WATCHLIST"), commandArgs.Coalesce("MARKETVALUE"), commandArgs.Coalesce("DAYCOUNT"), commandArgs.Coalesce("CONFIDENCE"), commandArgs.Coalesce("RETURNDAYS")); } else if (arg.Equals("UPDATEMISSINGPRICES")) { CommandArgs commandArgs=new CommandArgs(args); if(commandArgs.Has("DATE"))Program.GetMissingPrices(commandArgs.Coalesce("DATE")); else Program.GetMissingPrices(); } else if (arg.Equals("UPDATEMISSINGPRICESSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("UPDATEMISSINGPRICESSYMBOL REQUIRES SYMBOL");return 0;} else Program.GetMissingPricesSymbol(commandArgs.Coalesce("SYMBOL")); } else if(arg.Equals("LOADGDP")) { Program.LoadGDPPerCapita(); } else if(arg.Equals("LOADPREMARKETDATA")) { Program.LoadPremarketData(); } else if(arg.Equals("LOADHEADLINESWATCHLIST")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("LOADHEADLINESWATCHLIST REQUIRES WATCHLIST");return 0;} else Program.LoadHeadlinesWatchList(commandArgs.Coalesce("WATCHLIST")); } else if(arg.Equals("LOADHEADLINESSYMBOL")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL")){Console.WriteLine("LOADHEADLINESSYMBOL REQUIRES SYMBOL");return 0;} else Program.LoadHeadlinesSymbol(commandArgs.Coalesce("SYMBOL")); } else if(arg.Equals("FINDCOEFFICIENTS")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SYMBOL,DAYCOUNT")){Console.WriteLine("FINDCOEFFICIENTS REQUIRES SYMBOL,DAYCOUNT");return 0;} Program.FindCoefficients(commandArgs.Coalesce("SYMBOL"),commandArgs.Coalesce("DAYCOUNT"),commandArgs.Coalesce("STARTDATE",new DateTime())); } else if (arg.Equals("DISPLAYVOLATILITY")) { CommandArgs commandArgs = new CommandArgs(args); DateTime? startDate=null; if (!commandArgs.Has("SYMBOLS,DAYCOUNT")) { Console.WriteLine("DISPLAYVOLATILITY REQUIRES SYMBOLS,DAYCOUNT"); return 0; } if (commandArgs.Has("STARTDATE")) startDate = commandArgs.Coalesce("STARTDATE"); Program.DisplayVolatility(Utility.ToList(commandArgs.Coalesce("SYMBOLS")), commandArgs.Coalesce("DAYCOUNT"),startDate); } else if (arg.Equals("DISPLAYSHARPERATIO")) { CommandArgs commandArgs = new CommandArgs(args); DateTime? startDate = null; int months = 12; if (!commandArgs.Has("SYMBOLS")) { Console.WriteLine("DISPLAYSHARPERATIO REQUIRES SYMBOLS"); return 0; } if (commandArgs.Has("STARTDATE")) startDate = commandArgs.Coalesce("STARTDATE"); if (commandArgs.Has("MONTHS")) months = commandArgs.Coalesce("MONTHS"); Program.DisplaySharpeRatio(Utility.ToList(commandArgs.Coalesce("SYMBOLS")), months, startDate); } // ************************************************************************************************************************************************************************************************************************* // ************************************************************************************************** C M T M O M E N T U M ************************************************************************************************* // ************************************************************************************************************************************************************************************************************************* else if(arg.Equals("RUNCMTREND")) { Program.RunCMTrend(args); } else if(arg.Equals("CMTSESSION")) { Program.HandleCMTSession(args); } // ************************************************************************************************************************************************************************************************************************* // ************************************************************************************************** M G M O M E N T U M ************************************************************************************************* // ************************************************************************************************************************************************************************************************************************* else if (arg.Equals("RUNMOMENTUM")) { CommandArgs commandArgs = new CommandArgs(args); if (!commandArgs.Has("STARTDATE,MAXPOSITIONS")) return 0; Program.RunMomentum(commandArgs.Coalesce("STARTDATE"), commandArgs.Coalesce("MAXPOSITIONS")); } else if (arg.Equals("RUNBACKTEST")) { CommandArgs commandArgs = new CommandArgs(args); MGConfiguration mgParams=new MGConfiguration(); if (!commandArgs.Has("STARTDATE,MAXPOSITIONS,INITIALCASH,HOLDINGPERIOD")) { if (!commandArgs.Has("STARTDATE")) MDTrace.WriteLine(LogLevel.DEBUG, "Missing STARTDATE"); if (!commandArgs.Has("MAXPOSITIONS")) MDTrace.WriteLine(LogLevel.DEBUG, "Missing MAXPOSITIONS"); if (!commandArgs.Has("INITIALCASH")) MDTrace.WriteLine(LogLevel.DEBUG, "Missing INITIALCASH"); if (!commandArgs.Has("HOLDINGPERIOD")) MDTrace.WriteLine(LogLevel.DEBUG, "Missing HOLDINGPERIOD"); return 0; } mgParams.MaxPositions=commandArgs.Coalesce("MAXPOSITIONS"); mgParams.InitialCash=commandArgs.Coalesce("INITIALCASH"); mgParams.HoldingPeriod=commandArgs.Coalesce("HOLDINGPERIOD"); if(commandArgs.Has("INCLUDETRADEMASTERFORSYMBOLSHELD")) { mgParams.IncludeTradeMasterForSymbolsHeld=commandArgs.Get("INCLUDETRADEMASTERFORSYMBOLSHELD"); } if(commandArgs.Has("USESTOCHASTICS")) { mgParams.UseStochastics=commandArgs.Coalesce("USESTOCHASTICS",true); } // ** M A C D if(commandArgs.Has("USEMACD")) { mgParams.UseMACD=commandArgs.Coalesce("USEMACD",true); } if(commandArgs.Has("MACDREJECTSTRONGSELLSIGNALS")) { mgParams.MACDRejectStrongSellSignals=commandArgs.Coalesce("MACDREJECTSTRONGSELLSIGNALS",true); } if(commandArgs.Has("MACDREJECTWEAKSELLSIGNALS")) { mgParams.MACDRejectWeakSellSignals=commandArgs.Coalesce("MACDREJECTWEAKSELLSIGNALS",true); } if(commandArgs.Has("MACDSIGNALDAYS")) { mgParams.MACDSignalDays=commandArgs.Coalesce("MACDSIGNALDAYS",mgParams.MACDSignalDays); } if(commandArgs.Has("MACDSETUP")) { mgParams.MACDSetup=commandArgs.Coalesce("MACDSETUP",mgParams.MACDSetup); } // ** QualityIndicator qualityIndicator=new QualityIndicator(QualityIndicator.QualityType.IDIndicator); if(commandArgs.Has("QUALITYINDICATORTYPE")) qualityIndicator.Quality=QualityIndicator.ToQuality(commandArgs.Coalesce("QUALITYINDICATORTYPE","IDINDICATOR")); mgParams.QualityIndicatorType=qualityIndicator.ToString(); mgParams.UseLowSlopeBetaCheck=true; if(commandArgs.Has("USELOWSLOPEBETACHECK")) mgParams.UseLowSlopeBetaCheck=commandArgs.Coalesce("USELOWSLOPEBETACHECK",true); DateTime startDate = commandArgs.Coalesce("STARTDATE"); DateTime endDate=commandArgs.Coalesce("ENDDATE",new DateTime()); String pathSessionFileName = commandArgs.Coalesce("SESSIONFILE", null); if(null!=pathSessionFileName)pathSessionFileName=pathSessionFileName.Trim(); mgParams.DisplayHeader(); List results=new List(); MomentumBacktest backtestMomentum=new MomentumBacktest(); results.Add(backtestMomentum.PerformBacktest(startDate,endDate,pathSessionFileName,mgParams)); } else if (arg.Equals("MGSESSION")) { CommandArgs commandArgs = new CommandArgs(args); if(!commandArgs.Has("SESSIONFILE")) { MDTrace.WriteLine(LogLevel.DEBUG,"Missing SESSIONFILE"); return 0; } MomentumBacktest momentumBacktest = new MomentumBacktest(); momentumBacktest.DisplaySession(commandArgs.Coalesce("SESSIONFILE")); } else if(arg.Equals("MGGAINLOSS")) { CommandArgs commandArgs = new CommandArgs(args); if(!commandArgs.Has("SESSIONFILE")) { MDTrace.WriteLine(LogLevel.DEBUG,"Missing SESSIONFILE"); return 0; } MomentumBacktest momentumBacktest = new MomentumBacktest(); MomentumBacktest.DisplayGainLoss(commandArgs.Coalesce("SESSIONFILE")); } else if (arg.Equals("MGLIQUIDATE")) { DateTime? tradeDate = null; CommandArgs commandArgs = new CommandArgs(args); if (!commandArgs.Has("SESSIONFILE")) return 0; if (commandArgs.Has("TRADEDATE")) tradeDate = commandArgs.Coalesce("TRADEDATE"); MomentumBacktest momentumBacktest = new MomentumBacktest(); momentumBacktest.MGLiquididate(commandArgs.Coalesce("SESSIONFILE"), tradeDate); } else if(arg.Equals("MGCLOSEPOSITION")) { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SESSIONFILE")) { MDTrace.WriteLine(LogLevel.DEBUG,"Missing SESSIONFILE"); return 0; } if(!commandArgs.Has("SYMBOL")) { MDTrace.WriteLine(LogLevel.DEBUG,"Missing SYMBOL"); return 0; } if(!commandArgs.Has("PURCHASEDATE")) { MDTrace.WriteLine(LogLevel.DEBUG,"Missing PURCHASEDATE"); return 0; } if(!commandArgs.Has("SELLPRICE")) { MDTrace.WriteLine(LogLevel.DEBUG,"Missing SELLPRICE"); return 0; } if(!commandArgs.Has("SELLDATE")) { MDTrace.WriteLine(LogLevel.DEBUG,"Missing SELLDATE"); return 0; } MomentumBacktest momentumBacktest=new MomentumBacktest(); momentumBacktest.MGClosePosition( commandArgs.Get("SESSIONFILE"), commandArgs.Get("SYMBOL"), commandArgs.Get("PURCHASEDATE"), commandArgs.Get("SELLPRICE"), commandArgs.Get("SELLDATE") ); } else if (arg.Equals("MGUPDATEPRICE")) { CommandArgs commandArgs = new CommandArgs(args); if (!commandArgs.Has("SYMBOL,TRADEDATE,PRICE,SESSIONFILE")) return 0; MomentumBacktest momentumBacktest = new MomentumBacktest(); momentumBacktest.UpdateSessionPrice(commandArgs.Coalesce("SYMBOL"), commandArgs.Coalesce("TRADEDATE"), commandArgs.Coalesce("PRICE"), commandArgs.Coalesce("SESSIONFILE")); } // ************************************************************************************************************************************************************************************************************************* // ************************************************************************************************** C M M O M E N T U M ************************************************************************************************* // ************************************************************************************************************************************************************************************************************************* else if(arg.Equals("RUNCMBACKTEST")) // CMMOMENTUM { RunCMMomentum(args); } else if (arg.Equals("CMSESSION")) // CMMOMENTUM { CommandArgs commandArgs = new CommandArgs(args); if (!commandArgs.Has("SESSIONFILE")) {MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Missing SESSIONFILE"));return 0;} CMMomentumBacktest cmBacktest = new CMMomentumBacktest(); cmBacktest.DisplaySession(commandArgs.Coalesce("SESSIONFILE")); } else if(arg.Equals("CMGAINLOSS")) // CMMOMENTUM { CommandArgs commandArgs=new CommandArgs(args); if(!commandArgs.Has("SESSIONFILE")) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Missing SESSIONFILE")); return 0; } CMMomentumBacktest cmBacktest=new CMMomentumBacktest(); cmBacktest.DisplayGainLoss(commandArgs.Coalesce("SESSIONFILE")); } else if (arg.Equals("CMLIQUIDATE")) // CMMOMENTUM { DateTime? tradeDate = null; CommandArgs commandArgs = new CommandArgs(args); if(!commandArgs.Has("SESSIONFILE")) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Missing SESSIONFILE")); return 0; } if (commandArgs.Has("TRADEDATE")) tradeDate = commandArgs.Coalesce("TRADEDATE"); CMMomentumBacktest cmBacktest = new CMMomentumBacktest(); cmBacktest.CMLiquidate(commandArgs.Coalesce("SESSIONFILE"), tradeDate); } else if (arg.Equals("CMCANDIDATELASTRESORT")) // CMMOMENTUM { CMParams cmParams = new CMParams(); List candidates = Utility.ToList(cmParams.FallbackCandidateBestOf); CommandArgs commandArgs = new CommandArgs(args); if (!commandArgs.Has("TRADEDATE")) { MDTrace.WriteLine(LogLevel.DEBUG, "TRADEDATE required"); return 0; } CMCandidate cmCandidate = CMCandidateGenerator.GetFallbackCandidateOfLastResort(candidates, commandArgs.Coalesce("TRADEDATE"), commandArgs.Coalesce("TRADEDATE"), cmParams); if (null == cmCandidate) { MDTrace.WriteLine(LogLevel.DEBUG, "Unable to determine candidate of last resort."); return 0; } foreach (String candidate in candidates) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Candidate examined..{0}", candidate)); } MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Best candidate is {0}", cmCandidate.Symbol)); } else { DisplayUsage(); return 1; } return 0; } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); return 1; } finally { LocalPriceCache.GetInstance().Dispose(); GBPriceCache.GetInstance().Dispose(); } } // main // ***************************************************************************************************************************************************************************** // ***************************************************************************************************************************************************************************** // ***************************************************************************************************************************************************************************** public static void RunPriceCheckOpenPositions() { PortfolioTrades portfolioTrades=PortfolioDA.GetTrades(); portfolioTrades=portfolioTrades.GetOpenTradesOn(PricingDA.GetLatestDate()); List symbols=portfolioTrades.Symbols; symbols.Sort(); foreach(String symbol in symbols) { DateTime latestDate=PricingDA.GetLatestDate(symbol); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("{0} {1}",symbol,Utility.DateTimeToStringMMSDDSYYYY(latestDate))); } } public static void SendSMSEmail(String message) { try { String smsSMTPAddress = ConfigurationManager.AppSettings["sms_smtpaddress"]; String smsUserName = ConfigurationManager.AppSettings["sms_smsusername"]; String smsPassword = ConfigurationManager.AppSettings["sms_smspassword"]; String[] smsRecipients = ConfigurationManager.AppSettings["sms_smsrecipients"].Split(','); SMSClient.SendSMSEmail(message, smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Done.")); } catch(Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("SendSMSEmail: Exception: {0}.",exception.ToString())); } } public static void RunTests() { Dictionary items=MarketDataHelper.RunTests(); MDTrace.WriteLine(LogLevel.DEBUG,"************************************************* S U M M A R Y ********************************************"); MDTrace.WriteLine("Method,Status"); List keys=new List(items.Keys); for(int index=0;index symbols=PricingDA.GetSymbols(); DateGenerator dateGenerator=new DateGenerator(); int maxDaysBetween=100; foreach(String symbol in symbols) { DateTime minDate=PricingDA.GetEarliestDate(symbol); DateTime maxDate=PricingDA.GetLatestDate(symbol); DateTime earliestDate=DateTime.Parse("10-23-2003"); if(minDatemaxDaysBetween) { DateTime problemDate=prices[index].Date; DateTime problemDateEnd=prices[index+1].Date; Prices pricesAfter=PricingDA.GetPrices(symbol,maxDate,problemDate); Prices pricesBefore=PricingDA.GetPrices(symbol,problemDate,minDate); int countPricesBefore=0; int countPricesAfter=0; double stddevBefore=0.00; double stddevAfter=0.00; if(null!=pricesAfter) { countPricesAfter=pricesAfter.Count; float[] returnsAfter=pricesAfter.GetReturns(); stddevAfter=Numerics.StdDev(ref returnsAfter); } if(null!=pricesBefore) { countPricesBefore=pricesBefore.Count; float[] returnsBefore=pricesBefore.GetReturns(); stddevBefore=Numerics.StdDev(ref returnsBefore); } if(countPricesBefore>countPricesAfter&&double.IsNaN(stddevAfter)) { PricingDA.DeletePriceOnOrAfter(symbol,problemDate); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Found price discontinuity at symbol:{0} for date : {1}, gap is {2} days, prices prior {3}, prices after {4}. deviation before {5}, deviation after {6}",symbol,prices[index].Date,daysBetween,countPricesBefore,countPricesAfter,Utility.FormatNumber(stddevBefore,2),Utility.FormatNumber(stddevAfter,2))); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Delete symbol:{0} for date >= {1}",symbol,Utility.DateTimeToStringMMHDDHYYYY(prices[index].Date))); } else if(countPricesAfter>countPricesBefore&&double.IsNaN(stddevBefore)) { PricingDA.DeletePriceOnOrBefore(symbol,problemDate); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Found price discontinuity at symbol:{0} for date : {1}, gap is {2} days, prices prior {3}, prices after {4}. deviation before {5}, deviation after {6}",symbol,prices[index].Date,daysBetween,countPricesBefore,countPricesAfter,Utility.FormatNumber(stddevBefore,2),Utility.FormatNumber(stddevAfter,2))); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Delete symbol:{0} for date <= {1}",symbol,Utility.DateTimeToStringMMHDDHYYYY(prices[index].Date))); } } } } } // ************************************************************************************************************************* // *********************************************** U P D A T E D A I L Y ************************************************ // ************************************************************************************************************************* public static void UpdateDaily() { UpdateDaily2(DateTime.Now); } // ************************************************************************************************************************************************************************************* // **************************************************************************** U P D A T E D A I L Y P R I C E S ******************************************************************************* // ************************************************************************************************************************************************************************************* public static void UpdateDailyPrices(DateTime startDate) { DateGenerator dateGenerator=new DateGenerator(); String smsSMTPAddress = ConfigurationManager.AppSettings["sms_smtpaddress"]; String smsUserName = ConfigurationManager.AppSettings["sms_smsusername"]; String smsPassword = ConfigurationManager.AppSettings["sms_smspassword"]; String[] smsRecipients = ConfigurationManager.AppSettings["sms_smsrecipients"].Split(','); DateTime currentDate=DateTime.Now.Date; // Sanity check. If the given date is not today then ask the user to confirm if (currentDate != startDate.Date) { Console.WriteLine(String.Format("Run date is not today, please confirm Y/N:{0}?",startDate.ToShortDateString())); String result=Console.ReadLine(); if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES")))return; } 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}), please confirm Y/N:{1}?",description,startDate.ToShortDateString())); String result=Console.ReadLine(); if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES"))) return; } 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; } Utility.RemoveLogFiles(); int STAGE_1=0,STAGE_FINAL=2; DeletePriceWatchList("valuations",startDate.ToShortDateString()); DeletePriceWatchList("Momentum",startDate.ToShortDateString()); ManualResetEvent[] resetEvents = new ManualResetEvent[STAGE_FINAL+1]; for(int index=0;index manualResetEventsList = resetEvents.ToList(); manualResetEventsList.Remove(resetEvents[STAGE_FINAL]); // Remove THIS thread from the events we will wait on..no sense waiting on ourselves ManualResetEvent[] allResetEventsSans12 = manualResetEventsList.ToArray(); bool running = true; bool connectionIssue = false; SMSClient.SendSMSEmail("UPDATEDAILYPRICES Network monitor activated", smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); while (running) { if (!NetworkStatus.IsInternetConnected()) { connectionIssue = true; SMSClient.SendSMSEmail("UPDATEDAILYPRICES Network is not connected", smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); } else if (connectionIssue) { connectionIssue = false; SMSClient.SendSMSEmail("UPDATEDAILYPRICES There was a network connection issue.", smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); } if (WaitHandle.WaitAll(allResetEventsSans12, 30000)) running = false; // if all worker threads are done then wrap it up here. } SMSClient.SendSMSEmail("UPDATEDAILYPRICES Network monitor ended", smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); resetEvents[STAGE_FINAL].Set(); }); // Here is the start of the real workers ThreadPool.QueueUserWorkItem(delegate { UpdatePricesBigCharts(startDate); // bigcharts.marketwatch.com UpdatePricesYahooSweep(startDate); // The sweep variation of the method is intended to be used after the BigCharts update because the sweep will take pricing_source into consideration when fetching prices. resetEvents[STAGE_1].Set(); SMSClient.SendSMSEmail("UPDATEDAILYPRICES UPDATEPRICESBIGCHARTS/YAHOO done.", smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); }); resetEvents[STAGE_1].WaitOne(); // wait for pricing to finish WaitHandle.WaitAll(resetEvents); } // ************************************************************************************************************************************************************************************* // **************************************************************************** U P D A T E D A I L Y 2 ******************************************************************************* // ************************************************************************************************************************************************************************************* public static void UpdateDaily2(DateTime startDate) { DateGenerator dateGenerator=new DateGenerator(); String smsSMTPAddress = ConfigurationManager.AppSettings["sms_smtpaddress"]; String smsUserName = ConfigurationManager.AppSettings["sms_smsusername"]; String smsPassword = ConfigurationManager.AppSettings["sms_smspassword"]; String[] smsRecipients = ConfigurationManager.AppSettings["sms_smsrecipients"].Split(','); DateTime currentDate=DateTime.Now.Date; // Sanity check. If the given date is not today then ask the user to confirm if (currentDate != startDate.Date) { Console.WriteLine(String.Format("Run date is not today, please confirm Y/N:{0}?",startDate.ToShortDateString())); String result=Console.ReadLine(); if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES")))return; } 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}), please confirm Y/N:{1}?",description,startDate.ToShortDateString())); String result=Console.ReadLine(); if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES"))) return; } 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; } Utility.RemoveLogFiles(); int STAGE_1=0,STAGE_2=1,STAGE_3=2,STAGE_4=3,STAGE_5=4,STAGE_6=5,STAGE_7=6,STAGE_8=7,STAGE_9=8,STAGE_10=9,STAGE_11=10,STAGE_12=11,STAGE_FINAL=12; DeletePriceWatchList("valuations",startDate.ToShortDateString()); DeletePriceWatchList("Momentum",startDate.ToShortDateString()); ManualResetEvent[] resetEvents = new ManualResetEvent[STAGE_FINAL+1]; for(int index=0;index manualResetEventsList = resetEvents.ToList(); manualResetEventsList.Remove(resetEvents[STAGE_FINAL]); // Remove THIS thread from the events we will wait on..no sense waiting on ourselves ManualResetEvent[] allResetEventsSans12 = manualResetEventsList.ToArray(); bool running = true; bool connectionIssue = false; SMSClient.SendSMSEmail("UPDATEDAILY2 Network monitor activated", smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); while (running) { if (!NetworkStatus.IsInternetConnected()) { connectionIssue = true; SMSClient.SendSMSEmail("UPDATEDAILY2 Network is not connected", smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); } else if (connectionIssue) { connectionIssue = false; SMSClient.SendSMSEmail("UPDATEDAILY2 There was a network connection issue.", smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); } if (WaitHandle.WaitAll(allResetEventsSans12, 30000)) running = false; // if all worker threads are done then wrap it up here. } SMSClient.SendSMSEmail("UPDATEDAILY2 Network monitor ended", smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); resetEvents[STAGE_FINAL].Set(); }); // Here is the start of the real workers ThreadPool.QueueUserWorkItem(delegate { UpdatePricesBigCharts(startDate); // bigcharts.marketwatch.com UpdatePricesYahooSweep(startDate); // The sweep variation of the method is intended to be used after the BigCharts update because the sweep will take pricing_source into consideration when fetching prices. resetEvents[STAGE_1].Set(); SMSClient.SendSMSEmail("UPDATEDAILY2 UPDATEPRICESBIGCHARTS/YAHOO done.", smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); }); resetEvents[STAGE_1].WaitOne(); // wait for pricing to finish ThreadPool.QueueUserWorkItem(delegate { LoadConsumerPriceIndex(); // Load consumer price index data from Bureau of Labor Statistics UpdateCompanyProfiles(); // financials.morningstar.com and finance.yahoo.com LoadGDPPerCapita(); // api.worldbank.org resetEvents[STAGE_2].Set(); }); ThreadPool.QueueUserWorkItem(delegate { UpdateYieldCurve(); // www.treasury.gov resetEvents[STAGE_3].Set(); }); ThreadPool.QueueUserWorkItem(delegate { UpdateLatestAnalystRatings(true); // WWW.BRIEFING.COM UpdateMissingAnalystRatings(); // MARKET BEAT resetEvents[STAGE_4].Set(); }); ThreadPool.QueueUserWorkItem(delegate { UpdateSplits(); // eoddata.com ProcessAllSplits(); // non-network operation resetEvents[STAGE_5].Set(); }); ThreadPool.QueueUserWorkItem(delegate { LoadInsiderTransactions(); // InsiderTracking stopped working so this source is now going directly to SEC.GOV. www.insidertracking.com resetEvents[STAGE_6].Set(); }); ThreadPool.QueueUserWorkItem(delegate { UpdateEarningsAnnouncements(); // www.zacks.com LoadZacksRank(); // www.zacks.com resetEvents[STAGE_7].Set(); }); ThreadPool.QueueUserWorkItem(delegate { GetSECFilingsWatchList("Valuations");// www.sec.gov resetEvents[STAGE_8].Set(); }); ThreadPool.QueueUserWorkItem(delegate { UpdateAnalystPriceTarget(); // finance.yahoo.com GetETFHoldings(); // finance.yahoo.com resetEvents[STAGE_9].Set(); }); ThreadPool.QueueUserWorkItem(delegate { UpdateAllMissingCIK(); // /www.sec.gov resetEvents[STAGE_10].Set(); }); ThreadPool.QueueUserWorkItem(delegate { UpdateDividendHistory(); // www.nasdaq.com DIVIDEND HISTORY IS BROKEN.... WORKING ON THIS ONE. resetEvents[STAGE_11].Set(); }); ThreadPool.QueueUserWorkItem(delegate { // UpdateOptionsChainsWatchList("valuations"); // www.nasdaq.com OPTIONS CHAINS ARE NOT WORKING : THIS NEEDS TO BE OBSOLETED resetEvents[STAGE_12].Set(); }); WaitHandle.WaitAll(resetEvents); } // ************************************************************************************************************************* // *********************************************** U P D A T E A L L ************************************************ // ************************************************************************************************************************* public static void UpdateAll() { try { //UpdateMissingAnalystRatings(); // runs daily as well UpdatePrices(); GetMissingPrices(); UpdateEarningsAnnouncements(); // runs daily as well LoadFundamentals(); LoadFinancialStatements(); LoadHistorical(); LoadInsiderTransactions(); // runs daily as well UpdateYieldCurve(); // runs daily as well UpdateAllMissingCIK(); // runs daily as well UpdateDividendHistory(); // runs daily as well //UpdateAnalystRatings(null, true); // runs daily as well UpdateLatestAnalystRatings(true); UpdateCompanyProfiles(); // runs daily as well UpdateSECFilings(); GetETFHoldings(); // runs daily as well LoadGDPPerCapita(); // runs daily as well UpdateOptionsChains(); UpdateAnalystPriceTarget(); // runs daily as well CalcSticker(); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } public static void UpdateAllNoPrices() { try { //UpdateMissingAnalystRatings(); LoadFundamentals(); LoadFinancialStatements(); LoadHistorical(); CalcSticker(); LoadInsiderTransactions(); UpdateYieldCurve(); UpdateAllMissingCIK(); UpdateDividendHistory(); UpdateLatestAnalystRatings(true); //UpdateAnalystRatings(null, true); UpdateCompanyProfiles(); UpdateSECFilings(); GetETFHoldings(); LoadGDPPerCapita(); UpdateOptionsChains(); UpdateAnalystPriceTarget(); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } // ************************************************************************************************************************* // *********************************************** Z A C K S R A N K ************************************************ // ************************************************************************************************************************* public static void LoadZacksRank() { ZacksRankMarketDataHelper zacksRankMarketDataHelper=new ZacksRankMarketDataHelper(); zacksRankMarketDataHelper.LoadZacksRank(); } public static void LoadZacksRank(String symbol) { ZacksRankMarketDataHelper zacksRankMarketDataHelper=new ZacksRankMarketDataHelper(); zacksRankMarketDataHelper.LoadZacksRank(symbol); } // ************************************************************************************************************************* // *********************************************** D I V I D E N D H I S T O R Y ************************************************ // ************************************************************************************************************************* public static void UpdateDividendHistory(String symbol) { DividendHistoryMarketDataHelper dividendHistoryMarketDataHelper=new DividendHistoryMarketDataHelper(); dividendHistoryMarketDataHelper.UpdateDividendHistory(symbol); } public static void UpdateDividendHistory() { DividendHistoryMarketDataHelper dividendHistoryMarketDataHelper=new DividendHistoryMarketDataHelper(); dividendHistoryMarketDataHelper.UpdateDividendHistory(); } // ***************************************************************************************************************************** // *************************************************** A N A L Y S T P R I C E T A R G E T ******************************* // ***************************************************************************************************************************** public static void UpdateAnalystPriceTarget() { MDTrace.WriteLine(LogLevel.DEBUG,"[UPDATEANALYSTPRICETARGET]"); AnalystPriceTargetMarketDataHelper analystPriceTargetMarketDataHelper=new AnalystPriceTargetMarketDataHelper(); analystPriceTargetMarketDataHelper.LoadAnalystPriceTarget(); MDTrace.WriteLine(LogLevel.DEBUG,"[UPDATEANALYSTPRICETARGET] Done"); } // ***************************************************************************************************************************** // *************************************************** A N A L Y S T R A T I N G S ***************************************** // ***************************************************************************************************************************** public static void UpdateMissingAnalystRatings() { try { DateGenerator dateGenerator = new DateGenerator(); List symbols = PricingDA.GetSymbols(); DateTime maxDate=AnalystRatingsDA.GetMaxDateNoZacks(); foreach (String symbol in symbols) { AnalystRatings analystRatings = MarketDataHelper.GetAnalystRatingsMarketBeat(symbol); if (null == analystRatings || 0 == analystRatings.Count) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("No analyst ratings for {0}", symbol)); continue; } analystRatings = new AnalystRatings((from AnalystRating analystRating in analystRatings where analystRating.Date >= maxDate.Date select analystRating).ToList()); AnalystRatings duplicateList = new AnalystRatings(); foreach (AnalystRating analystRating in analystRatings) { if (AnalystRatingsDA.ContainsAnalystRating(analystRating)) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Already have analyst rating for {0} on {1} from brokerage firm {2}", analystRating.Symbol, analystRating.Date.ToShortDateString(), analystRating.BrokerageFirm)); duplicateList.Add(analystRating); continue; } } analystRatings = new AnalystRatings(analystRatings.Except(duplicateList).ToList()); foreach (AnalystRating analystRating in analystRatings) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Inserting Analyst Rating for {0} on {1} from brokerage firm {2}", analystRating.Symbol, analystRating.Date.ToShortDateString(), analystRating.BrokerageFirm)); } AnalystRatingsDA.InsertAnalystRatings(analystRatings); } } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG, exception); } } public static void UpdateAnalystRatings(String paramSymbol = null,DateTime? minDate=null) { try { MDTrace.WriteLine(LogLevel.DEBUG, "[UPDATEANALYSTRATINGS]"); List symbols = new List(); if (paramSymbol == null) symbols = PricingDA.GetSymbols(); else symbols.Add(paramSymbol); foreach (String symbol in symbols) { AnalystRatings analystRatings = MarketDataHelper.GetAnalystRatingsMarketBeat(symbol); if (null == analystRatings || 0 == analystRatings.Count) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("No analyst ratings for {0}", symbol)); continue; } AnalystRatings duplicateList = new AnalystRatings(); if (null != minDate) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Minimum Rating Date of {0} is specified.", minDate.Value.ToShortDateString())); analystRatings = new AnalystRatings((from AnalystRating analystRating in analystRatings where analystRating.Date >= minDate.Value select analystRating).ToList()); } foreach (AnalystRating analystRating in analystRatings) { if (AnalystRatingsDA.ContainsAnalystRating(analystRating)) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Already have analyst rating for {0} on {1} from brokerage firm {2}", analystRating.Symbol, analystRating.Date.ToShortDateString(), analystRating.BrokerageFirm)); duplicateList.Add(analystRating); continue; } } analystRatings = new AnalystRatings(analystRatings.Except(duplicateList).ToList()); foreach (AnalystRating analystRating in analystRatings) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Inserting Analyst Rating for {0} on {1} from brokerage firm {2}", analystRating.Symbol, analystRating.Date.ToShortDateString(), analystRating.BrokerageFirm)); } AnalystRatingsDA.InsertAnalystRatings(analystRatings); } } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG, exception); } finally { MDTrace.WriteLine(LogLevel.DEBUG, "[UPDATEANALYSTRATINGS]"); } } public static void UpdateLatestAnalystRatings(Boolean createSecurityMaster = true) { try { DateGenerator dateGenerator = new DateGenerator(); MDTrace.WriteLine(LogLevel.DEBUG, "[UPDATELATESTANALYSTRATINGS]"); AnalystRatings analystRatings = MarketDataHelper.GetLatestAnalystRatings(); List symbols = PricingDA.GetSymbolsNotIn(analystRatings.Symbols); foreach (String symbol in symbols) { if (false == createSecurityMaster) { MDTrace.WriteLine(LogLevel.DEBUG, "Removing " + symbol + ", missing from security master."); AnalystRating analystRating = (from item in analystRatings where item.Symbol.Equals(symbol) select item).FirstOrDefault(); if (null != analystRating) MDTrace.WriteLine(LogLevel.DEBUG, analystRating.ToString()); } } MDTrace.WriteLine(LogLevel.DEBUG, "*************************"); if (false == createSecurityMaster) analystRatings.Remove(symbols); foreach (AnalystRating analystRating in analystRatings) { String symbolNotFound = (from symbol in symbols where symbol.Equals(analystRating.Symbol) select symbol).FirstOrDefault(); if (null != symbolNotFound && createSecurityMaster) { MDTrace.WriteLine(LogLevel.DEBUG, "Adding security '" + analystRating.Symbol + "' '" + analystRating.CompanyName + "'"); if (!PricingDA.AddSecurity(analystRating.Symbol, analystRating.CompanyName)) MDTrace.WriteLine(LogLevel.DEBUG, "Failed to add '" + symbols + "'"); else { MDTrace.WriteLine(LogLevel.DEBUG, "Added '" + analystRating.Symbol + "'"); MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Loading prices for {0}", analystRating.Symbol)); DateTime pricingDate = dateGenerator.FindPrevBusinessDay(analystRating.Date); Prices prices = MarketDataHelper.GetDailyPrices(analystRating.Symbol, Constants.MIN_PRICING_DATE, pricingDate); // use the Yahoo JSON bulk feed if (null != prices) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Inserting {0} prices for {1}", prices.Count, analystRating.Symbol)); PricingDA.InsertPrices(prices); MDTrace.WriteLine(LogLevel.DEBUG, "Done."); } } } MDTrace.WriteLine(LogLevel.DEBUG, analystRating.ToString()); } AnalystRatingsDA.InsertAnalystRatings(analystRatings); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG, exception); } } // ************************************************************************************************************************* // *********************************************** O P T I O N S D A T A ************************************************ // ************************************************************************************************************************* public static void UpdateOptionsChainsWatchList(String watchList) // get options chains from NASDAQ { try { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("UpdateOptionsChainWatchList {0}",watchList)); List symbols = WatchListDA.GetWatchList(watchList); OptionsChainsMarketDataHelper optionsChainsMarketDataHelper = new OptionsChainsMarketDataHelper(); optionsChainsMarketDataHelper.LoadOptionsChains(symbols); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } public static void UpdateOptionsChains() // get options chains from NASDAQ { try { List symbols = PricingDA.GetSymbols(); OptionsChainsMarketDataHelper optionsChainsMarketDataHelper = new OptionsChainsMarketDataHelper(); optionsChainsMarketDataHelper.LoadOptionsChains(symbols); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } public static void UpdateOptionsChains(String symbol) // get options chains from NASDAQ { try { if (null == symbol) return; if(!symbol.Contains(',')) { symbol = symbol.ToUpper(); OptionsChainsMarketDataHelper optionsChainsMarketDataHelper = new OptionsChainsMarketDataHelper(); optionsChainsMarketDataHelper.LoadOptionsChains(symbol); } else { String[] symbolArray=symbol.Split(','); List symbols=symbolArray.ToList(); for(int index=0;index symbols = PricingDA.GetSymbols(); for(int index=0;index symbols = WatchListDA.GetWatchList(watchListName); PricingMarketDataHelper pricingMarketDataHelper=new PricingMarketDataHelper(); pricingMarketDataHelper.UpdateLatestPrices(symbols); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void UpdateLatestPriceOpenPositions() { try { PortfolioTrades portfolioTrades=PortfolioDA.GetOpenTrades(); List symbols=(from PortfolioTrade portfolioTrade in portfolioTrades select portfolioTrade.Symbol).Distinct().ToList(); if(symbols.Any(x=>x.Equals("SPY")))symbols.Add("SH"); PricingMarketDataHelper pricingMarketDataHelper=new PricingMarketDataHelper(); pricingMarketDataHelper.UpdateLatestPrices(symbols); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void DeletePriceWatchList(String watchListName,String strDate) { try { List symbols = WatchListDA.GetWatchList(watchListName); if(null==symbols||0==symbols.Count) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("There are no symbols for watchlist {0}",watchListName)); return; } foreach (String symbol in symbols) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Delete price {0} on {1}, watchlist {2}",symbol,strDate,watchListName)); DeletePriceSymbol(symbol, strDate); } } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void RollPriceForward(String symbol,DateTime fromDate,DateTime toDate) { try { DateGenerator dateGenerator=new DateGenerator(); if(!PricingDA.CheckPricingOn(symbol,fromDate)) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("There is no price for {0} on {1}",symbol,fromDate.ToShortDateString())); return; } if(PricingDA.CheckPricingOn(symbol,toDate)) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("There is already a price for {0} on {1}",symbol,toDate.ToShortDateString())); return; } if(!dateGenerator.IsMarketOpen(toDate)) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("The market is not open on {0}",toDate.ToShortDateString())); return; } Price price=PricingDA.GetPrice(symbol,fromDate); price.Date=toDate; MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Rolling forward price for {0}. Source date is {1} destination date is {2}",symbol,fromDate.ToShortDateString(),toDate.ToShortDateString())); PricingDA.InsertPrice(price); } catch(Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void FindAllSymbolsMissingPriceOn(DateTime date,bool rollForward=false,String strFilter=null) { int countOfValid=0; int countOfInvalid=0; DateGenerator dateGenerator=new DateGenerator(); try { if(null!=strFilter)strFilter=strFilter.ToUpper(); List symbols=PricingDA.GetSymbols(); if(null==symbols||0==symbols.Count) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("There are no symbols. Nothing to do.")); return; } foreach (String symbol in symbols) { DateTime previousBusinessDate=dateGenerator.FindPrevBusinessDay(date); bool hasPriceOnPreviousBusinessDate=PricingDA.CheckPricingOn(symbol,previousBusinessDate); bool hasPriceOnDate=PricingDA.CheckPricingOn(symbol,date); if(hasPriceOnDate && hasPriceOnPreviousBusinessDate) { countOfValid++; } else if(!hasPriceOnDate && !hasPriceOnPreviousBusinessDate) { countOfInvalid++; } else if(!hasPriceOnDate && hasPriceOnPreviousBusinessDate) { countOfInvalid++; MDTrace.WriteLine(LogLevel.DEBUG,String.Format("No price for {0} on {1}.",symbol,date.ToShortDateString())); if(rollForward) { if(null!=strFilter && !strFilter.Equals(symbol))continue; Price price=PricingDA.GetPrice(symbol,previousBusinessDate); price.Date=date; MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Rolling forward price for {0}. Source date is {1} destination date is {2}",symbol,previousBusinessDate.ToShortDateString(),date.ToShortDateString())); PricingDA.InsertPrice(price); } } else if(hasPriceOnDate && !hasPriceOnPreviousBusinessDate) { countOfValid++; } } MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Symbols with price {0}, Symbols without price {1}.",countOfValid,countOfInvalid)); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } //****************************************************************************************************************** public static void AddPrice(String symbol,DateTime pricingDate,double open,double high,double low,double close,long volume) { try { Price price=new Price(); price.Symbol=symbol; price.Date=pricingDate; price.Open=open; price.High=high; price.Low = low; price.Close = close; price.AdjClose = close; price.Volume = volume; MDTrace.WriteLine(LogLevel.DEBUG,"Delete price '" + symbol + "' for " + Utility.DateTimeToStringMMSDDSYYYY(pricingDate)); PricingDA.DeletePrice(symbol, pricingDate); MDTrace.WriteLine(LogLevel.DEBUG,"Add price "+price.ToString()); if (!PricingDA.InsertPrice(price)) MDTrace.WriteLine(LogLevel.DEBUG,"Error adding price for '" + symbol+"'"); else MDTrace.WriteLine(LogLevel.DEBUG,"Price added for '"+symbol+"'"); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } public static void DeletePriceSymbol(String symbol, String strDate) { try { DateTime pricingDate = DateTime.Parse(strDate); MDTrace.WriteLine(LogLevel.DEBUG,"Delete price '" + symbol + "' for " + Utility.DateTimeToStringMMSDDSYYYY(pricingDate)); if(PricingDA.DeletePrice(symbol, pricingDate)) MDTrace.WriteLine(LogLevel.DEBUG,"Ok"); else MDTrace.WriteLine(LogLevel.DEBUG,"Failed."); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } public static void LoadAllPricesSymbol(String symbol) { 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)prices=MarketDataHelper.GetPricesAsOf(symbol,startDate,endDate); if (null == prices || 0==prices.Count) // if less than 252 days of prices then forget it { 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."); } public static void ShowAllPricesSymbol(String symbol) { 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 less than 252 days of prices then forget it { MDTrace.WriteLine(LogLevel.DEBUG,"No prices for '" + symbol + "'"); return; } MDTrace.WriteLine(LogLevel.DEBUG,Price.Header); for (int secIndex = 0; secIndex < prices.Count; secIndex++) { MDTrace.WriteLine(LogLevel.DEBUG,prices[secIndex].ToString()); } MDTrace.WriteLine(LogLevel.DEBUG,"Done."); } public static void LoadAllPricesSymbolDate(String symbol,DateTime startDate) { DateTime endDate = DateTime.Now; Prices prices=MarketDataHelper.GetDailyPrices(symbol,startDate,endDate); // use the Yahoo JSON bulk feed //if(null==prices||0==prices.Count)prices=MarketDataHelper.GetPricesAsOf(symbol,startDate,endDate); if (null == prices || 0==prices.Count) // if less than 252 days of prices then forget it { 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."); } public static void LoadAllPricesWatchList(String watchListName) { List symbols = WatchListDA.GetWatchList(watchListName); for (int index = 0; index < symbols.Count; index++) { DateTime startDate=Constants.MIN_PRICING_DATE; DateTime endDate=DateTime.Now; Prices prices = MarketDataHelper.GetDailyPrices(symbols[index], startDate, endDate); if (null == prices) { MDTrace.WriteLine(LogLevel.DEBUG,"No prices for '" + symbols[index] + "'"); continue; } else { 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."); } } } public static void UpdatePricesAndYield() { UpdatePrices(); UpdateYieldCurve(); } public static void UpdatePrices() { List symbols=PricingDA.GetSymbols(); PricingMarketDataHelper pricingMarketDataHelper=new PricingMarketDataHelper(); pricingMarketDataHelper.LoadPrices(symbols); } public static void UpdatePricesDate(String strDate) { DateTime pricingDate = DateTime.Parse(strDate); List symbols = PricingDA.GetSymbols(); for (int index = 0; index < symbols.Count; index++) { Prices prices = MarketDataHelper.GetDailyPrices(symbols[index], pricingDate, pricingDate); if (null == prices) { MDTrace.WriteLine(LogLevel.DEBUG,"No prices for '" + symbols[index] + "' on "+Utility.DateTimeToStringMMSDDSYYYY(pricingDate)); continue; } else { 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."); } } } public static void UpdatePricesSymbol(String symbol) { DateGenerator dateGenerator = new DateGenerator(); DateTime startDate = DateTime.Now; // the lest recent date DateTime endDate = DateTime.Now; // the most recent date endDate = dateGenerator.GetPrevBusinessDay(endDate); startDate = PricingDA.GetLatestDate(symbol); startDate = dateGenerator.FindNextBusinessDay(startDate); if (startDate.Date > endDate.Date) { MDTrace.WriteLine(LogLevel.DEBUG,"Already have latest price for '" + symbol + "'"); return; } Prices prices = MarketDataHelper.GetDailyPrices(symbol, startDate, endDate); if (null == prices) { MDTrace.WriteLine(LogLevel.DEBUG,"No prices for '" + symbol + "'"); return; } else { 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."); } } public static void GetMissingPrices(DateTime? marketDate=null) { PricingMarketDataHelper pricingMarketDataHelper=new PricingMarketDataHelper(); pricingMarketDataHelper.GetMissingPrices(marketDate); } public static void GetMissingPricesSymbol(String symbol) { PricingMarketDataHelper pricingMarketDataHelper=new PricingMarketDataHelper(); pricingMarketDataHelper.GetMissingPricesSymbol(symbol); } // ***************************************************************************************************************************** // ************************************************ H I S T O R I C A L D A T A ********************************************* // ***************************************************************************************************************************** public static void LoadHistorical(String symbol) { HistoricalMarketDataHelper historicalMarketDataHelper=new HistoricalMarketDataHelper(); historicalMarketDataHelper.LoadHistorical(symbol); } public static void LoadHistorical() { HistoricalMarketDataHelper historicalMarketDataHelper=new HistoricalMarketDataHelper(); historicalMarketDataHelper.LoadHistorical(); } // ******************************************************************************************************************************* //****************************************F U N D A M E N T A L D A T A ************************************************ // ******************************************************************************************************************************* public static void LoadFundamentals() { FundamentalMarketDataHelper fundamentalMarketDataHelper=new FundamentalMarketDataHelper(); fundamentalMarketDataHelper.LoadFundamentals(); } public static void LoadFundamental(String symbol) { FundamentalMarketDataHelper fundamentalMarketDataHelper=new FundamentalMarketDataHelper(); fundamentalMarketDataHelper.LoadFundamentals(symbol); } public static void LoadFundamentalsFinViz() { FundamentalMarketDataHelper fundamentalMarketDataHelper=new FundamentalMarketDataHelper(); fundamentalMarketDataHelper.LoadFundamentalsFinViz(); } public static void LoadFundamentalFinViz(String symbol) { FundamentalMarketDataHelper fundamentalMarketDataHelper=new FundamentalMarketDataHelper(); fundamentalMarketDataHelper.LoadFundamentalsFinViz(symbol); } // ******************************************************************************************************************************* // ************************************ I N C O M E S T A T E M E N T A N D B A L A N C E S H E E T**************************** // ******************************************************************************************************************************* public static void LoadFinancialStatements() { FinancialStatementsMarketDataHelper financialStatementsMarketDataHelper=new FinancialStatementsMarketDataHelper(); financialStatementsMarketDataHelper.LoadFinancialStatements(); } public static void LoadFinancialStatementsSymbol(String symbol) { FinancialStatementsMarketDataHelper financialStatementsMarketDataHelper=new FinancialStatementsMarketDataHelper(); financialStatementsMarketDataHelper.LoadFinancialStatements(symbol); } // ******************************************************************************************************************************* // **************************************************** M A C D A N A L Y S I S ************************************************ // ******************************************************************************************************************************* public static void RunPivots(String symbol, int dayCount) { try { Prices prices = PricingDA.GetPrices(symbol,dayCount); MDTrace.WriteLine(LogLevel.DEBUG,ResistanceSupport.Header); for (int index = 0; index < prices.Count; index++) { ResistanceSupport resistanceAndSupport = new ResistanceSupport(prices[index]); MDTrace.WriteLine(LogLevel.DEBUG,resistanceAndSupport.ToString()); } } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void GenerateMovingAverageSheet(String strFileTemplate,String symbol) { try { String currentWorkingDirectory = Directory.GetCurrentDirectory(); MDTrace.WriteLine(LogLevel.DEBUG,"GenerateMovingAverageSheet " + currentWorkingDirectory + "\\" + strFileTemplate + " for " + symbol ); MovingAverageHelperSheet.GenerateMovingAverageSheet(currentWorkingDirectory + "\\" + strFileTemplate, symbol); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void RunMACDSignalSymbol(String symbol,String macd="MACD(8,17,9)") { DateGenerator dateGenerator = new DateGenerator(); int pricingDays = 120; // 90 try { DateTime startDate = PricingDA.GetLatestDate(symbol); ; if (Utility.IsEpoch(startDate)) { MDTrace.WriteLine(LogLevel.DEBUG,"No price dates for '" + symbol + "'"); return; } DateTime historicalDate = dateGenerator.GenerateHistoricalDate(startDate, pricingDays); Prices prices = PricingDA.GetPrices(symbol, startDate, historicalDate); String companyName = PricingDA.GetNameForSymbol(symbol); MACDSetup macdSetup = new MACDSetup(macd); MACDSignals macdSignals = MACDGenerator.GenerateMACD(prices, macdSetup); MDTrace.WriteLine(LogLevel.DEBUG,"Company:" + Utility.AddQuotes(companyName)); Signals signals = SignalGenerator.GenerateSignals(macdSignals); MDTrace.WriteLine(LogLevel.DEBUG,"Symbol,Date,Indicator,Reason"); StringBuilder sb = new StringBuilder(); for (int index = 0; index < signals.Count; index++) { Signal signal = signals[index]; sb.Append(symbol).Append(","); sb.Append(Utility.DateTimeToStringMMHDDHYYYY(signal.SignalDate)).Append(","); sb.Append(signal.SignalIndicatorString).Append(","); sb.Append(Utility.AddQuotes(signal.Reason)); MDTrace.WriteLine(LogLevel.DEBUG,sb.ToString()); sb.Clear(); } } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } //************************************************************************************************************************ //********************************************** S I G N A L T R A D E ************************************************** //************************************************************************************************************************ public static void TradeSymbol(String symbol,int shares,DateTime startDate,int holdingDays) { DateGenerator dateGenerator = new DateGenerator(); DateTime endDate = DateTime.Now; startDate = dateGenerator.GetNextBusinessDay(startDate); endDate=dateGenerator.FindForwardBusinessDay(startDate,holdingDays-1); Price startPrice = PricingDA.GetPrice(symbol,startDate); Price endPrice = PricingDA.GetPrice(symbol, endDate); double beginMarketValue = 0.00; double endMarketValue = 0.00; if (null == endPrice) { MDTrace.WriteLine(LogLevel.DEBUG,"Ending price is not available on " + Utility.DateTimeToStringMMHDDHYYYY(endDate)); endPrice = PricingDA.GetPrice(symbol); endDate = endPrice.Date; MDTrace.WriteLine(LogLevel.DEBUG,"Using latest available price " + Utility.DateTimeToStringMMHDDHYYYY(endPrice.Date)); } if (null == startPrice) { MDTrace.WriteLine(LogLevel.DEBUG,"Starting price is not available on " + Utility.DateTimeToStringMMHDDHYYYY(startDate)); return; } MDTrace.WriteLine(LogLevel.DEBUG, ""); MDTrace.WriteLine(LogLevel.DEBUG,"Buy " + shares + " " + symbol + " @ " + Utility.FormatCurrency(startPrice.Open) + " on " + Utility.DateTimeToStringMMHDDHYYYY(startDate)); MDTrace.WriteLine(LogLevel.DEBUG,"Sell " + shares + " " + symbol + " @ " + Utility.FormatCurrency(endPrice.Close) + " on "+Utility.DateTimeToStringMMHDDHYYYY(endDate)); beginMarketValue = shares * startPrice.Open; endMarketValue = shares * endPrice.Close; MDTrace.WriteLine(LogLevel.DEBUG,"Beginning market value:"+Utility.FormatNumber(beginMarketValue)); MDTrace.WriteLine(LogLevel.DEBUG,"Ending market value:" + Utility.FormatNumber(endMarketValue)); MDTrace.WriteLine(LogLevel.DEBUG,"Gain/Loss:" + Utility.FormatNumber(endMarketValue - beginMarketValue)); MDTrace.WriteLine(LogLevel.DEBUG,"Return:" + Utility.FormatNumber(((endMarketValue - beginMarketValue) / beginMarketValue)*100.00)+"%"); } // ***************************************** T R A D E S I G N A L W A T C H L I S T ********************** public static void TradeSignalWatchListDateProgressHandler(String symbol) { MDTrace.WriteLine(LogLevel.DEBUG,"Working on "+symbol); } // *************************************************************************************************************** public static void CalcPortfolioBeta(String account=null) { try { DateTime analysisDate = DateTime.Now; PortfolioTrades portfolioTrades = PortfolioDA.GetOpenTrades(); if (null != account) portfolioTrades = portfolioTrades.FilterAccount(account); PortfolioHoldings portfolioHoldings = PortfolioHoldings.GetPortfolioHoldings(portfolioTrades, 1, analysisDate); PortfolioHoldingsWithBeta portfolioHoldingsWithBeta = new PortfolioHoldingsWithBeta(portfolioHoldings, analysisDate); MDTrace.WriteLine("Holding,Weight,Beta,Weighted Beta,Contribution To Beta"); foreach (PortfolioHoldingWithBeta portfolioHoldingWithBeta in portfolioHoldingsWithBeta) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("{0},{1},{2},{3},{4}", portfolioHoldingWithBeta.Symbol, Utility.FormatNumber(portfolioHoldingWithBeta.WeightExp, 2), Utility.FormatNumber(portfolioHoldingWithBeta.Beta, 2), Utility.FormatNumber(portfolioHoldingWithBeta.WeightedBeta, 4), Utility.FormatPercent(portfolioHoldingWithBeta.BetaContribution))); } MDTrace.WriteLine(LogLevel.DEBUG, String.Format("36 month portfolio beta is {0}", Utility.FormatNumber(portfolioHoldingsWithBeta.PortfolioBeta, 2))); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG, exception.ToString()); } } public static void CalcBeta(String symbol) { try { double beta = BetaGenerator.Beta(symbol); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("36 month beta for {0} is {1}", symbol, beta)); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } public static void CalcBetaAll() { try { MDTrace.WriteLine(LogLevel.DEBUG,"Symbol,Beta,Months"); List symbols = PricingDA.GetSymbols(); for (int index = 0; index < symbols.Count; index++) { String symbol = symbols[index]; double beta = BetaGenerator.Beta(symbol); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("{0},{1},{2}", symbol,beta,36)); } } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } //**************************************************************************************************************************** //**************************************************************************************************************************** //*************************************************** D I S C O U N T E D C A S H F L O W M O D E L ************************ //**************************************************************************************************************************** public static void CalcDCF() { try { MDTrace.WriteLine(LogLevel.DEBUG,"Generating valuations.."); List symbols = PricingDA.GetSymbols(); MDTrace.WriteLine(LogLevel.DEBUG,DCFValuation.Header); foreach(String symbol in symbols) { DCFValuation dcfValuation = DCFGenerator.GenerateDCFValuation(symbol); MDTrace.WriteLine(LogLevel.DEBUG,dcfValuation.ToString()); } MDTrace.WriteLine(LogLevel.DEBUG,"Done."); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } //**************************************************************************************************************************** //*************************************************** S T I C K E R P R I C E *********************************************** //**************************************************************************************************************************** public static void FindETFMOS() { try { List etfSymbols=ETFHoldingsDA.GetETFSymbols(); List etfsInMOS=new List(); foreach(String symbol in etfSymbols) { ETFHoldings etfHoldings = ETFHoldingsDA.GetETFHoldings(symbol); if(null==etfHoldings||0==etfHoldings.Count) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("ETF {0} has no holdings.",symbol)); return; } List symbolsInETF=(from ETFHolding etfHolding in etfHoldings select etfHolding.HoldingSymbol).ToList(); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Generating valuation for ETF {0}",symbol)); Valuations valuations= ValuationGenerator.GenerateValuations(symbolsInETF,null,null); if(null==valuations||0==valuations.Count)continue; int countMOSInLine=0; foreach(Valuation valuation in valuations) { if(!(valuation.LatestPrice<=valuation.MOS))continue; countMOSInLine++; } if(countMOSInLine.Equals(etfHoldings.Count)) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Adding ETF {0}",symbol)); etfsInMOS.Add(symbol); } } MDTrace.WriteLine("**************************************************"); foreach(String etfSymbol in etfsInMOS) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("ETF {0}",etfSymbol)); } MDTrace.WriteLine(LogLevel.DEBUG,"Done."); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } public static void CalcStickerETF(String symbol) { try { ETFHoldings etfHoldings = ETFHoldingsDA.GetETFHoldings(symbol); if(null==etfHoldings||0==etfHoldings.Count) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("ETF {0} has no holdings.",symbol)); return; } List etfSymbols=(from ETFHolding etfHolding in etfHoldings select etfHolding.HoldingSymbol).ToList(); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Generating valuation for ETF {0}",symbol)); Valuations valuations= ValuationGenerator.GenerateValuations(etfSymbols,new ValuationGenerator.OnItemCompleteHandler(OnItemCompleteHandler),new ValuationGenerator.OnErrorItemHandler(OnErrorItemHandler)); foreach(Valuation valuation in valuations) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("{0},{1},{2}",valuation.Symbol,Utility.FormatCurrency(valuation.LatestPrice),Utility.FormatCurrency(valuation.MOS))); } MDTrace.WriteLine(LogLevel.DEBUG,"Done."); } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); } } public static void CalcAcquirersMultiple() { MDTrace.WriteLine("Generating aqcuirers multiple valuations..."); AcquirersMultipleCollection collection=AcquirersMultipeGenerator.ApplyRanks(); MDTrace.WriteLine(LogLevel.DEBUG,AcquirersMultipleItem.Heading); foreach(AcquirersMultipleItem acquirersMultipleItem in collection) { MDTrace.WriteLine(LogLevel.DEBUG,acquirersMultipleItem.ToString()); } } public static void CalcAcquirersMultipleSymbol(String symbol) { MDTrace.WriteLine("Generating aqcuirers multiple valuations..."); AcquirersMultipleCollection collection=AcquirersMultipeGenerator.ApplyRanks(symbol); MDTrace.WriteLine(LogLevel.DEBUG,AcquirersMultipleItem.Heading); foreach(AcquirersMultipleItem acquirersMultipleItem in collection) { MDTrace.WriteLine(LogLevel.DEBUG,acquirersMultipleItem.ToString()); } } public static void CalcTLBRanks() { TLBItemList tlbItemList=TLBRankGenerator.ApplyTLBRanks(); MDTrace.WriteLine(LogLevel.DEBUG,"Symbol,EBIT,EarningsYield,EnterpriseValue,WorkingCapital,PPE,ROIC,TLBRankRROIC,ROC,TLBRankROC"); for(int index=0;index symbols = PricingDA.GetSymbols(); MDTrace.WriteLine(LogLevel.DEBUG,"CompanyName," + SwingTrade.Header + ",MOS,MOS80,LatestPricedate,LatestPrice,Bargain,ROIC(Avg%),AvgEquityGrowth(AvgBVPS%),AvgEquityGrowth_2Y(AvgBVPS%),AvgEquityGrowth_4Y(AvgBVPS%),EPSGrowth(Avg%),EPSGrowth_2Y(Avg%),EPSGrowth_4Y(Avg%),RevenueGrowth(Avg%),RevenueGrowth_2Y(Avg%),RevenueGrowth_4Y(Avg%),FreeCashflowGrowth(Avg%),OperatingCashflow(Avg),WorkingCapital(Avg),Comment"); for (int index = 0; index < symbols.Count; index++) { String symbol = symbols[index]; bool bargain = false; String companyName = PricingDA.GetNameForSymbol(symbol); Prices prices = PricingDA.GetPrices(symbol, historicalDays); if (null == prices || 0 == prices.Count) continue; Price latestPrice = prices[0]; DMAPrices ma21 = MovingAverageGenerator.GenerateMovingAverage(prices, 21); if (null == ma21) continue; BollingerBands bollingerBands = BollingerBandGenerator.GenerateBollingerBands(prices); if (null == bollingerBands) continue; SwingTrades swingTrades = SwingTradeHelper.FindSwingTrades(prices, ma21.GetDMAPricesByDate(),bollingerBands.GetBollingerBandElementsByDate()); if (null == swingTrades || 0 == swingTrades.Count) continue; SwingTrade lastSwingTrade = swingTrades[swingTrades.Count - 1]; if (!Utility.IsEpoch(lastSwingTrade.CloseDate) && dateGenerator.DaysBetween(latestPrice.Date, lastSwingTrade.CloseDate) > 5) continue; TimeSeriesCollection bookValuePerShareCollection = HistoricalDA.GetTimeSeries(symbol, TimeSeriesElement.ElementType.BVPS); TimeSeriesCollection epsCollection = HistoricalDA.GetTimeSeries(symbol, TimeSeriesElement.ElementType.EPS); TimeSeriesCollection roicCollection = HistoricalDA.GetTimeSeries(symbol, TimeSeriesElement.ElementType.ROIC); TimeSeriesCollection revenueCollection = HistoricalDA.GetTimeSeries(symbol, TimeSeriesElement.ElementType.Revenue); TimeSeriesCollection freeCashflowCollection = HistoricalDA.GetTimeSeries(symbol, TimeSeriesElement.ElementType.FreeCashflow); TimeSeriesCollection operatingCashflowCollection = HistoricalDA.GetTimeSeries(symbol, TimeSeriesElement.ElementType.OperatingCashflow); TimeSeriesCollection workingCapitalCollection = HistoricalDA.GetTimeSeries(symbol, TimeSeriesElement.ElementType.WorkingCapital); float[] bookValuesPerShareSeries = bookValuePerShareCollection.ToFloat(); float[] epsSeries = epsCollection.ToFloat(); float[] roicSeries = roicCollection.ToFloat(); float[] revenueSeries = revenueCollection.ToFloat(); float[] freeCashflowSeries = freeCashflowCollection.ToFloat(); float[] operatingCashflowSeries = operatingCashflowCollection.ToFloat(); float[] workingCapitalSeries = workingCapitalCollection.ToFloat(); double averageGrowth = Numerics.AverageReturn(ref bookValuesPerShareSeries); double averageGrowth2Year = Numerics.AverageReturnTop(ref bookValuesPerShareSeries, 2); double averageGrowth4Year = Numerics.AverageReturnTop(ref bookValuesPerShareSeries, 4); double epsGrowth = Numerics.AverageReturn(ref epsSeries); double epsGrowth2Year = Numerics.AverageReturnTop(ref epsSeries, 2); double epsGrowth4Year = Numerics.AverageReturnTop(ref epsSeries, 4); double roic = Numerics.Mean(ref roicSeries); double revenueGrowth = Numerics.AverageReturn(ref revenueSeries); double revenueGrowth2Year = Numerics.AverageReturnTop(ref revenueSeries, 2); double revenueGrowth4Year = Numerics.AverageReturnTop(ref revenueSeries, 4); double freeCashflowGrowth = Numerics.AverageReturn(ref freeCashflowSeries); double averageOperatingCashflow = Numerics.Mean(ref operatingCashflowSeries); double averageWorkingCapital = Numerics.Mean(ref workingCapitalSeries); StickerPrice stickerPrice = new StickerPrice(symbol); bargain = latestPrice.Close < stickerPrice.MarginOfSafety ? true : false; if (filterBargain && !bargain) continue; StringBuilder sb=new StringBuilder(); sb.Append(companyName.Replace(",", "")).Append(","); sb.Append(lastSwingTrade.ToString()).Append(","); sb.Append(Utility.FormatNumber(stickerPrice.MarginOfSafety)).Append(","); sb.Append(Utility.FormatNumber(stickerPrice.MarginOfSafety80Pcnt)).Append(","); sb.Append(Utility.DateTimeToStringMMHDDHYYYY(latestPrice.Date)).Append(","); sb.Append(Utility.FormatNumber(latestPrice.Close)).Append(","); sb.Append(latestPrice.Close symbols = PricingDA.GetSymbols(); foreach (String symbol in symbols) { String cik = MarketDataHelper.GetCIK(symbol); if (null == cik) { MDTrace.WriteLine(LogLevel.DEBUG,symbol+",null"); continue; } PricingDA.UpdateCIKForSymbol(symbol, cik); MDTrace.WriteLine(LogLevel.DEBUG,symbol + "," + cik); } } catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void UpdateAllMissingCIK() { CIKMarketDataHelper cikMarketDataHelper=new CIKMarketDataHelper(); cikMarketDataHelper.UpdateAllMissingCIK(); } public static void UpdateCompanyProfiles() { try { CompanyProfileMarketDataHelper companyProfileMarketDataHelper=new CompanyProfileMarketDataHelper(); companyProfileMarketDataHelper.UpdateCompanyProfiles(); } catch(Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void UpdateCompanyProfile(String symbol) { try { CompanyProfileMarketDataHelper companyProfileMarketDataHelper=new CompanyProfileMarketDataHelper(); companyProfileMarketDataHelper.UpdateCompanyProfile(symbol); } catch(Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void UpdateCompanyProfileSymbol(String symbol) { try { CompanyProfileMarketDataHelper companyProfileMarketDataHelper=new CompanyProfileMarketDataHelper(); companyProfileMarketDataHelper.UpdateCompanyProfile(symbol); } catch(Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void DisplayCompanyProfiles() { try { List symbols = PricingDA.GetSymbols(); foreach (String symbol in symbols) { CompanyProfile companyProfile=MarketDataHelper.GetCompanyProfile(symbol); if(null==companyProfile) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("No profile for {0}",symbol)); continue; } MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Symbol:'{0}' Sector:'{1}' Industry:'{2}'",symbol,companyProfile.Sector,companyProfile.Industry)); } } catch(Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,exception); } } public static void GetSECFilingsWatchList(String watchListName) { List symbols = WatchListDA.GetWatchList(watchListName); SECFilingMarketDataHelper secFilingMarketDataHelper=new SECFilingMarketDataHelper(); secFilingMarketDataHelper.UpdateSECFilings(symbols); } public static void UpdateSECFilings() { SECFilingMarketDataHelper secFilingMarketDataHelper=new SECFilingMarketDataHelper(); secFilingMarketDataHelper.UpdateSECFilings(); } public static void GetSECFilingsOpenPositions() { List symbols=PortfolioDA.GetOpenSymbols(); SECFilingMarketDataHelper secFilingMarketDataHelper=new SECFilingMarketDataHelper(); secFilingMarketDataHelper.UpdateSECFilings(symbols); } public static void GetSECFilingsSymbol(String symbol) { List symbols=new List(); symbols.Add(symbol); SECFilingMarketDataHelper secFilingMarketDataHelper=new SECFilingMarketDataHelper(); secFilingMarketDataHelper.UpdateSECFilings(symbols); } public static void GetETFHoldings() { ETFHoldingsMarketDataHelper etfHoldingsMarketDataHelper=new ETFHoldingsMarketDataHelper(); etfHoldingsMarketDataHelper.LoadETFHoldings(); } public static void GetETFHoldingsSymbol(String symbol) { ETFHoldingsMarketDataHelper etfHoldingsMarketDataHelper=new ETFHoldingsMarketDataHelper(); etfHoldingsMarketDataHelper.LoadETFHoldings(symbol); } // *********************************** U P D A T E Y I E L D C U R V E ***************************************** public static void UpdateYieldCurve() // maintains current year of yield curve data { int year = DateTime.Now.Year; MDTrace.WriteLine(LogLevel.DEBUG,"Retrieving yield curve for year "+year); YieldCurve yieldCurve=MarketDataHelper.GetYieldCurve(year); if (null == yieldCurve) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Failed to get YieldCurve for {0}", year)); return; } MDTrace.WriteLine(LogLevel.DEBUG,"got "+yieldCurve.Count+" points for "+year); YieldCurveDA.InsertOrUpdate(yieldCurve); } public static void UpdateYieldCurve(int numYears) // gets last numYears of yield curve data { List years = DateGenerator.GenerateHistoricalYear(DateTime.Now.Year, numYears); for (int index = 0; index < years.Count; index++) { MDTrace.WriteLine(LogLevel.DEBUG,"Retrieving yield curve for year " + years[index]); YieldCurve yieldCurve = MarketDataHelper.GetYieldCurve(years[index]); if (null == yieldCurve || 0 == yieldCurve.Count) { MDTrace.WriteLine(LogLevel.DEBUG,"No yield curve data for "+years[index]); break; } MDTrace.WriteLine(LogLevel.DEBUG,"got " + yieldCurve.Count + " points for " + years[index]); YieldCurveDA.InsertOrUpdate(yieldCurve); } } // **************************************************************************************************** // *********************** E C O N O M I C I N D I C A T O R S - W O R L D B A N K **************** // **************************************************************************************************** public static void LoadGDPPerCapita() { try { MDTrace.WriteLine("[LoadGSPPerCapita]"); EconomicIndicators economicIndicators=MarketDataHelper.GetGDPPerCapita(); if(null==economicIndicators||0==economicIndicators.Count) { MDTrace.WriteLine(LogLevel.DEBUG,"[LoadGDPPerCapita] No data, see log file for potential issues."); return; } List distinctCountry=(from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.CountryCode).Distinct().ToList(); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[LoadGDPPerCapita] Downloaded {0} countries.",distinctCountry.Count)); MDTrace.WriteLine(LogLevel.DEBUG,"[LoadGDPPerCapita] Saving..."); if(EconomicIndicatorDA.InsertUpdateEconomicIndicators(economicIndicators)) { MDTrace.WriteLine(LogLevel.DEBUG,"[LoadGDPPerCapita] Success."); } else { MDTrace.WriteLine(LogLevel.DEBUG,"[LoadGDPPerCapita] Failed, check log file for isssues."); } } catch(Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[LoadGDPPerCapita] Exception:{0}",exception.ToString())); } } // **************************************************************************************************** // *********************** C O N S U M E R P R I C E I N D E X - B U R E A U O F L A B O R S T A T I S T I C S ************************************************* public static void LoadConsumerPriceIndex() { try { MDTrace.WriteLine("[LoadConsumerPriceIndex] started."); PriceIndices priceIndices=MarketDataHelper.GetConsumerPriceIndices(); if(null==priceIndices) { MDTrace.WriteLine(LogLevel.DEBUG,"[LoadConsumerPriceIndex] Failed, check log file for isssues."); return; } MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[LoadConsumerPriceIndex] Got:{0} records from source feed.",priceIndices.Count())); MDTrace.WriteLine(LogLevel.DEBUG,"[LoadConsumerPriceIndex] Saving..."); ConsumerPriceIndexDA.InsertUpdatePriceIndices(priceIndices); MDTrace.WriteLine(LogLevel.DEBUG,"[LoadConsumerPriceIndex] Save complete..."); } catch(Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[LoadConsumerPriceIndex] Exception:{0}",exception.ToString())); } } // **************************************************************************************************** // **************************************************************************************************** // ************************************ V A L U E A T R I S K ************************************* // **************************************************************************************************** // calculate the best new position to enter given the watchList, marketValue public class VaRResultSymbol : VaRResult, IComparable { private String symbol; public VaRResultSymbol(String symbol, VaRResult varResult) : base(varResult) { this.symbol = symbol; } public String Symbol { get { return symbol; } set { symbol = value; } } public int CompareTo(Object obj) { if (!obj.GetType().IsInstanceOfType(this)) throw new Exception("Expected VaRResultSymbol"); return VaRExpectedLoss.CompareTo((obj as VaRResultSymbol).VaRExpectedLoss); } } public static void GetOptimalPositionFromWatchList(String watchListName,String strMarketValue,String strDayCount,String strConfidence,String strReturnDays) { List watchListSymbols = null; double marketValue=double.Parse(strMarketValue); int dayCount=int.Parse(strDayCount); double confidence=double.Parse(strConfidence); int returnDays=int.Parse(strReturnDays); confidence /= 100.00; MDTrace.WriteLine(LogLevel.DEBUG,"GETOPTIMALPOSITIONFROMWATCHLIST"); MDTrace.WriteLine(LogLevel.DEBUG,"MarketValue:" + Utility.FormatCurrency(marketValue)); MDTrace.WriteLine(LogLevel.DEBUG,"DayCount:"+dayCount); MDTrace.WriteLine(LogLevel.DEBUG,"Confidence:"+Utility.FormatPercent(confidence)); MDTrace.WriteLine(LogLevel.DEBUG,"ReturnDays:"+returnDays); List varResults = new List(); PortfolioHoldings portfolioHoldings = new PortfolioHoldings(); if ("{All}".Equals(watchListName)) watchListSymbols = PricingDA.GetSymbols(); watchListSymbols = WatchListDA.GetWatchList(watchListName); PortfolioTrades portfolioTrades = PortfolioDA.GetOpenTrades(); List portfolioTradeSymbols = (from portfolioTrade in portfolioTrades select portfolioTrade.Symbol).Distinct().ToList(); watchListSymbols = (from watchListSymbol in watchListSymbols select watchListSymbol).Except(portfolioTradeSymbols).ToList(); for (int index = 0; index < portfolioTradeSymbols.Count; index++) { String symbol = portfolioTradeSymbols[index]; List trades = (from portfolioTrade in portfolioTrades where portfolioTrade.Symbol.Equals(symbol) select portfolioTrade).ToList(); double totalShares = (from portfolioTrade in trades select portfolioTrade.Shares).Sum(); PortfolioHolding portfolioHolding = new PortfolioHolding(); portfolioHolding.Symbol = symbol; portfolioHolding.Shares = totalShares; portfolioHolding.Prices = PricingDA.GetPrices(symbol, dayCount + 1); portfolioHolding.Weight = 0; portfolioHolding.MarketValue = portfolioHolding.Prices[0].Close * totalShares; portfolioHoldings.Add(portfolioHolding); } for (int index = 0; index < watchListSymbols.Count; index++) { PortfolioHolding portfolioHolding = new PortfolioHolding(); String symbol = watchListSymbols[index]; portfolioHolding.Symbol = symbol; portfolioHolding.Prices = PricingDA.GetPrices(symbol, dayCount + 1); portfolioHolding.Weight = 0; portfolioHolding.MarketValue = marketValue; portfolioHoldings.Add(portfolioHolding); VaRResult varResult = HistoricalVaR.GetVaR(portfolioHoldings, confidence); portfolioHoldings.Remove(portfolioHolding); VaRResultSymbol varResultSymbol = new VaRResultSymbol(symbol, varResult); varResults.Add(varResultSymbol); } varResults.Sort(); MDTrace.WriteLine(LogLevel.DEBUG,"Symbol,Expected Loss"); for (int index = 0; index < varResults.Count; index++) { VaRResultSymbol varResult = varResults[index]; MDTrace.WriteLine(LogLevel.DEBUG,varResult.Symbol + "," + varResult.VaRExpectedLoss); } } public static void GetVaR(String strDayCount, String strConfidence, String strReturnDays) { DateTime startdDate = DateTime.Now; int dayCount=30; int returnDays = 1; double confidence=95; dayCount = int.Parse(strDayCount); confidence = double.Parse(strConfidence); returnDays = int.Parse(strReturnDays); confidence /= 100.00; MDTrace.WriteLine(LogLevel.DEBUG,"GETVAR"); MDTrace.WriteLine(LogLevel.DEBUG,"DayCount:" + dayCount); MDTrace.WriteLine(LogLevel.DEBUG,"Confidence:" + Utility.FormatPercent(confidence)); MDTrace.WriteLine(LogLevel.DEBUG,"ReturnDays:" + returnDays); PortfolioTrades portfolioTrades = PortfolioDA.GetOpenTrades(); PortfolioHoldings portfolioHoldings = PortfolioHoldings.GetPortfolioHoldings(portfolioTrades, dayCount, startdDate); VaRResult varResult = HistoricalVaR.GetVaR(portfolioHoldings, confidence); MDTrace.WriteLine(LogLevel.DEBUG,"Symbol,Shares,MarketValue,Weight"); for (int index = 0; index < portfolioHoldings.Count; index++) { StringBuilder sb = new StringBuilder(); PortfolioHolding portfolioHolding = portfolioHoldings[index]; sb.Append(portfolioHolding.Symbol).Append(" "); sb.Append(Utility.FormatNumber(portfolioHolding.Shares)).Append(" "); sb.Append(Utility.FormatCurrency(portfolioHolding.MarketValue)).Append(" "); sb.Append(Utility.FormatPercent(portfolioHolding.Weight)); MDTrace.WriteLine(LogLevel.DEBUG,sb.ToString()); } MDTrace.WriteLine(LogLevel.DEBUG,"Daily VaR with " + dayCount + " days of history"); MDTrace.WriteLine(LogLevel.DEBUG,"The maximum loss over "+returnDays+" days with " + Utility.FormatPercent(confidence) + " confidence is " + Utility.FormatCurrency(varResult.VaRExpectedLoss) + " (" + Utility.FormatPercent(varResult.VaRPercent)+")"); MDTrace.WriteLine(LogLevel.DEBUG,"Total market value "+Utility.FormatCurrency(portfolioHoldings.GetMarketValue())); return; } // ********************************************************************************************************************************* public static void LoadInsiderTransactionsWatchLists() { MDTrace.WriteLine(LogLevel.DEBUG,"LoadInsiderTransactionsWatchLists"); List allSymbols=new List(); List watchLists = WatchListDA.GetWatchLists(); foreach (String watchList in watchLists) { List symbols = WatchListDA.GetWatchList(watchList); foreach (String symbol in symbols) { allSymbols.Add(symbol); } } InsiderTransactionMarketDataHelper insiderTransactionMarketDataHelper=new InsiderTransactionMarketDataHelper(); insiderTransactionMarketDataHelper.LoadInsiderTransactions(allSymbols); } public static void LoadInsiderTransactions() { List symbols = PricingDA.GetSymbols(); InsiderTransactionMarketDataHelper insiderTransactionMarketDataHelper = new InsiderTransactionMarketDataHelper(); insiderTransactionMarketDataHelper.LoadInsiderTransactions(symbols); } public static void LoadInsiderTransactionsSymbol(String symbol) { InsiderTransactionMarketDataHelper insiderTransactionMarketDataHelper = new InsiderTransactionMarketDataHelper(); insiderTransactionMarketDataHelper.LoadInsiderTransactions(symbol); } // ********************************************************************************************************************************************** // ************************************************** L I S T G A I N / L O S S F O R C O V E R E D C A L L S **************************** // ********************************************************************************************************************************************** // need to get the standard deviation over number of days to expiration. if the strike price > (market price + standard deviation) // likewie if the market price - standard deviation public static void DisplayAvailableOptions(int maxDaysToExpiration=45,bool verbose=false) { OptionsParams optionsParams = new OptionsParams(); List symbols = PricingDA.GetSymbols(); DateGenerator dateGenerator = new DateGenerator(); double investment = 10000.00; double requiredReturn=.05; // .075; // minimum return for dollar for premium double minimumCashGain = investment * requiredReturn; long recordsProcessed = 0; double targetShockRank = -.10; ////-.15; // test gain/loss using the -15% shock rank double volatility; MDTrace.WriteLine(String.Format("DISPLAYAVAILABLEOPTIONS {0}",maxDaysToExpiration)); MDTrace.WriteLine(LogLevel.DEBUG,OptionsParams.Header+",DaysBelowShockRank"); for (int symbolIndex = 0; symbolIndex < symbols.Count; symbolIndex++) { String symbol=symbols[symbolIndex]; String companyName = PricingDA.GetNameForSymbol(symbol); TimeSeriesCollection bvpsSeries=HistoricalDA.GetTimeSeries(symbol, TimeSeriesElement.ElementType.BVPS); TimeSeriesCollection epsSeries=HistoricalDA.GetTimeSeries(symbol, TimeSeriesElement.ElementType.EPS); if (null == bvpsSeries || 0 == bvpsSeries.Count) { if (verbose)MDTrace.WriteLine(String.Format("No BVPS for {0}",symbol)); continue; } if (null == epsSeries || 0 == epsSeries.Count) { if (verbose)MDTrace.WriteLine(String.Format("No EPS for {0}",symbol)); continue; } if (bvpsSeries[0].Value < 0) { if (verbose)MDTrace.WriteLine(String.Format("BVPS[0]<0 for {0}",symbol)); continue; } if (epsSeries[0].Value < 0) { if (verbose)MDTrace.WriteLine(String.Format("EPS<0 for {0}",symbol)); continue; } Prices allPrices = PricingDA.GetPrices(symbol); if (null == allPrices) { if (verbose)MDTrace.WriteLine(String.Format("No prices for {0}",symbol)); continue; } Options options = OptionsDA.GetOptions(symbol, DateTime.Now, OptionTypeEnum.CallOption); for (int optionIndex = 0; optionIndex < options.Count; optionIndex++) { recordsProcessed++; Option option=options[optionIndex]; if (option.Volume.Equals(0)){if (verbose)MDTrace.WriteLine(String.Format("Volume is zero for {0}",symbol)); continue;} if (option.Bid.Equals(double.NaN) || option.Strike.Equals(double.NaN)) { if (verbose)MDTrace.WriteLine(String.Format("Bid or Strike is NaN for {0}",symbol)); continue; } int daysToExpiration = dateGenerator.DaysBetweenActual(option.Expiration, DateTime.Now); // must be expiring within range // calculate the volatility Prices currentPrices = allPrices.Top(daysToExpiration); if (null == currentPrices || 0==currentPrices.Count) { if (verbose)MDTrace.WriteLine(String.Format("No price for {0}", symbol)); continue; } Price currentPrice = currentPrices[0]; if (null == currentPrice) continue; volatility = currentPrices.Volatility(); if (!PriceInRange(symbol, currentPrices)) { if (verbose)MDTrace.WriteLine(String.Format("PriceInRange fails for {0}", symbol)); continue; } optionsParams.Symbol = symbol; optionsParams.CompanyName = companyName; optionsParams.Cashdown = investment; optionsParams.ExpirationDate = option.Expiration; optionsParams.Bid = option.Bid; optionsParams.Strike = option.Strike; optionsParams.OpenInterest = option.OpenInterest; optionsParams.Contracts =(int)( (investment / currentPrice.Close) / 100.00); optionsParams.MarketPrice = currentPrice.Close; optionsParams.Premium = optionsParams.Shares * optionsParams.Bid; optionsParams.Volatility = volatility; optionsParams.VolatilityDays = daysToExpiration; EquityPriceShocks equityPriceShocks = EquityPriceShocks.CreateEquityPriceShocks(currentPrice, optionsParams); // get the number of instances where the stock returned less than targetShockRank (i.e.) where the stocks return < .15 int lossBelowShockCount = 0; float[] returns = allPrices.GetReturns(daysToExpiration); for (int index = 0; index < returns.Length; index++) { if (returns[index] <= targetShockRank) lossBelowShockCount++; } bool discard=false; double equityPriceShockGLViolation=double.NaN; foreach (EquityPriceShock equityPriceShock in equityPriceShocks) { if (equityPriceShock.Rank == targetShockRank && equityPriceShock.TransactionGL < minimumCashGain) { equityPriceShockGLViolation = equityPriceShock.TransactionGL; discard = true; break; } } if (discard) { if (verbose)MDTrace.WriteLine(String.Format("PriceShockGL vs minimum cash gain fails for {0}, {1}<{2}", symbol,equityPriceShockGLViolation,minimumCashGain)); continue; } if (optionsParams.Premium < minimumCashGain) { if (verbose)MDTrace.WriteLine(String.Format("Premium check vs cash gain fails for {0}", symbol)); continue; } if (daysToExpiration > maxDaysToExpiration || daysToExpiration < 0) { if (verbose)MDTrace.WriteLine(String.Format("Days to expiration check fails for {0}", symbol)); continue; } if (optionsParams.OpenInterest < 100) { if (verbose)MDTrace.WriteLine(String.Format("Open Interest check fails for {0}", symbol)); continue; } if (optionsParams.MarketPrice < 2.00) { if (verbose)MDTrace.WriteLine(String.Format("MarketPrice check fails for {0}", symbol)); continue; } if (optionsParams.Premium < 0.00) { if (verbose)MDTrace.WriteLine(String.Format("Premium < 0 check fails for {0}", symbol)); continue; } MDTrace.WriteLine(LogLevel.DEBUG, optionsParams.ToString()+",\""+Utility.FormatNumber(lossBelowShockCount,0,true)+"\""); } // for all options } // for all symbols MDTrace.WriteLine(LogLevel.DEBUG,String.Format("processed {0} records",recordsProcessed)); } // Using the volatility This method checks to see if prices fall outside of (multipler*standard deviation) // Essentially, we are checking for outlier prices in the set. private static bool PriceInRange(String symbol,Prices currentPrices,int multiplier=4) { DateGenerator dateGenerator = new DateGenerator(); DateTime nextBusinessDay = dateGenerator.FindNextBusinessDay(DateTime.Now); if (null == currentPrices || 0 == currentPrices.Count()) return false; Price currentPrice = currentPrices[0]; double volatility = currentPrices.Volatility(); double average = currentPrices.Mean(); volatility *=multiplier; double upperBound = average + volatility; double lowerBound = average - volatility; for (int index = 0; index < currentPrices.Count; index++) { currentPrice = currentPrices[index]; if (currentPrice.Close > upperBound || currentPrice.Close < lowerBound) return false; } return true; } private static void LoadPremarketData() { int retries=3; int sleepTime=2000; PremarketElements premarketElements=null; for(int retry=0;retry symbols = WatchListDA.GetWatchList(watchList); HeadlinesMarketDataHelper headlinesMarketDataHelper= new HeadlinesMarketDataHelper(); headlinesMarketDataHelper.LoadHeadlines(symbols); } private static void LoadHeadlinesSymbol(String symbol) { List symbols=new List(); symbols.Add(symbol); HeadlinesMarketDataHelper headlinesMarketDataHelper= new HeadlinesMarketDataHelper(); headlinesMarketDataHelper.LoadHeadlines(); } //private static void LoadHeadlinesWatchList(String watchList) //{ // MDTrace.WriteLine(LogLevel.DEBUG,String.Format("LoadHeadlinesWatchList {0}",watchList)); // List symbols = WatchListDA.GetWatchList(watchList); // foreach(String symbol in symbols) // { // LoadHeadlinesSymbol(symbol); // Thread.Sleep(500); // } //} //private static void LoadHeadlinesSymbol(String symbol) //{ // HeadlinesMarketDataHelper headlinesMarketDataHelper= new HeadlinesMarketDataHelper(); // headlinesMarketDataHelper.LoadHeadlines(); //} // ******************** public class Item { public Item() { } public Item(String symbol,float coefficient) { this.Symbol=symbol; this.Coefficient=coefficient; } public String Symbol{get;set;} public float Coefficient{get;set;} } public class ItemComparator : IComparer { public int Compare(Item v1,Item v2) { if(null==v1&&null==v2)return 0; if(null==v1)return 1; if(null==v2)return -1; return v1.Coefficient.CompareTo(v2.Coefficient); } } public static void DisplayVolatility(List symbols, int dayCount, DateTime? startDate) { if (null == startDate) startDate = PricingDA.GetLatestDate(); foreach (String symbol in symbols) { Prices prices = PricingDA.GetPrices(symbol, startDate.Value,dayCount); if (null == prices || 0 == prices.Count) { MDTrace.WriteLine(LogLevel.DEBUG,String.Format("No prices for {0}",symbol)); continue; } double volatility=prices.Volatility(); MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Symbol:{0} Volatility:{1} Days:{2} StartDate:{3}", symbol, Utility.FormatNumber(volatility, 4), prices.Count, startDate.Value.ToShortDateString())); } } public static void DisplaySharpeRatio(List symbols, int months, DateTime? startDate) { if (null == startDate) startDate = PricingDA.GetLatestDate(); foreach (String symbol in symbols) { double sharpeRatio = SharpeRatioGenerator.GenerateSharpeRatio(symbol, startDate.Value, months); MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Symbol:{0} SharpeRatio:{1} Months:{2} StartDate:{3}", symbol, Utility.FormatNumber(sharpeRatio, 4), months,startDate.Value.ToShortDateString())); } } public static void FindCoefficients(String symbol,int dayCount,DateTime startDate) { List symbols=PricingDA.GetSymbols(); symbols=(from currSymbol in symbols where !currSymbol.Equals(symbol) select currSymbol).ToList(); Dictionary matrix=new Dictionary(); if(Utility.IsEpoch(startDate))MDTrace.WriteLine(LogLevel.DEBUG,String.Format("FINDCOEFFICIENTS: {0} {1}",symbol,dayCount)); else MDTrace.WriteLine(LogLevel.DEBUG,String.Format("FINDCOEFFICIENTS: {0} {1} {2}",symbol,dayCount,Utility.DateTimeToStringMMHDDHYYYY(startDate))); Prices stockPrices=null; if(!Utility.IsEpoch(startDate))stockPrices=PricingDA.GetPrices(symbol,startDate,dayCount); else stockPrices=PricingDA.GetPrices(symbol,dayCount); float[] stockReturns=stockPrices.GetReturns(); Console.WriteLine("Working"); foreach(String masterSymbol in symbols) { Prices prices=null; if(!Utility.IsEpoch(startDate))prices=PricingDA.GetPrices(masterSymbol,startDate,dayCount); else prices=PricingDA.GetPrices(masterSymbol,dayCount); if(null==prices||0==prices.Count)continue; float[] returns=prices.GetReturns(); if(null==stockReturns||null==returns)continue; float correlationReturns=Numerics.Correlation(ref stockReturns,ref returns); if(!matrix.ContainsKey(masterSymbol))matrix.Add(masterSymbol,new Item(masterSymbol,(float)((correlationReturns)/2.00))); } List items=new List(matrix.Values); items=(from item in items where !double.IsNaN(item.Coefficient) select item).ToList(); items.Sort(new ItemComparator()); Console.WriteLine("Symbol,Coefficient"); Console.WriteLine(String.Format("Strongest Inverse:{0},{1}",items[0].Symbol,items[0].Coefficient)); Console.WriteLine(String.Format("Strongest Inverse:{0},{1}",items[1].Symbol,items[1].Coefficient)); Console.WriteLine(String.Format("Strongest Inverse:{0},{1}",items[2].Symbol,items[2].Coefficient)); Console.WriteLine(String.Format("Strongest Inverse:{0},{1}",items[3].Symbol,items[3].Coefficient)); Console.WriteLine(String.Format("Strongest Positive:{0},{1}",items[items.Count-4].Symbol,items[items.Count-4].Coefficient)); Console.WriteLine(String.Format("Strongest Positive:{0},{1}",items[items.Count-3].Symbol,items[items.Count-3].Coefficient)); Console.WriteLine(String.Format("Strongest Positive:{0},{1}",items[items.Count-2].Symbol,items[items.Count-2].Coefficient)); Console.WriteLine(String.Format("Strongest Positive:{0},{1}",items[items.Count-1].Symbol,items[items.Count-1].Coefficient)); } public static void RunMomentum(DateTime analysisDate,int maxPositions) { MGConfiguration config=new MGConfiguration(); MomentumCandidates momentumCandidates=MomentumGenerator.GenerateMomentum(analysisDate,config); MDTrace.WriteLine(LogLevel.DEBUG,String.Format("{0}",MomentumCandidate.Header())); for(int index=0;index("STARTDATE"); cmParams.MaxPositions=commandArgs.Get("MAXPOSITIONS"); cmParams.InitialCash=commandArgs.Get("INITIALCASH"); cmParams.HoldingPeriod=commandArgs.Get("HOLDINGPERIOD"); if(commandArgs.Has("USECNN")) { if(!commandArgs.Has("USECNNCLIENT,USECNNDAYCOUNT")) { MDTrace.WriteLine(LogLevel.DEBUG,"Missing USECNNCLIENT, USECNNDAYCOUNT"); return; } cmParams.UseCNN=true; cmParams.UseCNNHost=commandArgs.Get("USECNNHOST"); cmParams.UseCNNDayCount=commandArgs.Get("USECNNDAYCOUNT"); if(commandArgs.Has("USECNNREWARDPERCENTDECIMAL"))cmParams.UseCNNRewardPercentDecimal=commandArgs.Get("USECNNREWARDPERCENTDECIMAL"); } if(commandArgs.Has("USEOVEREXTENDEDINDICATOR")) { if(!commandArgs.Has("USEOVEREXTENDEDINDICATORDAYS,USEOVEREXTENDEDINDICATORVIOLATIONTHRESHHOLD,USEOVEREXTENDEDINDICATORMARGINPERCENT")) { MDTrace.WriteLine(LogLevel.DEBUG,"Missing USEOVEREXTENDEDINDICATORDAYS, USEOVEREXTENDEDINDICATORVIOLATIONTHRESHHOLD, USEOVEREXTENDEDINDICATORMARGINPERCENT"); return; } cmParams.UseOverExtendedIndicator=commandArgs.Get("USEOVEREXTENDEDINDICATOR"); cmParams.UseOverExtendedIndicatorDays=commandArgs.Get("USEOVEREXTENDEDINDICATORDAYS"); cmParams.UseOverExtendedIndicatorViolationThreshhold=commandArgs.Get("USEOVEREXTENDEDINDICATORVIOLATIONTHRESHHOLD"); cmParams.UseOverExtendedIndicatorMarginPercent=commandArgs.Get("USEOVEREXTENDEDINDICATORMARGINPERCENT"); } if(commandArgs.Has("USEMAXPOSITIONBUCKETWEIGHT")) // UseMaxPositionBucketWeight { if(!commandArgs.Has("USEMAXPOSITIONBUCKETWEIGHTMAXWEIGHT")) // UseMaxPositionBucketWeightMaxWeight { MDTrace.WriteLine(LogLevel.DEBUG,"Missing USEMAXPOSITIONBUCKETWEIGHTMAXWEIGHT"); return; } cmParams.UseMaxPositionBucketWeight=commandArgs.Get("USEMAXPOSITIONBUCKETWEIGHT"); cmParams.UseMaxPositionBucketWeightMaxWeight=commandArgs.Get("USEMAXPOSITIONBUCKETWEIGHTMAXWEIGHT"); } else { cmParams.UseMaxPositionBucketWeight=false; cmParams.UseMaxPositionBucketWeightMaxWeight=0; } if(commandArgs.Has("TARGETBETA"))cmParams.TargetBeta=commandArgs.Get("TARGETBETA"); else cmParams.TargetBeta=1.00; DateTime endDate=DateTime.Now; String pathSessionFileName=commandArgs.Coalesce("SESSIONFILE",null); if(null!=pathSessionFileName) pathSessionFileName=pathSessionFileName.Trim(); cmParams.DisplayHeader(); CMMomentumBacktest backtestMomentum=new CMMomentumBacktest(); List results=new List(); results.Add(backtestMomentum.PerformBacktest(cmParams.AnalysisDate,endDate,pathSessionFileName,cmParams)); } // ****************************************************************************************************************************************************************************************** // ********************************************************************** C M T T R E N D M O D E L R U N N E R A N D C M T T R E N D R E L A T E D *********************************** // ****************************************************************************************************************************************************************************************** //CMTSESSION /SESSIONFILE: public static void HandleCMTSession(String[] args) { CommandArgs commandArgs=new CommandArgs(args); if (!commandArgs.Has("SESSIONFILE")) {MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Missing SESSIONFILE"));return;} CMTTrendModel trendModel=new CMTTrendModel(); trendModel.DisplaySession(commandArgs.Coalesce("SESSIONFILE")); } public static int RunCMTrend(String[] args) { CommandArgs commandArgs=new CommandArgs(args); String mode; if(!commandArgs.Has("MODE")) { if(!commandArgs.Has("MODE")) MDTrace.WriteLine(LogLevel.DEBUG,"MODE is a required paramater."); MDTrace.WriteLine(LogLevel.DEBUG,"RUNMMTREND /MODE:DAILY|BACKTEST|RUNTRENDTEMPLATE|ANALYZE|DISPLAY|CLOSEPOSITION /SELLDATE:{CLOSEPOSITION} /PRICE:{CLOSEPOSITION} /SYMBOL:{for mode ANALYZE,CLOSEPOSITION} /TRADEDATE:{for mode DAILY,RUNTRENDTEMPLATE,ANALYZE,CLOSEPOSITION) /STARTDATE:(for mode BACKTEST) /ENDDATE:(for mode BACKTEST) /INITIALCASH: /SESSIONFILE: MAXOPENPOSITIONS: /MAXDAILYPOSITIONS: Runs Mark Minervini trend"); return 0; } mode=commandArgs.Get("MODE"); if("ENTRYTEST".Equals(mode)) { CMTParams cmtParams=new CMTParams(); if(!commandArgs.Has("SYMBOL")||!commandArgs.Has("STARTDATE")) { if(!commandArgs.Contains("SYMBOL")) MDTrace.WriteLine(LogLevel.DEBUG,"SYMBOL is a required parameter when MODE=ENTRYTEST"); if(!commandArgs.Contains("STARTDATE")) MDTrace.WriteLine(LogLevel.DEBUG,"STARTDATE is a required parameter when MODE=ENTRYTEST"); return 0; } CMTTrendModel trendModel=new CMTTrendModel(); trendModel.EntryTest(commandArgs.Get("SYMBOL"),commandArgs.Get("STARTDATE")); } else if("CLOSEPOSITION".Equals(mode)) { CMTParams cmtParams=new CMTParams(); if(!commandArgs.Has("PURCHASEDATE,SYMBOL,SESSIONFILE,PRICE,SELLDATE")) { if(!commandArgs.Contains("PURCHASEDATE")) MDTrace.WriteLine(LogLevel.DEBUG,"PURCHASEDATE is a required parameter when MODE=CLOSEPOSITION"); if(!commandArgs.Contains("SYMBOL")) MDTrace.WriteLine(LogLevel.DEBUG,"SYMBOL is a required parameter when MODE=CLOSEPOSITION"); if(!commandArgs.Contains("SESSIONFILE")) MDTrace.WriteLine(LogLevel.DEBUG,"SESSIONFILE is a required parameter when MODE=CLOSEPOSITION"); if(!commandArgs.Contains("PRICE")) MDTrace.WriteLine(LogLevel.DEBUG,"PRICE is a required parameter when MODE=CLOSEPOSITION"); if(!commandArgs.Contains("SELLDATE")) MDTrace.WriteLine(LogLevel.DEBUG,"SELLDATE is a required parameter when MODE=CLOSEPOSITION"); return 0; } CMTTrendModel trendModel=new CMTTrendModel(); trendModel.ClosePosition(commandArgs.Get("SYMBOL"),commandArgs.Get("PURCHASEDATE"),commandArgs.Get("SELLDATE"),commandArgs.Get("PRICE"),commandArgs.Get("SESSIONFILE")); } else if("DAILY".Equals(mode)) { CMTParams cmtParams=new CMTParams(); if(!commandArgs.Has("TRADEDATE,SESSIONFILE")) { if(!commandArgs.Contains("TRADEDATE")) MDTrace.WriteLine(LogLevel.DEBUG,"TRADEDATE is a required parameter when MODE=DAILY"); if(!commandArgs.Contains("SESSIONFILE")) MDTrace.WriteLine(LogLevel.DEBUG,"SESSIONFILE is a required parameter when MODE=DAILY"); return 0; } if(commandArgs.Contains("INITIALCASH")) cmtParams.InitialCash=commandArgs.Get("INITIALCASH"); if(commandArgs.Contains("MAXDAILYPOSITIONS")) cmtParams.MaxDailyPositions=commandArgs.Get("MAXDAILYPOSITIONS"); if(commandArgs.Contains("MAXOPENPOSITIONS")) cmtParams.MaxOpenPositions=commandArgs.Get("MAXOPENPOSITIONS"); if(commandArgs.Has("ONLYTRADESYMBOLS")) cmtParams.OnlyTradeSymbols=commandArgs.Get("ONLYTRADESYMBOLS"); if(commandArgs.Contains("POSITIONRISKPERCENTDECIMAL")) { cmtParams.PositionRiskPercentDecimal=commandArgs.Get("POSITIONRISKPERCENTDECIMAL"); } if(commandArgs.Contains("ENTRYTYPE")) { List entryTypes=Utility.ToList(commandArgs.Get("ENTRYTYPE")); List constraints=new List { "OVEREXTENDED","MVP","NARROWRANGE","MACD","PRICETREND","VOLUMETREND" }; bool results=entryTypes.All(i => constraints.ContainsIgnoreCase(i)); if(!results) { MDTrace.WriteLine(LogLevel.DEBUG,"ENTRYTYPE must consist of one or more OVEREXTENDED, MVP, NarrowRange, MACD, PriceTrend, VolumeTrend"); return 0; } cmtParams.EntryType=commandArgs.Get("ENTRYTYPE"); } CMTTrendModel trendModel=new CMTTrendModel(); if(commandArgs.Contains("USETRADEONLYSECTORS")) { cmtParams.UseTradeOnlySectors=commandArgs.Get("USETRADEONLYSECTORS"); if(cmtParams.UseTradeOnlySectors) { cmtParams.UseTradeOnlySectorsSectors=commandArgs.Get("USETRADEONLYSECTORSSECTORS"); } } CMTTrendModelResult result=trendModel.RunDaily(commandArgs.Get("TRADEDATE"),commandArgs.Get("SESSIONFILE"),cmtParams); } else if("BACKTEST".Equals(mode)) { CMTParams cmtParams=new CMTParams(); bool sellAtEndOfSimulation=true; if(!commandArgs.Has("STARTDATE,ENDDATE,SESSIONFILE")) { if(!commandArgs.Contains("STARTDATE")) MDTrace.WriteLine(LogLevel.DEBUG,"STARTDATE is a required parameter"); if(!commandArgs.Contains("ENDDATE")) MDTrace.WriteLine(LogLevel.DEBUG,"ENDDATE is a required parameter"); if(!commandArgs.Contains("SESSIONFILE")) MDTrace.WriteLine(LogLevel.DEBUG,"SESSIONFILE is a required parameter"); return 0; } CMTTrendModel trendModel=new CMTTrendModel(); if(commandArgs.Contains("USETRADEONLYSECTORS")) { cmtParams.UseTradeOnlySectors=commandArgs.Get("USETRADEONLYSECTORS"); if(cmtParams.UseTradeOnlySectors) { cmtParams.UseTradeOnlySectorsSectors=commandArgs.Get("USETRADEONLYSECTORSSECTORS"); } } if(commandArgs.Contains("USEPROFITMAXIMIZATION")) { cmtParams.UseProfitMaximization=commandArgs.Get("USEPROFITMAXIMIZATION"); if(commandArgs.Contains("USEPROFITMAXIMIZATIONEXPRESSION")) { cmtParams.UseProfitMaximizationExpression=commandArgs.Get("USEPROFITMAXIMIZATIONEXPRESSION"); } } if(commandArgs.Contains("MAXDAILYPOSITIONS")) cmtParams.MaxDailyPositions=commandArgs.Get("MAXDAILYPOSITIONS"); if(commandArgs.Contains("MAXOPENPOSITIONS")) cmtParams.MaxOpenPositions=commandArgs.Get("MAXOPENPOSITIONS"); if(commandArgs.Contains("BENCHMARKMOVINGAVERAGEDAYS")) cmtParams.BenchmarkMovingAverageDays=commandArgs.Get("BENCHMARKMOVINGAVERAGEDAYS"); if(commandArgs.Contains("BENCHMARKMOVINGAVERAGEHORIZON")) cmtParams.BenchmarkMovingAverageHorizon=commandArgs.Get("BENCHMARKMOVINGAVERAGEHORIZON"); if(commandArgs.Has("ONLYTRADESYMBOLS")) cmtParams.OnlyTradeSymbols=commandArgs.Get("ONLYTRADESYMBOLS"); if(commandArgs.Contains("POSITIONRISKPERCENTDECIMAL")) { cmtParams.PositionRiskPercentDecimal=commandArgs.Get("POSITIONRISKPERCENTDECIMAL"); } if(commandArgs.Contains("ENTRYTYPE")) { List entryTypes=Utility.ToList(commandArgs.Get("ENTRYTYPE")); List constraints=new List { "OVEREXTENDED","MVP","NARROWRANGE","MACD","PRICETREND","VOLUMETREND" }; bool results=entryTypes.All(i => constraints.ContainsIgnoreCase(i)); if(!results) { MDTrace.WriteLine(LogLevel.DEBUG,"ENTRYTYPE must consist of one or more OVEREXTENDED, MVP, NarrowRange, MACD, PriceTrend, VolumeTrend"); return 0; } cmtParams.EntryType=commandArgs.Get("ENTRYTYPE"); } if(commandArgs.Contains("SELLATENDOFSIMULATION")) { sellAtEndOfSimulation=commandArgs.Get("SELLATENDOFSIMULATION"); } CMTTrendModelResult result=trendModel.RunBacktestMode(commandArgs.Get("STARTDATE"),commandArgs.Get("ENDDATE"),sellAtEndOfSimulation,commandArgs.Get("SESSIONFILE"),cmtParams); } else if("DISPLAY".Equals(mode)) { if(!commandArgs.Contains("SESSIONFILE")) { MDTrace.WriteLine(LogLevel.DEBUG,"SESSIONFILE is a required parameter"); return 0; } CMTTrendModel trendModel=new CMTTrendModel(); trendModel.DisplaySession(commandArgs.Get("SESSIONFILE")); } else if("RUNTRENDTEMPLATE".Equals(mode)) { if(!commandArgs.Contains("TRADEDATE")) { MDTrace.WriteLine(LogLevel.DEBUG,"TRADEDATE is a required parameter when MODE=DAILY"); return 0; } CMTTrendModel trendModel=new CMTTrendModel(); trendModel.RunTrendTemplate(commandArgs.Get("TRADEDATE")); } else { MDTrace.WriteLine(LogLevel.DEBUG,"RUNCMTREND /MODE:DAILY|BACKTEST /TRADEDATE:{for mode DAILY) /STARTDATE:(for mode BACKTEST) /ENDDATE:(for mode BACKTEST) /INITIALCASH: /SESSIONFILE: /MAXPOSITIONS Runs Mark Minervini trend"); } return 0; } } }