forked from zvtvz/zvt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1)improve target selector 2)add examples
- Loading branch information
Showing
10 changed files
with
331 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
import logging | ||
|
||
from apscheduler.schedulers.background import BackgroundScheduler | ||
|
||
from examples.report_utils import report_top_entites | ||
from zvt import init_log | ||
from zvt.api import TopType | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
sched = BackgroundScheduler() | ||
|
||
|
||
@sched.scheduled_job("cron", hour=17, minute=0, day_of_week="mon-fri") | ||
def report_top_stocks(): | ||
report_top_entites( | ||
entity_type="stock", | ||
entity_provider="em", | ||
data_provider="em", | ||
periods=[3, 8, 30], | ||
ignore_new_stock=True, | ||
adjust_type=None, | ||
top_count=20, | ||
turnover_threshold=400000000, | ||
turnover_rate_threshold=0.02, | ||
em_group_over_write=True, | ||
return_type=TopType.positive, | ||
) | ||
report_top_entites( | ||
entity_type="stock", | ||
entity_provider="em", | ||
data_provider="em", | ||
periods=[365], | ||
ignore_new_stock=True, | ||
adjust_type=None, | ||
top_count=30, | ||
turnover_threshold=200000000, | ||
turnover_rate_threshold=0.02, | ||
em_group_over_write=True, | ||
return_type=TopType.negative, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
init_log("report_top_stocks.log") | ||
|
||
report_top_stocks() | ||
|
||
sched.start() | ||
|
||
sched._thread.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# -*- coding: utf-8 -*- | ||
from typing import Optional, Type, List, Union | ||
|
||
import pandas as pd | ||
|
||
from zvt.api import get_top_performance_by_month | ||
from zvt.api.selector import get_players | ||
from zvt.contract import TradableEntity, IntervalLevel, AdjustType | ||
from zvt.contract.factor import Transformer, Accumulator | ||
from zvt.domain import Stock | ||
from zvt.factors import TechnicalFactor | ||
from zvt.utils import pd_is_not_null, pre_month_start_date, next_date | ||
|
||
|
||
def top_dragon_and_tiger(data_provider="em", start_timestamp="2021-01-01", end_timestamp="2022-01-01"): | ||
dfs = [] | ||
for start_date, end_date, df in get_top_performance_by_month( | ||
start_timestamp=start_timestamp, end_timestamp=end_timestamp, list_days=250, data_provider=data_provider | ||
): | ||
pre_month_start = pre_month_start_date(start_date) | ||
for entity_id in df.index[:30]: | ||
players = get_players( | ||
entity_id=entity_id, | ||
start_timestamp=next_date(start_date, 15), | ||
end_timestamp=end_timestamp, | ||
provider=data_provider, | ||
direction="in", | ||
) | ||
print(players) | ||
dfs.append(players) | ||
|
||
player_df = pd.concat(dfs, sort=True) | ||
return player_df.sort_index(level=[0, 1]) | ||
|
||
|
||
class DragonTigerFactor(TechnicalFactor): | ||
def __init__( | ||
self, | ||
entity_id: str, | ||
entity_schema: Type[TradableEntity] = Stock, | ||
provider: str = "em", | ||
entity_provider: str = "em", | ||
exchanges: List[str] = None, | ||
codes: List[str] = None, | ||
start_timestamp: Union[str, pd.Timestamp] = None, | ||
end_timestamp: Union[str, pd.Timestamp] = None, | ||
columns: List = None, | ||
filters: List = None, | ||
order: object = None, | ||
limit: int = None, | ||
level: Union[str, IntervalLevel] = IntervalLevel.LEVEL_1DAY, | ||
category_field: str = "entity_id", | ||
time_field: str = "timestamp", | ||
computing_window: int = None, | ||
keep_all_timestamp: bool = False, | ||
fill_method: str = "ffill", | ||
effective_number: int = None, | ||
transformer: Transformer = None, | ||
accumulator: Accumulator = None, | ||
need_persist: bool = False, | ||
only_compute_factor: bool = False, | ||
factor_name: str = None, | ||
clear_state: bool = False, | ||
only_load_factor: bool = False, | ||
adjust_type: Union[AdjustType, str] = None, | ||
) -> None: | ||
super().__init__( | ||
entity_schema, | ||
provider, | ||
entity_provider, | ||
[entity_id], | ||
exchanges, | ||
codes, | ||
start_timestamp, | ||
end_timestamp, | ||
columns, | ||
filters, | ||
order, | ||
limit, | ||
level, | ||
category_field, | ||
time_field, | ||
computing_window, | ||
keep_all_timestamp, | ||
fill_method, | ||
effective_number, | ||
transformer, | ||
accumulator, | ||
need_persist, | ||
only_compute_factor, | ||
factor_name, | ||
clear_state, | ||
only_load_factor, | ||
adjust_type, | ||
) | ||
self.player_df = get_players( | ||
entity_id=entity_id, | ||
start_timestamp=start_timestamp, | ||
end_timestamp=end_timestamp, | ||
provider="em", | ||
direction="in", | ||
) | ||
|
||
def drawer_annotation_df(self) -> Optional[pd.DataFrame]: | ||
def order_type_flag(df): | ||
return "<br>".join(df.tolist()) | ||
|
||
if pd_is_not_null(self.player_df): | ||
annotation_df = self.player_df.copy() | ||
annotation_df["value"] = self.factor_df.loc[annotation_df.index]["close"] | ||
annotation_df["flag"] = annotation_df[["dep1", "dep2", "dep3", "dep4", "dep5"]].apply( | ||
lambda x: order_type_flag(x), axis=1 | ||
) | ||
annotation_df["color"] = "#ff7f0e" | ||
return annotation_df | ||
|
||
|
||
if __name__ == "__main__": | ||
top_dragon_and_tiger() | ||
# Stock1dHfqKdata.record_data(entity_id="stock_sz_002561", provider="em") | ||
# f = DragonTigerFactor(entity_id="stock_sz_002561", provider="em") | ||
# f.draw(show=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.