How to use cache_clear method in tempest

Best Python code snippet using tempest_python

oanda.py

Source:oanda.py Github

copy

Full Screen

...250 return self._instruments251 @instruments.setter252 def instruments(self, value):253 self._instruments = value254 type(self).price_data.fget.cache_clear()255 type(self).open.fget.cache_clear()256 type(self).high.fget.cache_clear()257 type(self).low.fget.cache_clear()258 type(self).close.fget.cache_clear()259 type(self).volume.fget.cache_clear()260 type(self).returns.fget.cache_clear()261 type(self).factor_data.fget.cache_clear()262 type(self).combined_factor.fget.cache_clear()263 type(self).combined_factor_data.fget.cache_clear()264 type(self).summaries.fget.cache_clear()265 @property266 def symbol(self) -> Optional[str]:267 """Optional symbol to arrange price data."""268 return self._symbol269 @symbol.setter270 def symbol(self, value):271 self._symbol = value272 type(self).price_data.fget.cache_clear()273 type(self).open.fget.cache_clear()274 type(self).high.fget.cache_clear()275 type(self).low.fget.cache_clear()276 type(self).close.fget.cache_clear()277 type(self).volume.fget.cache_clear()278 type(self).returns.fget.cache_clear()279 type(self).factor_data.fget.cache_clear()280 type(self).combined_factor.fget.cache_clear()281 type(self).combined_factor_data.fget.cache_clear()282 type(self).summaries.fget.cache_clear()283 @property284 def granularity(self) -> str:285 """Time period between each candle and between each rebalance."""286 return self._granularity287 @granularity.setter288 def granularity(self, value):289 self._granularity = value290 type(self).price_data.fget.cache_clear()291 type(self).open.fget.cache_clear()292 type(self).high.fget.cache_clear()293 type(self).low.fget.cache_clear()294 type(self).close.fget.cache_clear()295 type(self).volume.fget.cache_clear()296 type(self).returns.fget.cache_clear()297 type(self).factor_data.fget.cache_clear()298 type(self).combined_factor.fget.cache_clear()299 type(self).combined_factor_data.fget.cache_clear()300 type(self).summaries.fget.cache_clear()301 @property302 def count(self) -> int:303 """Number of historical OHLCV candles."""304 return self._count305 @count.setter306 def count(self, value):307 self._count = value308 type(self).price_data.fget.cache_clear()309 type(self).open.fget.cache_clear()310 type(self).high.fget.cache_clear()311 type(self).low.fget.cache_clear()312 type(self).close.fget.cache_clear()313 type(self).volume.fget.cache_clear()314 type(self).returns.fget.cache_clear()315 type(self).factor_data.fget.cache_clear()316 type(self).combined_factor.fget.cache_clear()317 type(self).combined_factor_data.fget.cache_clear()318 type(self).summaries.fget.cache_clear()319 @property320 def periods(self) -> Optional[List[int]]:321 """Optional forward periods for factor decay analysis."""322 return self._periods323 @periods.setter324 def periods(self, value):325 self._periods = value326 type(self).factor_data.fget.cache_clear()327 type(self).combined_factor.fget.cache_clear()328 type(self).combined_factor_data.fget.cache_clear()329 type(self).summaries.fget.cache_clear()330 @property331 def split(self) -> Union[int, Sequence[float]]:332 """Number of quantiles to split combined factor data."""333 return self._split334 @split.setter335 def split(self, value):336 self._split = value337 type(self).combined_factor_data.fget.cache_clear()338 @property339 def long_short(self) -> bool:340 """True if trade only top and bottom factor quantile, False if all."""341 return self._long_short342 @long_short.setter343 def long_short(self, value):344 self._long_short = value345 type(self).factor_data.fget.cache_clear()346 type(self).combined_factor.fget.cache_clear()347 type(self).combined_factor_data.fget.cache_clear()348 type(self).summaries.fget.cache_clear()349 @property350 def combination(self) -> str:351 """Formula for combining factors together."""352 return self._combination353 @combination.setter354 def combination(self, value):355 self._combination = value356 type(self).combined_factor.fget.cache_clear()357 type(self).combined_factor_data.fget.cache_clear()358 type(self).summaries.fget.cache_clear()359 @property360 def leverage(self) -> float:361 """Multiplier for the portfolio positions."""362 return self._leverage363 @leverage.setter364 def leverage(self, value):365 self._leverage = value366 type(self).factor_data.fget.cache_clear()367 type(self).combined_factor.fget.cache_clear()368 type(self).combined_factor_data.fget.cache_clear()369 type(self).summaries.fget.cache_clear()370 @property371 @lru_cache()372 def price_data(self) -> pd.DataFrame:373 """Historical OHLCV candles data."""374 return get_price_data(375 instruments=self.instruments,376 granularity=self.granularity,377 count=self.count,378 symbol=self.symbol,379 )380 @property381 @lru_cache()382 def open(self) -> pd.DataFrame:383 """Opening price data."""384 return self.price_data.xs("open", axis=1, level=1)385 @property386 @lru_cache()387 def high(self) -> pd.DataFrame:388 """High price data."""389 return self.price_data.xs("high", axis=1, level=1)390 @property391 @lru_cache()392 def low(self) -> pd.DataFrame:393 """Low price data."""394 return self.price_data.xs("low", axis=1, level=1)395 @property396 @lru_cache()397 def close(self) -> pd.DataFrame:398 """Closing price data."""399 return self.price_data.xs("close", axis=1, level=1)400 @property401 @lru_cache()402 def volume(self) -> pd.DataFrame:403 """Tick volume data."""404 return self.price_data.xs("volume", axis=1, level=1)405 @property406 @lru_cache()407 def returns(self) -> pd.DataFrame:408 """Percentage change in the closing price data."""409 return self.close.pct_change()[1:]410 @property411 @lru_cache()412 def factor_data(self) -> Dict[str, pd.DataFrame]:413 """Individual factor values, quantiles, weights and returns."""414 factor_data = {}415 prefix = "Preparing factor data:"416 start_time = time.time()417 for i, (name, function) in enumerate(self.factors.items()):418 print_progress(i, len(self.factors), prefix, f"`{name}`")419 try:420 factor, s = function(self)421 except ValueError:422 factor, s = function(self), 3423 except TypeError:424 raise TypeError(f"`{name}` must return atleast factor.")425 factor_data[name] = get_factor_data(426 factor=factor,427 price_data=self.price_data,428 periods=self.periods,429 split=s,430 long_short=self.long_short,431 leverage=self.leverage,432 name=name,433 )434 suffix = f"in {time.time() - start_time:.1f} s"435 print_progress(len(self.factors), len(self.factors), prefix, suffix)436 return factor_data437 @property438 @lru_cache()439 def combined_factor(self) -> pd.DataFrame:440 """Single factor obtained by combination."""441 return combine_factors(self.factor_data, self.combination)442 @combined_factor.setter443 def combined_factor(self, value):444 self._combined_factor = value445 type(self).combined_factor_data.fget.cache_clear()446 @property447 @lru_cache()448 def combined_factor_data(self) -> pd.DataFrame:449 """Combined factor values, quantiles, weights and returns."""450 return get_factor_data(451 factor=self.combined_factor,452 price_data=self.price_data,453 periods=self.periods,454 split=self.split,455 long_short=self.long_short,456 leverage=self.leverage,457 name=f"{self.__class__.__name__}_combined",458 )459 @property460 @lru_cache()461 def summaries(self) -> List[pd.Series]:462 """Past performance summaries of individual factors."""463 summaries = []464 prefix = "Preparing performance:"465 start_time = time.time()466 for i, factor in enumerate(self.factor_data):467 print_progress(i, len(self.factor_data), prefix, f"`{factor}`")468 summaries.append(self.performance(factor, False))469 suffix = f"in {time.time() - start_time:.1f} s"470 print_progress(len(self.factor_data), len(self.factor_data), prefix, suffix)471 return summaries472 def __repr__(self):473 return f"{__class__.__name__}.{self.__class__.__name__}" f"{list(self.factors)}"474 def __len__(self):475 return len(self.factors)476 def __getitem__(self, name: str):477 return self.factors[name]478 def __setitem__(self, name: str, function: Factor):479 self.factors[name] = function480 type(self).factor_data.fget.cache_clear()481 type(self).combined_factor.fget.cache_clear()482 type(self).combined_factor_data.fget.cache_clear()483 type(self).summaries.fget.cache_clear()484 def __delitem__(self, name: str):485 del self.factors[name]486 type(self).factor_data.fget.cache_clear()487 type(self).combined_factor.fget.cache_clear()488 type(self).combined_factor_data.fget.cache_clear()489 type(self).summaries.fget.cache_clear()490 def __iter__(self):491 return iter(self.factors.items())492 def performance(493 self, factor: Optional[str] = None, output: bool = True494 ) -> pd.Series:495 """Return and show past performance summary."""496 if factor:497 log, summary = get_performance(self.factor_data[factor], output)498 if output:499 self.logger.info(log)500 return summary501 log, summary = get_performance(self.combined_factor_data, output)502 if output:503 self.logger.info(log)504 return summary505 def select(506 self,507 rules: str,508 swap_to: Optional[str] = None,509 inplace: bool = False,510 ) -> None:511 """Select factors that meet the given rules and optionally swap signs.512 Available metrics:513 - ic: Information Coefficient based on Spearman Rank Correlation514 - autocorr: Factor Rank Autocorrelation515 - sharpe: Annualized Sharpe Ratio516 - beta: Annualized Beta as exposure to trading universe517 - alpha: Annualized Alpha as excess returns over trading universe518 - win: Win Rate519 - rr: Risk / Reward Ratio520 - profit: Profit Factor = (sum of earnings) / (sum of losses)521 - cagr: Compound Annual Growth Rate522 """523 select = pd.concat(self.summaries, axis=1).T.query(rules)524 signs = pd.Series(1, select.index) if not swap_to else select[swap_to]525 signs[signs > 0], signs[signs < 0] = 1, -1526 if signs.empty:527 self.logger.error(f"No factor satisfies the rules `{rules}`.")528 else:529 self.logger.info(530 f"Factors with signs that meet the rules `{rules}`:\n"531 f"\n"532 f"{signs.to_string()}\n"533 )534 if inplace:535 factors = {}536 for name, sign in signs.items():537 if sign == 1:538 factors[name] = self.factors[name]539 elif sign == -1:540 factors["-" + name] = swap_sign(self.factors[name])541 self.factors = factors542 type(self).factor_data.fget.cache_clear()543 type(self).combined_factor.fget.cache_clear()544 type(self).combined_factor_data.fget.cache_clear()545 type(self).summaries.fget.cache_clear()546 def rebalance(547 self,548 accountID: str = os.getenv("OANDA_ACCOUNT_ID"),549 live: bool = False,550 keep_current_trades: bool = False,551 ) -> None:552 """Generate and place orders to rebalance portfolio."""553 weights = self.combined_factor_data["weights"]554 positions = weights.loc[weights.index.get_level_values("date")[-1]]555 positions.sort_values(inplace=True)556 hostname, headers = _get_hostname_headers()557 endpoint = f"/v3/accounts/{accountID}"558 url = hostname + endpoint559 req = ur.Request(url, headers=headers)...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...108@before_request109def update(info=None):110 if 'photo' in request.form:111 process_image(request.form['photo'][22:], info['uid'])112 get_image.cache_clear()113 ldap_update_profile(request.json, info['uid'])114 return jsonify({"success": True}), 200115@app.route('/upload', methods=['POST'])116@auth.oidc_auth117@before_request118def upload(info=None):119 if 'photo' in request.form:120 process_image(request.form['photo'][22:], info['uid'])121 get_image.cache_clear()122 return redirect('/', 302)123@app.route("/logout")124@auth.oidc_logout125def logout():126 return redirect("/", 302)127@app.route("/image/<uid>", methods=["GET"])128def image(uid):129 return get_image(uid)130@app.route('/clearcache')131@auth.oidc_auth132@before_request133def clear_cache(info=None):134 if not ldap_is_rtp(info['user_obj']):135 return redirect("/")136 ldap_get_active_members.cache_clear()137 ldap_get_intro_members.cache_clear()138 ldap_get_onfloor_members.cache_clear()139 ldap_get_current_students.cache_clear()140 ldap_get_all_members.cache_clear()141 ldap_get_groups.cache_clear()142 ldap_get_group_desc.cache_clear()143 ldap_get_eboard.cache_clear()144 ldap_search_members.cache_clear()145 ldap_get_year.cache_clear()146 get_image.cache_clear()147 get_gravatar.cache_clear()148 proxy_image.cache_clear()149 flash('Cache cleared!')150 return redirect(request.referrer, 302)151@app.errorhandler(404)152@app.errorhandler(500)153def handle_internal_error(e):154 if isinstance(e.original_exception, BadQueryError):155 return render_template("404.html", message=e.original_exception), 404156 raise e.original_exception157@app.route('/api/v1/healthcheck', methods=["GET"])158def health_check():159 # Return codes160 # 200 - Success161 # 512 - LDAP failure162 return_code = 200...

