void IBClient::commissionReport( const CommissionReport& commissionReport) { auto dict = createDictionary(std::map<std::string, K> { { "commission", kf(commissionReport.commission) }, { "currency", ks((S)commissionReport.currency.c_str()) }, { "execId", ks((S)commissionReport.execId.c_str()) }, { "realizedPNL", kf(commissionReport.realizedPNL) }, { "yield", kf(commissionReport.yield) }, { "yieldRedemptionDate", kp((S)stringFormat("%i", commissionReport.yieldRedemptionDate).c_str()) } }); receiveData("commissionReport", dict); }
//----------------------------------------------------------------------- void Animation::_applyBaseKeyFrame() { if (mUseBaseKeyFrame) { Animation* baseAnim = this; if (mBaseKeyFrameAnimationName != StringUtil::BLANK && mContainer) baseAnim = mContainer->getAnimation(mBaseKeyFrameAnimationName); if (baseAnim) { for (NodeTrackList::iterator i = mNodeTrackList.begin(); i != mNodeTrackList.end(); ++i) { NodeAnimationTrack* track = i->second; NodeAnimationTrack* baseTrack; if (baseAnim == this) baseTrack = track; else baseTrack = baseAnim->getNodeTrack(track->getHandle()); TransformKeyFrame kf(baseTrack, mBaseKeyFrameTime); baseTrack->getInterpolatedKeyFrame(baseAnim->_getTimeIndex(mBaseKeyFrameTime), &kf); track->_applyBaseKeyFrame(&kf); } for (VertexTrackList::iterator i = mVertexTrackList.begin(); i != mVertexTrackList.end(); ++i) { VertexAnimationTrack* track = i->second; if (track->getAnimationType() == VAT_POSE) { VertexAnimationTrack* baseTrack; if (baseAnim == this) baseTrack = track; else baseTrack = baseAnim->getVertexTrack(track->getHandle()); VertexPoseKeyFrame kf(baseTrack, mBaseKeyFrameTime); baseTrack->getInterpolatedKeyFrame(baseAnim->_getTimeIndex(mBaseKeyFrameTime), &kf); track->_applyBaseKeyFrame(&kf); } } } // Re-base has been done, this is a one-way translation mUseBaseKeyFrame = false; } }
void IBClient::updatePortfolio(const Contract &contract, int position, double marketPrice, double marketValue, double averageCost, double unrealizedPNL, double realizedPNL, const IBString &accountName) { auto dict = createDictionary(std::map<std::string, K> { { "contract", kj(contract.conId) }, { "position", ki(position) }, { "marketPrice", kf(marketPrice) }, { "marketValue", kf(marketValue) }, { "averageCost", kf(averageCost) }, { "unrealizedPNL", kf(unrealizedPNL) }, { "realizedPNL", kf(realizedPNL) }, { "accountName", kp((S)accountName.c_str()) } }); receiveData("updatePortfolio", dict); }
void IBClient::tickEFP(TickerId tickerId, TickType tickType, double basisPoints, const IBString &formattedBasisPoints, double totalDividends, int holdDays, const IBString &futureExpiry, double dividendImpact, double dividendsToExpiry) { auto dict = createDictionary(std::map<std::string, K> { { "tickerId", kj(tickerId) }, { "tickType", ki(tickType) }, { "basisPoints", kf(basisPoints) }, { "formattedBasisPoints", kp((S)formattedBasisPoints.c_str()) }, { "totalDividends", kf(totalDividends) }, { "holdDays", ki(holdDays) }, { "futureExpiry", kp((S)futureExpiry.c_str()) }, { "dividendImpact", kf(dividendImpact) }, { "dividendsToExpiry", kf(dividendsToExpiry) } }); receiveData("tickEFP", dict); }
void IBClient::realtimeBar(TickerId reqId, long time, double open, double high, double low, double close, long volume, double wap, int count) { auto dict = createDictionary(std::map<std::string, K> { { "reqId", kj(reqId) }, { "time", kj(time) }, // TODO: Convert { "open", kf(open) }, { "high", kf(high) }, { "low", kf(low) }, { "close", kf(close) }, { "volume", kj(volume) }, { "wap", kf(wap) }, { "count", ki(count) } }); receiveData("realtimeBar", dict); }
void operator()(Engine& e, Configuration &c, double temp) { typedef typename Configuration::modification Modification; //1 & 2 Modification modif; m_temperature = temp; detail::kernel_functor<Engine,Configuration,Modification> kf(e,c,modif); m_kernel_ratio = random_apply(m_kernel_id,m_rand(e),m_kernel,kf); //3 m_ref_pdf_ratio = m_density.pdf_ratio(c,modif); m_green_ratio = m_kernel_ratio*m_ref_pdf_ratio; //4 if(m_green_ratio<=0) { m_delta =0; m_accepted=false; return; } m_delta = c.delta_energy(modif); m_acceptance_probability = m_acceptance(m_delta,m_temperature,m_green_ratio); //5 m_accepted = ( m_rand(e) < m_acceptance_probability ); if (m_accepted) modif.apply(c); //modif.apply(c,m_accepted); }
/* * Estimate the balls position and velocity with a filter * */ static void filter_ball_state(int *init_filter, int *reset_sim) { int i; static double timeOfFlight = 0.0; // not being used now // calculate the racket orientation from endeffector calc_racket(&racket_state, &racket_orient, cart_state[RIGHT_HAND], cart_orient[RIGHT_HAND]); if(!simulation) { // estimate the initial ball state and the already taken time of flight if (estimate_ball_state(&ballPred, &timeOfFlight)) { // do nothing } } else { // for simulation // difference between simulate ball and integrate ball especially? simulate_ball(&sim_ball_state, &racket_state, &racket_orient, reset_sim); kf(&ballPred, blobs[BLOB1].blob, racket_state, racket_orient, init_filter); //estimate_ball_state(&ballPred, &timeOfFlight); /*for(i = 1; i <= N_CART; i++) { ballPred.x[i] = sim_ball_state.x[i]; ballPred.xd[i] = sim_ball_state.xd[i]; }*/ } // saving blob data to file //save_sim_data(); //print_filter_accuracy(); }
void IBClient::orderStatus(OrderId orderId, const IBString &status, int filled, int remaining, double avgFillPrice, int permId, int parentId, double lastFillPrice, int clientId, const IBString &whyHeld) { auto dict = createDictionary(std::map<std::string, K> { { "id", ki(orderId) }, { "status", kp((S)status.c_str()) }, { "filled", ki(filled) }, { "remaining", ki(remaining) }, { "avgFillPrice", kf(avgFillPrice) }, { "permId", ki(permId) }, { "parentId", ki(parentId) }, { "lastFilledPrice", kf(lastFillPrice) }, { "clientId", ki(clientId) }, { "whyHeld", kp((S)whyHeld.c_str()) } }); receiveData("orderStatus", dict); }
void NxAnimation::Update( unsigned long elapsedMS ) { if( !mEnabled ) return; float divideBy1000 = 0.001f; float elapsedS = static_cast<float>(elapsedMS) * divideBy1000; //Keyframes mTotalElapsedTime += ( elapsedS * mSpeed ); if( mKeyFrames.size() ){ NxKeyframe kf( mTotalElapsedTime ); GetInterpolatedKeyFrame( mTotalElapsedTime, &kf); OnValue( mTotalElapsedTime, kf.GetValue() ); } // Events mTotalEventElapsedTime += ( elapsedS * mSpeed ); if( mEvents.size() ) { NxEvent ev( mTotalEventElapsedTime ); GetInterpolatedEvent( mTotalEventElapsedTime, &ev ) ; } }
void IBClient::position(const IBString &account, const Contract &contract, int position, double avgCost) { receiveData("position", knk(4, ks((S)account.c_str()), kj(contract.conId), ki(position), kf(avgCost))); }
Foam::scalar Foam::ReversibleReaction<ReactionThermo, ReactionRate>::kr ( const scalar T, const scalar p, const scalarField& c ) const { return kr(kf(T, p, c), T, p, c); }
void IBClient::updateMktDepth(TickerId id, int position, int operation, int side, double price, int size) { receiveData("updateMktDepth", knk(6, kj(id), ki(position), ki(operation), ki(side), kf(price), ki(size))); }
TEST_F(PdepTest, ChebyshevIntermediate2) { // Test Chebyshev rates in the normal interpolation region vector_fp kf(6); set_TP(400.0, 0.1 * 101325); kin_->getFwdRateConstants(&kf[0]); // Expected rates computed using RMG-py EXPECT_NEAR(1.713599902e+05, kf[4], 1e-3); EXPECT_NEAR(9.581780687e-24, kf[5], 1e-31); }
TEST_F(PdepTest, ChebyshevIntermediate1) { // Test Chebyshev rates in the normal interpolation region vector_fp kf(6); set_TP(1100.0, 20 * 101325); kin_->getFwdRateConstants(&kf[0]); // Expected rates computed using RMG-py EXPECT_NEAR(3.130698657e+06, kf[4], 1e-1); EXPECT_NEAR(1.187949573e+00, kf[5], 1e-7); }
void IBClient::updateMktDepthL2(TickerId id, int position, IBString marketMaker, int operation, int side, double price, int size) { receiveData("updateMktDepthL2", knk(7, kj(id), ki(position), ks((S)marketMaker.c_str()), ki(operation), ki(side), kf(price), ki(size))); }
// Callback function for /robot0/odom to update KF on movement void updateOnMovement(const nav_msgs::Odometry &odom){ if(odom.pose.pose.position.x != prevX && odom.pose.pose.position.y != prevY){ ROS_INFO("KF time"); prevY = odom.pose.pose.position.y; prevX = odom.pose.pose.position.x; float initCov[3][3] = {{0,0,0},{0,0,0},{0,0,0}}; kf(initCov, vel_model_, sense_model_); } }
void IBClient::execDetails(int reqId, const Contract &contract, const Execution &execution) { auto exec = createDictionary(std::map<std::string, K> { { "execId", ks((S)execution.execId.c_str()) }, { "time", kp((S)execution.time.c_str()) }, // TODO: Convert { "acctNumber", ks((S)execution.acctNumber.c_str()) }, { "exchange", ks((S)execution.exchange.c_str()) }, { "side", ks((S)execution.side.c_str()) }, { "shares", ki(execution.shares) }, { "price", kf(execution.price) }, { "permId", ki(execution.permId) }, { "clientId", kj(execution.clientId) }, { "orderId", kj(execution.orderId) }, { "liquidation", ki(execution.liquidation) }, { "cumQty", ki(execution.cumQty) }, { "avgPrice", kf(execution.avgPrice) }, { "evRule", kp((S)execution.evRule.c_str()) }, { "evMultiplier", kf(execution.evMultiplier) } }); receiveData("execDetails", knk(3, ki(reqId), kj(contract.conId), exec)); }
TEST_F(PdepTest, PlogDuplicatePressures) { // Test that multiple rate expressions are combined when necessary set_TP(500.0, 1e10); vector_fp kf(6); kin_->getFwdRateConstants(&kf[0]); double kf1 = k(1.3700e+14, -0.79, 17603.0) + k(1.2800e+03, 1.71, 9774.0); double kf2 = k(-7.4100e+27, -5.54, 12108.0) + k(1.9000e+12, -0.29, 8306.0); EXPECT_NEAR(kf1, kf[1], 1e-9 * kf1); EXPECT_NEAR(kf2, kf[2], 1e-9 * kf2); }
TEST_F(PdepTest, PlogHighPressure) { // Test that P-log reactions have the right high-pressure limit set_TP(500.0, 1e10); vector_fp kf(6); kin_->getFwdRateConstants(&kf[0]); // Pre-exponential factor decreases by 10^3 for second-order reaction // when converting from cm + mol to m + kmol double kf0 = k(5.963200e+53, -11.529, 52599.6); double kf3 = k(1.740000e+04, 1.98, 4521.0); EXPECT_NEAR(kf0, kf[0], 1e-9 * kf0); EXPECT_NEAR(kf3, kf[3], 1e-9 * kf3); }
void IBClient::tickOptionComputation(TickerId tickerId, TickType tickType, double impliedVol, double delta, double optPrice, double pvDividend, double gamma, double vega, double theta, double undPrice) { auto dict = createDictionary(std::map<std::string, K> { { "tickerId", kj(tickerId) }, { "tickType", ki(tickType) }, { "impliedVol", kf(impliedVol) }, { "delta", kf(delta) }, { "optPrice", kf(optPrice) }, { "pvDividend", kf(pvDividend) }, { "gamma", kf(gamma) }, { "vega", kf(vega) }, { "theta", kf(theta) }, { "undPrice", kf(undPrice) } }); receiveData("tickOptionComputation", dict); }
TEST_F(PdepTest, PlogCornerCases) { // Test rate evaluation at the corner cases where the pressure // is exactly of the specified interpolation values set_TP(500.0, 101325); vector_fp kf(6); kin_->getFwdRateConstants(&kf[0]); double kf0 = k(4.910800e+28, -4.8507, 24772.8); double kf1 = k(1.2600e+17, -1.83, 15003.0) + k(1.2300e+01, 2.68, 6335.0); double kf2 = k(3.4600e+9, 0.442, 5463.0); EXPECT_NEAR(kf0, kf[0], 1e-9 * kf0); EXPECT_NEAR(kf1, kf[1], 1e-9 * kf1); EXPECT_NEAR(kf2, kf[2], 1e-9 * kf2); }
//--------------------------------------------------------------------- void NumericAnimationTrack::applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex, Real weight, Real scale) { // Nothing to do if no keyframes or zero weight, scale if (mKeyFrames.empty() || !weight || !scale) return; NumericKeyFrame kf(0, timeIndex.getTimePos()); getInterpolatedKeyFrame(timeIndex, &kf); // add to existing. Weights are not relative, but treated as // absolute multipliers for the animation AnyNumeric val = kf.getValue() * (weight * scale); anim->applyDeltaValue(val); }
/** * @brief Check kernel type by file extension and special ISIS kernels * * This method is a fallback attempt to determine the type of an expected NAIF * kernel. This method assumes the proper way (inspecting first 8 characters * of the kernel file) did not succeed in making this determination. * * There are some times that are expected to fail this test. ISIS DEMs are * cube files and will not be determined using the NAIF 8 character approach. * As such, all files that end in .cub are assumed to be DEMs and are tagged * as such. * * There are also some special ISIS IK addendum files that exist in the ISIS * system. These files are used to augment an instruments' IK kernel and * potentially override some of the original IK contents. This file type is * determined by checking for a ".ti" extension and then further checking the * base filename for the substring "Addendum". This is the only way to ensure * it is an ISIS IAK file. It must pass both tests or it is simply tagged as * an IK (due to the .ti extension). * * The remainder of the tests are strictly testing the file extension. Here is * how the associations are made to the files based upon their file * extensions: * * .cub = DEM - ISIS cubes are DEMs * .ti = IK - unless "Addendum" is in basename, then it is an IAK * .tf = FK - frames kernel * .tsc = SCLK - spacecraft clock kernel * .tsl = LSK - leap seconds kernel * .tpc = PCK - planetary ephemeris kernel * .bc = CK - C-kernel * .bsp = SPK - spacecraft position kernel * .bes = EK - event kernels * * If none of these file extensions or condition are found, then the value of * the parameter iktype is returned as the default type. * * @param kfile File to determine type for * @param iktype Default type to be used in none are determined from this * methiod * * @return QString Type of kernel found from file extensions */ QString Kernels::resolveTypeByExt(const QString &kfile, const QString &iktype) const { QString ktype(iktype); // Set default condition // Deciminate file parts FileName kf(kfile); string ext = IString(kf.extension()).DownCase(); // Check extensions for types if (ext == "cub") { ktype = "DEM"; } else if (ext == "ti") { // Assume its an instrument kernel but check for ISIS IAK file ktype = "IK"; string base = IString(kf.baseName()).DownCase(); string::size_type idx = base.find("addendum"); if (idx != string::npos) { // This is an ISIS IK addendum (IAK) ktype = "IAK"; } } else if (ext == "tsc") { ktype = "SCLK"; } else if (ext == "tf") { ktype = "FK"; } else if (ext == "tls") { ktype = "LSK"; } else if (ext == "tpc") { ktype = "PCK"; } else if (ext == "bc") { ktype = "CK"; } else if (ext == "bsp") { ktype = "SPK"; } else if (ext == "bes") { ktype = "EK"; } return (ktype); }
TEST_F(PdepTest, PlogLowPressure) { // Test that P-log reactions have the right low-pressure limit set_TP(500.0, 1e-7); vector_fp kf(6); kin_->getFwdRateConstants(&kf[0]); // Pre-exponential factor decreases by 10^3 for second-order reaction // when converting from cm + mol to m + kmol double kf0 = k(1.212400e+13, -0.5779, 10872.7); double kf1 = k(1.230000e+05, 1.53, 4737.0); double kf2 = k(2.440000e+7, 1.04, 3980.0); double kf3 = k(1.740000e+04, 1.98, 4521.0); EXPECT_NEAR(kf0, kf[0], 1e-9 * kf0); EXPECT_NEAR(kf1, kf[1], 1e-9 * kf1); EXPECT_NEAR(kf2, kf[2], 1e-9 * kf2); EXPECT_NEAR(kf3, kf[3], 1e-9 * kf3); }
static void poll_state(unsigned long ignored) { printk(KERN_NOTICE "%s: time\n", LIRC_DRIVER_NAME); del_timer(&poll_timer); if (is_claimed) return; kf(NULL); if (!is_claimed) { printk(KERN_NOTICE "%s: could not claim port, giving up\n", LIRC_DRIVER_NAME); init_timer(&poll_timer); poll_timer.expires = jiffies + HZ; poll_timer.data = (unsigned long)current; poll_timer.function = poll_state; add_timer(&poll_timer); } }
cv::KalmanFilter createKalmanFilter(int stateSize, int measSize, int contrSize, unsigned int type) { // FORMULAS: // xdot = A*x + B*u + w with Cov(w)=Q // y = C*x + v with Cov(v) = R // create kalman filter object kf cv::KalmanFilter kf(stateSize, measSize, contrSize, type); //A cv::setIdentity(kf.transitionMatrix); //initialize state matrix A with and identity kf.transitionMatrix.at<float>(10) = 1; //CHANGE LATER kf.transitionMatrix.at<float>(15) = 1; // B kf.controlMatrix = cv::Mat::zeros(stateSize, 1,type); kf.controlMatrix.at<float>(3) = -1; // C kf.measurementMatrix = cv::Mat::zeros(measSize, stateSize, type); //initialize C matrix as a zero matrix kf.measurementMatrix.at<float>(0) = 1.0f; //C matrix; add a float value of 1.0f to the four entries in the matrix kf.measurementMatrix.at<float>(5) = 1.0f; // R cv::setIdentity(kf.measurementNoiseCov, cv::Scalar(1e-5)); //GEÄNDERT!!!!!!!!! R 1e-1 // Q kf.processNoiseCov.at<float>(0) = 1e-2;//1e-2; //Q Matrix kf.processNoiseCov.at<float>(5) = 1e-2;//1e-2; kf.processNoiseCov.at<float>(10) = 5.0f;//5.0f; kf.processNoiseCov.at<float>(15) = 5.0f;//5.0f; // P, initialization kf.errorCovPre.at<float>(0) = 1; // px kf.errorCovPre.at<float>(5) = 1; // px kf.errorCovPre.at<float>(10) = 1; kf.errorCovPre.at<float>(15) = 1; return kf; }
//--------------------------------------------------------------------- void NodeAnimationTrack::applyToNode(Node* node, const TimeIndex& timeIndex, Real weight, Real scl) { // Nothing to do if no keyframes or zero weight or no node if (mKeyFrames.empty() || !weight || !node) return; TransformKeyFrame kf(0, timeIndex.getTimePos()); getInterpolatedKeyFrame(timeIndex, &kf); // add to existing. Weights are not relative, but treated as absolute multipliers for the animation Vector3 translate = kf.getTranslate() * weight * scl; node->translate(translate); // interpolate between no-rotation and full rotation, to point 'weight', so 0 = no rotate, 1 = full Quaternion rotate; Animation::RotationInterpolationMode rim = mParent->getRotationInterpolationMode(); if (rim == Animation::RIM_LINEAR) { rotate = Quaternion::nlerp(weight, Quaternion::IDENTITY, kf.getRotation(), mUseShortestRotationPath); } else //if (rim == Animation::RIM_SPHERICAL) { rotate = Quaternion::Slerp(weight, Quaternion::IDENTITY, kf.getRotation(), mUseShortestRotationPath); } node->rotate(rotate); Vector3 scale = kf.getScale(); // Not sure how to modify scale for cumulative anims... leave it alone //scale = ((Vector3::UNIT_SCALE - kf.getScale()) * weight) + Vector3::UNIT_SCALE; if (scale != Vector3::UNIT_SCALE) { if (scl != 1.0f) scale = Vector3::UNIT_SCALE + (scale - Vector3::UNIT_SCALE) * scl; else if (weight != 1.0f) scale = Vector3::UNIT_SCALE + (scale - Vector3::UNIT_SCALE) * weight; } node->scale(scale); }
TDF_API K K_DECL TDF_optionCodeInfo(K h, K windCode) { ::THANDLE tdf = NULL; std::string code; try { TDF::parseTdfHandle(h, tdf); code = q::q2String(windCode); } catch (std::string const& error) { return q::error2q(error); } ::TDF_OPTION_CODE info = { 0 }; ::TDF_ERR result = static_cast<::TDF_ERR>(::TDF_GetOptionCodeInfo(tdf, code.c_str(), &info)); if (result != TDF_ERR_SUCCESS) { return q::error2q(::TDF::getError(result)); } q::K_ptr data(ktn(0, 6 + 12)); kK(data.get())[0 + 0] = ks(const_cast<S>(info.basicCode.szWindCode)); kK(data.get())[0 + 1] = ks(const_cast<S>(info.basicCode.szMarket)); kK(data.get())[0 + 2] = ks(const_cast<S>(info.basicCode.szCode)); kK(data.get())[0 + 3] = ks(const_cast<S>(info.basicCode.szENName)); kK(data.get())[0 + 4] = ks(const_cast<S>(Wind::encoder::GB18030_UTF8::encode(info.basicCode.szCNName).c_str())); kK(data.get())[0 + 5] = kg(info.basicCode.nType); kK(data.get())[6 + 0] = ks(const_cast<S>(info.szContractID)); kK(data.get())[6 + 1] = ks(const_cast<S>(info.szUnderlyingSecurityID)); kK(data.get())[6 + 2] = kc(info.chCallOrPut); kK(data.get())[6 + 3] = kd(q::date2q(info.nExerciseDate)); kK(data.get())[6 + 4] = kc(info.chUnderlyingType); kK(data.get())[6 + 5] = kc(info.chOptionType); kK(data.get())[6 + 6] = kc(info.chPriceLimitType); kK(data.get())[6 + 7] = ki(info.nContractMultiplierUnit); kK(data.get())[6 + 8] = kf(info.nExercisePrice); kK(data.get())[6 + 9] = kd(q::date2q(info.nStartDate)); kK(data.get())[6 + 10] = kd(q::date2q(info.nEndDate)); kK(data.get())[6 + 11] = kd(q::date2q(info.nExpireDate)); return data.release(); }
TEST_F(PdepTest, ChebyshevEdgeCases) { vector_fp kf(6); // Minimum P set_TP(500.0, 1000.0); kin_->getFwdRateConstants(&kf[0]); EXPECT_NEAR(1.225785655e+06, kf[4], 1e-2); // Maximum P set_TP(500.0, 1.0e7); kin_->getFwdRateConstants(&kf[0]); EXPECT_NEAR(1.580981157e+03, kf[4], 1e-5); // Minimum T set_TP(300.0, 101325); kin_->getFwdRateConstants(&kf[0]); EXPECT_NEAR(5.405987017e+03, kf[4], 1e-5); // Maximum T set_TP(2000.0, 101325); kin_->getFwdRateConstants(&kf[0]); EXPECT_NEAR(3.354054351e+07, kf[4], 1e-1); }
//Calling functions with different valencies and with simple data types int eg3() { K result=NULL; //Monadic [Single argument function] result=k(c,"f1s",ks("Hello World"),(K)0); printf( "Executing f1s - This will return a symbol [type=%i] with value %s\n\n\n",result->t,result->s); //Dyadic function result=k(c,"f2i",ki(10),ki(1),(K)0); printf( "Executing f2s - This will return a integer [type=%i] with value %i\n\n\n",result->t,result->i); //Triadic function result=k(c,"f3f",kf(10),kf(-1.),kf(2.2),(K)0); printf( "Executing f2s - This will return a float [type=%i] with value %f\n\n\n",result->t,result->f); //The examples above can be extended to up to functions with eight arguments. //[Errors are discussed later] printf("Finished Example 3"); return 1; }