Skip to content

Commit

Permalink
1)fix wrong marshmallow version issue 2)add simple guides
Browse files Browse the repository at this point in the history
Former-commit-id: 25ebe65
  • Loading branch information
foolcage committed Nov 26, 2019
1 parent 7568e57 commit 7833f70
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 6 deletions.
Empty file removed MANIFEST.in
Empty file.
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

ZVT是在[fooltrader](https://github.com/foolcage/fooltrader)的基础上重新思考后编写的量化项目,其包含可扩展的数据recorder,api,因子计算,选股,回测,交易,以及统一的可视化,定位为**中低频** **多级别** **多因子** **多标的** 全市场分析和交易框架。

## 📝5分钟用起来
## 🔖5分钟用起来

>"一个系统,如果5分钟用不起来,那肯定是设计软件的人本身就没想清楚,并且其压根就没打算自己用。" ------ foolcage
Expand All @@ -24,6 +24,61 @@ pip3 install zvt ipython -i http://pypi.douban.com/simple --trusted-host pypi.do
```

进入ipython,体验一把
```
In [1]: import os
In [2]: os.environ["TESTING_ZVT"] = "1"
In [3]: from zvt import *
start unzip /Users/xuanqi/workspace/github/zvtvz/zvt/zvt/sample_data/data.zip to /Users/xuanqi/zvt-test-home/data
finish unzip /Users/xuanqi/workspace/github/zvtvz/zvt/zvt/sample_data/data.zip to /Users/xuanqi/zvt-test-home/data
zvt env:{'data_path': '/Users/xuanqi/zvt-test-home/data', 'domain_module': 'zvt.domain', 'ui_path': '/Users/xuanqi/zvt-test-home/ui', 'log_path': '/Users/xuanqi/zvt-test-home/logs', 'jq_username': None, 'jq_password': None}
In [5]: from zvt.api import *
In [6]: df = get_kdata(entity_id='stock_sz_000338',provider='joinquant')
n [8]: df.tail()
Out[8]:
id entity_id timestamp provider code name level open close high low volume turnover change_pct turnover_rate
timestamp
2019-10-29 stock_sz_000338_2019-10-29 stock_sz_000338 2019-10-29 joinquant 000338 潍柴动力 1d 12.00 11.78 12.02 11.76 28533132.0 3.381845e+08 None None
2019-10-30 stock_sz_000338_2019-10-30 stock_sz_000338 2019-10-30 joinquant 000338 潍柴动力 1d 11.74 12.05 12.08 11.61 42652561.0 5.066013e+08 None None
2019-10-31 stock_sz_000338_2019-10-31 stock_sz_000338 2019-10-31 joinquant 000338 潍柴动力 1d 12.05 11.56 12.08 11.50 77329380.0 9.010439e+08 None None
2019-11-01 stock_sz_000338_2019-11-01 stock_sz_000338 2019-11-01 joinquant 000338 潍柴动力 1d 11.55 12.69 12.70 11.52 160732771.0 1.974125e+09 None None
2019-11-04 stock_sz_000338_2019-11-04 stock_sz_000338 2019-11-04 joinquant 000338 潍柴动力 1d 12.77 13.00 13.11 12.77 126673139.0 1.643788e+09 None None
```

财务数据
```
In [12]: from zvt.domain import *
In [13]: df = get_finance_factor(entity_id='stock_sz_000338',columns=FinanceFactor.important_cols())
In [14]: df.tail()
Out[14]:
basic_eps total_op_income net_profit op_income_growth_yoy net_profit_growth_yoy roe rota gross_profit_margin net_margin timestamp
timestamp
2018-10-31 0.73 1.182000e+11 6.001000e+09 0.0595 0.3037 0.1647 0.0414 0.2164 0.0681 2018-10-31
2019-03-26 1.08 1.593000e+11 8.658000e+09 0.0507 0.2716 0.2273 0.0589 0.2233 0.0730 2019-03-26
2019-04-29 0.33 4.521000e+10 2.591000e+09 0.1530 0.3499 0.0637 0.0160 0.2166 0.0746 2019-04-29
2019-08-30 0.67 9.086000e+10 5.287000e+09 0.1045 0.2037 0.1249 0.0315 0.2175 0.0759 2019-08-30
2019-10-31 0.89 1.267000e+11 7.058000e+09 0.0721 0.1761 0.1720 0.0435 0.2206 0.0736 2019-10-31
```

跑个策略
```
In [15]: from zvt.samples import *
In [16]: t = MyMaTrader(codes=['000338'], level=IntervalLevel.LEVEL_1DAY, start_timestamp='2018-01-01',
...: end_timestamp='2019-06-30', trader_name='000338_ma_trader')
In [17]: t.run()
```
<p align="center"><img src='./docs/imgs/output-value.jpg'/></p>

## 📝配置正式环境

>待完善
**注意**
>可视化方面,master分支只保留行情指标功能,其他复杂功能在[draft分支](https://github.com/zvtvz/zvt/tree/draft)里面存档
Expand Down
Binary file added docs/imgs/output-value.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ apscheduler == 3.4.0
jqdatasdk
demjson == 2.2.4
marshmallow-sqlalchemy == 0.19.0
marshmallow == 3.2.2
ccxt == 1.17.191
plotly==4.1.0
simplejson==3.16.0
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# For a discussion on single-sourcing the version across setup.py and the
# project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.3.4', # Required
version='0.4.0', # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down Expand Up @@ -120,7 +120,7 @@
# https://packaging.python.org/en/latest/requirements.html

install_requires=['zvdata>=1.0.5', 'Scrapy>=1.5.1', 'requests>=2.20.1', 'SQLAlchemy>=1.2.14', 'pandas>=0.24.2',
'arrow>=0.11.0',
'arrow>=0.11.0', 'marshmallow >= 3.2.2',
'tzlocal>=1.5.1', 'xlrd>=1.1.0', 'apscheduler>=3.4.0', 'jqdatasdk', 'demjson>=2.2.4',
'marshmallow-sqlalchemy>=0.19.0', 'ccxt>=1.17.191', 'plotly>=4.1.0', 'simplejson>=3.16.0'
'html5lib>=1.0.1',
Expand Down
1 change: 0 additions & 1 deletion zvt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def init_env(zvt_home: str,

init_schema()


if os.getenv('TESTING_ZVT'):
init_env(zvt_home=ZVT_TEST_HOME)
unzip(DATA_SAMPLE_ZIP_PATH, ZVT_TEST_DATA_PATH)
Expand Down
Empty file removed zvt/sample_data/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions zvt/samples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from .stock_traders import *
File renamed without changes.
52 changes: 52 additions & 0 deletions zvt/samples/stock_traders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
from zvdata import IntervalLevel
from zvt.factors.ma.ma_factor import CrossMaFactor
from zvt.factors.target_selector import TargetSelector
from zvt.factors.technical_factor import BullFactor

from zvt.trader.trader import StockTrader


class MyMaTrader(StockTrader):
def init_selectors(self, entity_ids, entity_type, exchanges, codes, start_timestamp, end_timestamp):
myselector = TargetSelector(entity_ids=entity_ids, entity_type=entity_type, exchanges=exchanges,
codes=codes, start_timestamp=start_timestamp, end_timestamp=end_timestamp,
provider='joinquant')

myselector.add_filter_factor(
CrossMaFactor(entity_ids=entity_ids, entity_type=entity_type, exchanges=exchanges,
codes=codes, start_timestamp=start_timestamp, end_timestamp=end_timestamp,
windows=[5, 10], persist_factor=False))

self.selectors.append(myselector)


class MyBullTrader(StockTrader):
def init_selectors(self, entity_ids, entity_type, exchanges, codes, start_timestamp, end_timestamp):
myselector = TargetSelector(entity_ids=entity_ids, entity_type=entity_type, exchanges=exchanges,
codes=codes, start_timestamp=start_timestamp, end_timestamp=end_timestamp,
provider='joinquant')

myselector.add_filter_factor(
BullFactor(entity_ids=entity_ids, entity_type=entity_type, exchanges=exchanges,
codes=codes, start_timestamp=start_timestamp, end_timestamp=end_timestamp))

self.selectors.append(myselector)


if __name__ == '__main__':
# single stock with cross ma factor
MyMaTrader(codes=['000338'], level=IntervalLevel.LEVEL_1DAY, start_timestamp='2018-01-01',
end_timestamp='2019-06-30', trader_name='000338_ma_trader').run()

# single stock with bull factor
# MyBullTrader(codes=['000338'], level=IntervalLevel.LEVEL_1DAY, start_timestamp='2018-01-01',
# end_timestamp='2019-06-30', trader_name='000338_bull_trader').run()

# multiple stocks with cross ma factor
# MyMaTrader(codes=SAMPLE_STOCK_CODES, level=IntervalLevel.LEVEL_1DAY, start_timestamp='2018-01-01',
# end_timestamp='2019-06-30', trader_name='sample_stocks_ma_trader').run()

# multiple stocks with bull factor
# MyBullTrader(codes=SAMPLE_STOCK_CODES, level=IntervalLevel.LEVEL_1DAY, start_timestamp='2018-01-01',
# end_timestamp='2019-06-30', trader_name='sample_stocks_bull_trader').run()
2 changes: 1 addition & 1 deletion zvt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ZVT_TEST_HOME = os.path.abspath(os.path.join(Path.home(), 'zvt-test-home'))
ZVT_TEST_DATA_PATH = os.path.join(ZVT_TEST_HOME, 'data')

DATA_SAMPLE_ZIP_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), 'sample_data', 'data.zip'))
DATA_SAMPLE_ZIP_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), 'samples', 'data.zip'))

# please change the path to your real store path
ZVT_HOME = os.path.abspath(os.path.join(Path.home(), 'zvt-home'))
Expand Down
10 changes: 9 additions & 1 deletion zvt/trader/trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

from zvdata import IntervalLevel
from zvdata.contract import get_db_session
from zvdata.normal_data import NormalData
from zvdata.utils.time_utils import to_pd_timestamp, now_pd_timestamp
from zvt.api.business import get_trader
from zvt.api.common import get_one_day_trading_minutes, decode_entity_id
from zvt.api.rules import iterate_timestamps, is_open_time, is_in_finished_timestamps, is_close_time, is_trading_date
from zvt.domain import business
from zvt.drawer.drawer import Drawer
from zvt.factors.target_selector import TargetSelector
from zvt.reader.business_reader import AccountReader
from zvt.trader import TradingSignal, TradingSignalType
from zvt.trader.account import SimAccountService

Expand Down Expand Up @@ -306,7 +309,12 @@ def send_trading_signals(self, timestamp, long_selected, short_selected):

def on_finish(self):
# show the result
pass
import plotly.io as pio
pio.renderers.default = "browser"
reader = AccountReader(trader_names=[self.trader_name])
drawer = Drawer(main_data=NormalData(reader.data_df.copy()[['trader_name', 'timestamp', 'all_value']],
category_field='trader_name'))
drawer.draw_line()

def run(self):
# iterate timestamp of the min level,e.g,9:30,9:35,9.40...for 5min level
Expand Down

0 comments on commit 7833f70

Please sign in to comment.