Strategy.py
2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from Investment.Strategy.StrategyBase import StrategyBase
from Investment.Strategy.FinancialStatementsStrategyBase import FinancialStatementsStrategyBase
from datetime import date
class Strategy(FinancialStatementsStrategyBase):
def __init__(self):
super().__init__()
def __repr__(self):
return self.Name
def setStrategy(self, per=None, pbr_up=None, pbr_down=None, roe=None, order='PER'):
super().setStrategy()
self.Name = 'PER_ROE_V1.0'
self.NumberOfStocks = 10
self.AdditionalFinancialStatementsItem = ['PER', 'PBR', 'ROE']
# self.FinancialStatementsCondition = '(PER > 6) and (ROE > 10) and (PBR > 0.5) and (PBR < 1)'
self.setFinancialStatementsCondition(per, pbr_up, pbr_down, roe)
print(self.FinancialStatementsCondition)
# self.FinancialStatementsCondition = '(PER > 0) and (PER < 20) and (ROE > 10)'
# self.FinancialStatementsCondition = '(PBR < 1)'
self.FinancialStatementsYear = 2016
self.FinancialStatementsQuater = 4
self.FinancialStatementsDiv = 'CFS'
self.StockDate = date(2017, 4, 10)
self.FinancialStatementsSearchTarget = ['StockCode', 'Equity', 'ProfitLoss']
self.StockSearchTarget = ['MarketCapitalization']
self.FinancialStatementsOrderBy = [order]
if order == 'PER':
self.FinancialStatementsOrderMethod = 'asc'
else:
self.FinancialStatementsOrderMethod = 'desc'
# self.FinancialStatementsOrderBy.append('ROE')
# self.FinancialStatementsOrderMethod = 'desc'
def setFinancialStatementsCondition(self, per, pbr_up, pbr_down, roe):
self.FinancialStatementsCondition = ''
if per is not None:
self.FinancialStatementsCondition += f'(PER > {per})'
if pbr_up:
if len(self.FinancialStatementsCondition) == 0:
self.FinancialStatementsCondition += f'(PBR > {pbr_up})'
else:
self.FinancialStatementsCondition += f' and (PBR > {pbr_up})'
if pbr_down:
if len(self.FinancialStatementsCondition) == 0:
self.FinancialStatementsCondition += f'(PBR < {pbr_down})'
else:
self.FinancialStatementsCondition += f' and (PBR < {pbr_down})'
if roe:
if len(self.FinancialStatementsCondition) == 0:
self.FinancialStatementsCondition += f'(ROE > {roe})'
else:
self.FinancialStatementsCondition += f' and (ROE > {roe})'
def searchData(self):
return FinancialStatementsStrategyBase.searchData(self)
def setAdditionalData(self):
return FinancialStatementsStrategyBase.setAdditionalData(self)