//.cc#include#include#include#include#include#include#include#include#includenamespacelongbeach{namespacesignals{usingstd::cout;SigBook::SigBook:SignalSmonImpl,m_spRefpp,m_spBook,m_vars,m_varsOK,m_varsDirty,m_numLevels,m_numSBvars,m_returnMode{if==false)LONGBEACH_THROW_ERROR_SS;ifLONGBEACH_THROW_ERROR_SS;m_spRefpp->addPriceListener);if{cout<<"Constructed"<removeBookListener;}voidSigBook::resetVarsconst{LONGBEACH_ASSERT==m_numSBvars);std::fill,m_vars.end,0.0);m_varsOK=false;m_varsDirty=false;}voidSigBook::reset{resetVars;SignalSmonImpl::reset;}voidSigBook::updateVarsconst{resetVars;if{if{cout<bbls,abls;boolbres=getNBookLevels;boolares=getNBookLevels;if==false||bres==false||ares==false){if{cout<bavgpx;std::vectorbttlsz;std::vectoraavgpx;std::vectorattlsz;bavgpx.resize;bttlsz.resize;aavgpx.resize;attlsz.resize;//initializetheavgpxsandttlszsbavgpx[0]=bbls[0]->getPrice;bttlsz[0]=bbls[0]->getSize;aavgpx[0]=abls[0]->getPrice;attlsz[0]=abls[0]->getSize;//gettherefpptouseincaseweneedtonormalizeboolrefppok;doublerefpx=m_spRefpp->getRefPrice;if{//somethingwrongwithrefpp,usemidpointbetweenbidandaskofthisbookinsteadrefpx=*0.5;}//forbestmkt,onlyusebidsideasavar,sowedon"trunintosingularityproblems//withRefPxm_vars[0]=bavgpx[0];if{m_vars[0]=refpx*MaxDiffRefMidpx;if{cout<getSize)/);bttlsz[i]=bttlsz[i-1]+bbls[i]->getSize;aavgpx[i]=*abls[i]->getSize)/);attlsz[i]=attlsz[i-1]+abls[i]->getSize;//stickeminforbothbidandasksides,butnormalizeemslightlyifthevaluesaretooextremem_vars[i]=bavgpx[i];if{m_vars[i]=m_vars[i-1]*MaxDownChg;if{cout<isPriceOK;doublerefpx=0.0;//possiblywecouldstillcalcsignals/printvalueshereevenifrefppisn"tok...if{//havetoresetvars,causeiftherewasnoupdatethenmaybevarsweren"tclearedyet//thiswillforceallthevarsprintedouttobe0.0resetVars;}elserefpx=m_spRefpp->getRefPrice;for{ifswitch{caseDIFF:m_state[i]=;break;caseARITH:m_state[i]=/refpx*10000;break;caseLOG:m_state[i]=log*10000;break;default:LONGBEACH_THROW_ERROR_SS;break;}elsem_state[i]=0.0;}}/************************************************************************************************///SigBookSpec/************************************************************************************************/SigBookSpec::SigBookSpec:m_numLevels,m_numSBvars,m_returnMode{}SigBookSpec::SigBookSpec:SignalSpec,m_book),m_sources,m_numLevels,m_numSBvars,m_returnMode{}ISignalPtrSigBookSpec::buildconst{IPriceProviderPtrpriceProv=builder->getPxPBuilder->buildPxProvider;IBookPtrbook=builder->getBookBuilder->buildBook;std::auto_ptrsb,m_description,builder->getClockMonitor,priceProv,book,m_numLevels,m_numSBvars,builder->getVerboseLevel,m_returnMode));sb->registerWithSourceMonitors,m_sources);returnISignalPtr;}voidSigBookSpec::checkValidconst{SignalSpec::checkValid;ifLONGBEACH_THROW_ERROR_SS;m_book->checkValid;util::checkSourcesValid;}voidSigBookSpec::hashCombineconst{SignalSpec::hashCombine;boost::hash_combine;boost::hash_combine;boost::hash_combine;boost::hash_combine;boost::hash_combine;}SigBookSpec*SigBookSpec::cloneconst{returnnewSigBookSpec;}boolSigBookSpec::compareconst{if)returnfalse;constSigBookSpec*b=dynamic_cast;ifreturnfalse;ifreturnfalse;ifreturnfalse;ifreturnfalse;ifreturnfalse;ifreturnfalse;returntrue;}voidSigBookSpec::printconst{constLuaPrintSettingsonei=ps.next;//indentationonepastcurrento<<"--SigBookSpec"<getDataRequirements;}boolSigBookSpec::registerScripting{//eachSpecclassmustbeaddedtoregisterScriptinginSignals_Scripting.ccluabind::module[luabind::class_.def).def_readwrite.def_readwrite.def_readwrite.def_readwrite.def_readwrite];returntrue;}}//namespacesignals}//namespacelongbeach
文章为作者独立观点,不代表 股票程序化软件自动交易接口观点