#include #include "../../shared/SimpleLogFile.h" #include "../../shared/GlobalConfigFile.h" #include "../alert_framework/AlertBase.h" #include "../misc_framework/CsvFileDataNodes.h" #include "Correlation.h" class Correlation : public Alert { private: bool _up; bool _fromClose; bool _useFutures; double _m; std::string _comparisonSymbol; GenericDataNode *_mainStockBaselineData; GenericDataNode *_mainStockCurrentData; GenericDataNode *_comparisonBaselineData; GenericDataNode *_comparisonCurrentData; bool _primed; int _lastReported; void onWakeup(int msgId); GenericDataNode *getBaselineData(std::string const &symbol); GenericDataNode *getCurrentData(std::string const &symbol, bool report); Correlation(DataNodeArgument const &args); friend class GenericDataNodeFactory; public: static std::string futuresSymbol; }; std::string Correlation::futuresSymbol; GenericDataNode *Correlation::getBaselineData(std::string const &symbol) { GenericDataNode *result; addAutoLink(GenericDataNodeFactory::replaceAndFind (GenericDataNodeFactory::findFactory (_fromClose?"ClosePrice":"OpenPrice"), NULL, 0, result, symbolPlaceholder, symbol)); return result; } GenericDataNode *Correlation::getCurrentData(std::string const &symbol, bool report) { GenericDataNode *result; addAutoLink(GenericDataNodeFactory::replaceAndFind (GenericDataNodeFactory::findFactory("LastPrintPrice"), (report?this:NULL), 0, result, symbolPlaceholder, symbol)); return result; } Correlation::Correlation(DataNodeArgument const &args) : _m(0.0), _mainStockBaselineData(NULL), _mainStockCurrentData(NULL), _comparisonBaselineData(NULL), _comparisonCurrentData(NULL), _primed(false), _lastReported(0) { DataNodeArgumentVector const &argList = args.getListValue(); assert(argList.size() == 4); // (Symbol, up, fromClose, useFutures) std::string const &symbol = argList[0].getStringValue(); _up = argList[1].getBooleanValue(); _fromClose = argList[2].getBooleanValue(); _useFutures = argList[3].getBooleanValue(); _m = strtodDefault(FileOwnerDataNode::getStringValue ("OvernightData.csv", _useFutures?"F Correlation M":"Correlation M", symbol), 0.0); //std::cout<<"_m="<<_m // <<", symbol="<getDouble(valid, mainStockBaseline); if (valid) _mainStockCurrentData->getDouble(valid, mainStockCurrent); if (valid) _comparisonBaselineData->getDouble(valid, comparisonBaseline); if (valid) _comparisonCurrentData->getDouble(valid, comparisonCurrent); if (valid) valid = (mainStockBaseline > 0) && (mainStockCurrent > 0) && (comparisonBaseline > 0) && (comparisonCurrent > 0); if (!valid) { //TclList msg; //msg<<__FILE__<<__LINE__<<__FUNCTION__ // <<"Correlation failed"< _lastReported + 50) // We jumped up by more than 50% at once. This is probably not real. _lastReported = possibleReport; else if (possibleReport > _lastReported) { _lastReported = possibleReport; if (_primed) { std::string description = "Trading "; description += ntoa(_lastReported); description += "% "; if (_up) description += "above"; else description += "below"; description += " expectations based on "; description += _comparisonSymbol; report(description, "cs=" + _comparisonSymbol, _lastReported); } } else if (possibleReport + 25 < _lastReported) /* We dropped by 25%. Presumably the previous one was a bad print, * so we don't want to just cut off the stock from all future * reports. In the rare cases when we legitimately drop by 25%, it's * okay to repeat some alerts. This is still interesting. If the * current print, not the previous print, is the eroneous print, * we may see some additional alerts. But not a lot, and this is * unavoidable. You to try to set primed to false, but that would * only help in the case when the bad print was in the main stock, * not the comparison stock. */ _lastReported = std::max(0, possibleReport); _primed = true; } catch (...) { TclList msg; msg<<__FILE__<<__LINE__<<__FUNCTION__ <<"Correlation exception"< ("SectorBreakdownOpen", symbolPlaceholderObject, false, false, false); GenericDataNodeFactory::sf< Correlation > ("SectorBreakdownClose", symbolPlaceholderObject, false, true, false); GenericDataNodeFactory::sf< Correlation > ("SectorBreakoutOpen", symbolPlaceholderObject, true, false, false); GenericDataNodeFactory::sf< Correlation > ("SectorBreakoutClose", symbolPlaceholderObject, true, true, false); GenericDataNodeFactory::sf< Correlation > ("PositiveFuturesDivergence", symbolPlaceholderObject, true, true, true); GenericDataNodeFactory::sf< Correlation > ("NegativeFuturesDivergence", symbolPlaceholderObject, false, true, true); }