Full Screen

Full Screen

ldap.py

Source:ldap.py Github

copy

Full Screen

...74def ldap_is_current_student(account):75 return _ldap_is_member_of_group(account, 'current_student')76def ldap_set_housingpoints(account, housing_points):77 account.housingPoints = housing_points78 ldap_get_current_students.cache_clear()79 ldap_get_member.cache_clear()80def ldap_set_roomnumber(account, room_number):81 if room_number == "":82 room_number = None83 account.roomNumber = room_number84 ldap_get_current_students.cache_clear()85 ldap_get_member.cache_clear()86def ldap_set_active(account):87 _ldap_add_member_to_group(account, 'active')88 ldap_get_active_members.cache_clear()89 ldap_get_member.cache_clear()90def ldap_set_inactive(account):91 _ldap_remove_member_from_group(account, 'active')92 ldap_get_active_members.cache_clear()93 ldap_get_member.cache_clear()94def ldap_set_intro_member(account):95 _ldap_add_member_to_group(account, 'intromembers')96 ldap_get_intro_members().cache_clear()97 ldap_get_member.cache_clear()98def ldap_set_not_intro_member(account):99 _ldap_remove_member_from_group(account, 'intromembers')100 ldap_get_intro_members().cache_clear()101 ldap_get_member.cache_clear()102def ldap_set_current_student(account):103 _ldap_add_member_to_group(account, 'current_student')104 ldap_get_current_students.cache_clear()105 ldap_get_member.cache_clear()106def ldap_set_non_current_student(account):107 _ldap_remove_member_from_group(account, 'current_student')108 ldap_get_current_students.cache_clear()109 ldap_get_member.cache_clear()110def ldap_set_failed(account):111 _ldap_add_member_to_group(account, 'failed')112 ldap_get_member.cache_clear()113def ldap_set_bad_standing(account):114 _ldap_add_member_to_group(account, 'bad_standing')115 ldap_get_member.cache_clear()116def ldap_set_onfloor(account):117 _ldap_add_member_to_group(account, 'onfloor')118 ldap_get_onfloor_members.cache_clear()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful