回测系统编写

in python •  6 years ago 

想做一个回测系统,一开始选择了开源回测项目backtreader
这个回测系统确实是很厉害,但对我而言,它是一个未知的框架,我不可能把一个不熟悉的框架放进我的量化系统中。
于是我开始写,我自己的回测系统
回测系统共有4个部分:
1)数据源导入
2)数据流进策略
3)策略给出买卖信号(signal)
4)run

好的,现在开始干活:
'''

build in python3.5.2

author hashaki

回测

import numpy as np
import matplotlib.pyplot as plt

回测

class Strategy:
def init(self,time,volume,high,low,open=None,close=None):
self.time=np.asarray(time)
self.volume=volume
self.high=high
self.low=low
self.open=open
self.close=close

# 设置金额
def set_money(self,money):
    self.primiryMoney=money
    if money==0 or money<0:
        print( 'wrong input --hashaki')

# 策略主体
def strategy(self):
    pass

# 风险过滤
def risk_control(self):
    pass

def test_buy(self,precent):
    print("Are U sure?")

def test_sell(self,precent):
    print("Are U Sure?")

def buy(self):
    print("that s real buy")

def sell(self):
    print("that s real sell")

def run(self):
    pass

def plot(self):
    plt.subplot(2,1,1)
    plt.plot(self.time,self.volume,color='pink',label='volume')
    plt.legend()
    plt.title("BackTrade")
    plt.show()

# 传进交易深度
def depth(self,buy,sell,depthNum):
    pass

'''

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!