Skip to content

Commit

Permalink
use standard target selector to select stocks
Browse files Browse the repository at this point in the history
  • Loading branch information
foolcage committed Nov 20, 2019
1 parent 1868f6f commit 1451a99
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion zvt/factors/factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self,
# child added arguments
keep_all_timestamp: bool = False,
fill_method: str = 'ffill',
effective_number: int = 10,
effective_number: int = None,
transformer: Transformer = None,
accumulator: Accumulator = None,
persist_factor: bool = True,
Expand Down
10 changes: 5 additions & 5 deletions zvt/factors/fundamental_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, data_schema=FinanceFactor,
FinanceFactor.op_income_growth_yoy,
FinanceFactor.net_profit_growth_yoy,
FinanceFactor.report_period],
filters: List = [FinanceFactor.roe > 0.03,
filters: List = [FinanceFactor.roe >= 0.03,
FinanceFactor.op_income_growth_yoy >= 0.1,
FinanceFactor.net_profit_growth_yoy >= 0.1],
order: object = None,
Expand All @@ -61,16 +61,16 @@ def __init__(self, data_schema=FinanceFactor,
category_field: str = 'entity_id',
time_field: str = 'timestamp',
computing_window: int = None,
keep_all_timestamp: bool = False,
keep_all_timestamp: bool = True,
fill_method: str = 'ffill',
effective_number: int = 10,
effective_number: int = None,
transformer: Transformer = None,
accumulator: Accumulator = None,
persist_factor: bool = False,
dry_run: bool = False,
# 3 years
window='1095d',
count=12
count=10
) -> None:
self.window = window
self.count = count
Expand All @@ -89,7 +89,7 @@ def filter_df(df):
elif row.report_period == 'season3':
se[index] = (row.roe >= 0.09)
elif row.report_period == 'half_year':
se[index] = (row.roe >= 0.08)
se[index] = (row.roe >= 0.06)
else:
se[index] = (row.roe >= 0.03)
return se
Expand Down
10 changes: 5 additions & 5 deletions zvt/factors/target_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from pandas import DataFrame

from zvdata import IntervalLevel
from zvt.drawer.drawer import Drawer
from zvt.factors.factor import FilterFactor, ScoreFactor, Factor
from zvdata.normal_data import NormalData
from zvdata.utils.pd_utils import index_df, pd_is_not_null
from zvdata.utils.time_utils import to_pd_timestamp, now_pd_timestamp
from zvdata.utils.time_utils import to_pd_timestamp
from zvt.api.quote import get_securities_in_blocks
from zvt.drawer.drawer import Drawer
from zvt.factors.factor import FilterFactor, ScoreFactor, Factor


class TargetType(Enum):
Expand Down Expand Up @@ -187,8 +187,8 @@ def generate_targets(self):
long_result = self.score_result[self.score_result.score >= self.long_threshold]
short_result = self.score_result[self.score_result.score <= self.short_threshold]
else:
long_result = self.filter_result[self.filter_result.score]
short_result = self.filter_result[~self.filter_result.score]
long_result = self.filter_result[self.filter_result.score == True]
short_result = self.filter_result[self.filter_result.score == False]

# filter in blocks
if self.block_selector:
Expand Down
12 changes: 5 additions & 7 deletions zvt/scheds/report2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import time

import pandas as pd
from apscheduler.schedulers.background import BackgroundScheduler

from zvdata.api import get_entities
Expand All @@ -28,15 +27,14 @@ def every_day_report():

today = to_time_str(t)

my_selector = TargetSelector(start_timestamp='2005-01-01', end_timestamp=today)
my_selector = TargetSelector(start_timestamp='2015-01-01', end_timestamp=today)
# add the factors
good_factor = GoodCompanyFactor(start_timestamp='2005-01-01', end_timestamp=today)
good_factor = GoodCompanyFactor(start_timestamp='2015-01-01', end_timestamp=today)

from_half_year = t - pd.Timedelta(days=140)
df = good_factor.result_df.reset_index()
df = df.loc[(df.timestamp >= from_half_year) & df['count']]
my_selector.add_filter_factor(good_factor)
my_selector.run()

long_targets = df.entity_id.to_list()
long_targets = my_selector.get_open_long_targets(today)
if long_targets:
long_targets = list(set(long_targets))
df = get_entities(provider='eastmoney', entity_schema=Stock, entity_ids=long_targets,
Expand Down

0 comments on commit 1451a99

Please sign in to comment.