Skip to content

Commit

Permalink
@new change
Browse files Browse the repository at this point in the history
  • Loading branch information
yutiansut committed Jun 19, 2017
1 parent faaf315 commit ef4f044
Show file tree
Hide file tree
Showing 9 changed files with 477 additions and 78 deletions.
5 changes: 1 addition & 4 deletions QUANTAXIS/QAARP/QAAccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import random
import time

from tabulate import tabulate

# 2017/6/4修改: 去除总资产的动态权益计算

Expand Down Expand Up @@ -196,9 +195,7 @@ def QA_account_update(self, __update_message):
'history': self.history,
'cash': self.cash,
'assets': self.assets,
'detail': tabulate(self.detail, headers=('date', 'code', 'price',
'amounts', 'sell_price', 'order_id', 'trade_id',
'sell_order_id', 'sell_trade_id', 'left_amount', 'commission'))
'detail': self.detail
},
'time': str(datetime.datetime.now()),
'date_stamp': str(time.mktime(datetime.datetime.now().timetuple()))
Expand Down
393 changes: 365 additions & 28 deletions QUANTAXIS/QABacktest/QABacktest.py

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions QUANTAXIS/QABacktest/backtest_setting.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[backtest]
strategy_start_date=2017-01-01
strategy_end_date=2017-06-15

#file:type:local
#file:type:dirname
#mongo:db-coll:path

strategy_gap=6

database_ip=127.0.0.1
username=admin
password=admin
strategy_name=test_strategy


[account]

account_assets=250000
strategy_stock_list=file:csv:local
3 changes: 3 additions & 0 deletions QUANTAXIS/QAMarket/QABid.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ def __init__(self):
'user': str('root'),
'strategy': str('example01'),
'status': '0x01',
'bid_model':'strategy',
'amount_model':'amount',
'order_id': str(random.random())
}
self.bid_list = [self.bid]

# 报价队列 插入/取出/查询

def QA_bid_insert(self):
Expand Down
26 changes: 17 additions & 9 deletions QUANTAXIS/QAMarket/QAMarket_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,23 @@ def __trading(__bid, __item):
__bid_t['price'] = (float(__item["high"]) +
float(__item["low"])) * 0.5
return __trading(__bid_t, __item)
else:
if ((float(__bid['price']) < float(__item["high"]) and
float(__bid['price']) > float(__item["low"])) or
float(__bid['price']) == float(__item["low"]) or
float(__bid['price']) == float(__item['high'])):

elif __bid['price'] == 'close_price':
__bid_t = __bid
__bid_t['price'] = float(__item["close"])
return __trading(__bid_t, __item)
else:
if __bid['amount_model'] == 'price':
__bid_s = __bid
__bid_s['amount'] = int(
__bid['amount'] / (__bid['price'] * 100)) * 100
__bid_s['amount_model'] = 'amount'
return __trading(__bid_s, __item)
elif ((float(__bid['price']) < float(__item["high"]) and
float(__bid['price']) > float(__item["low"])) or
float(__bid['price']) == float(__item["low"]) or
float(__bid['price']) == float(__item['high'])):
if float(__bid['amount']) < float(__item['volume']) * 100 / 16:

__deal_price = __bid['price']
elif float(__bid['amount']) >= float(__item['volume']) * 100 / 16 and \
float(__bid['amount']) < float(__item['volume']) * 100 / 8:
Expand Down Expand Up @@ -84,7 +93,6 @@ def __trading(__bid, __item):
float(__deal_price) * float(__bid['amount'])
if __commission_fee < 5:
__commission_fee = 5

return {
'header': {
'source': 'market',
Expand Down Expand Up @@ -148,8 +156,8 @@ def __trading(__bid, __item):
'volume': 0,
'code': 0
},
'fee':{
'commission':0
'fee': {
'commission': 0
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions test/backtest_setting.ini

This file was deleted.

31 changes: 31 additions & 0 deletions test/new_test/backtest_setting.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[backtest]
strategy_start_date=2017-01-01
strategy_end_date=2017-06-15



strategy_gap=6

database_ip=127.0.0.1
username=admin
password=admin
strategy_name=test_strategy
benchmark_code=hs300

[account]

account_assets=250000
stock_list=file:csv:local
#file:type:local
#file:type:dirname
#mongo:db-coll:path


[bid]

bid_model=market_price
#close_price/market_price/strategy


[strategy]
file_path=file:py:local
40 changes: 40 additions & 0 deletions test/new_test/strategy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# coding:utf-8
import random

import QUANTAXIS as QA


class strategy:
"""
携带一个函数句柄
"""
@classmethod
def setting(self):
pass

@classmethod
def predict(self, market, account, hold):
"""
一个极其简单的示例策略,随机 随机真的随机
"""

if hold == 0:
__dat = random.random()
if __dat > 0.5:

return {'if_buy': 1, 'amount':'mean'}
else:
return {'if_buy': 0,'amount': 'mean'}
else:
__dat = random.random()
if __dat > 0.5:
return {'if_buy': 1,'amount': 'mean'}
else:

return {'if_buy': 0,'amount': 'all'}


d = QA.QA_Backtest()

d.QA_backtest_init()
d.QA_backtest_start(strategy())
20 changes: 0 additions & 20 deletions test/strategy.py

This file was deleted.

0 comments on commit ef4f044

Please sign in to comment.