Giter VIP home page Giter VIP logo

Comments (4)

yutiansut avatar yutiansut commented on August 27, 2024

这样会把用户回测的时候的目录里面的函数引入的回测框架内

from quantaxis.

yutiansut avatar yutiansut commented on August 27, 2024
#框架内部

try:
    sys.path.append(os.getcwd())
    print('loading strategy from'+ os.getcwd())
    import user_strategy
    from user_strategy import before_backtest, before_trading, handle_bar, end_trading, end_backtest
except:
    QA_util_log_info(Exception)


def strategy_dec(func, *a, **b):

    def deoc(*a, **b):
        before_trading()
        handle_bar()
        func(*a, **b)
        end_trading()
    return deoc


def backtest_dec(func, *a, **b):

    def inside_backtest(*a, **b):
        before_backtest()
        func(*a, **b)
        end_backtest()
    return inside_backtest


class backtest():

    @backtest_dec
    @strategy_dec
    def exec_bid(self):
        print('from backtest_framework: exec bid market and account')


"""
loading strategy fromC:\Users\yutiansut\quantaxis\test\new_test
import successfully
from strategy: befor_backtest
from strategy: befor_trading
from strategy: handle_bar
from backtest_framework: exec bid market and account
from strategy: end_trading
from strategy: end_bar
"""

用户策略:

print('import successfully')

def before_backtest():
    print('from strategy: befor_backtest')
def before_trading():
    print('from strategy: befor_trading')
    
def handle_bar():
    print('from strategy: handle_bar')


def end_trading():
    print('from strategy: end_trading')

def end_backtest():
    print('from strategy: end_bar')
    

from quantaxis.

yutiansut avatar yutiansut commented on August 27, 2024

继续完善

回测框架用类的形式

class backtest():
    cash=10000
    def __init__(self,):
        pass
    
    @classmethod
    def before_backtest(backtest,func,*a,**b):
        #yield backtest.cash
        return func(backtest,*a,**b)

    
    @classmethod
    def before_trading(backtest,func,*a,**b):
        #yield backtest.cash
        return func(backtest,*a,**b)



    @classmethod
    def strategy(backtest,func,*a,**b):
        
        return func(backtest,*a,**b)
    @classmethod
    def end_trading(backtest,func,*a,**b):
        #yield backtest.cash
        return func(backtest,*a,**b)
    
    def exec_bid(self,bid):
        print(bid)
        self.cash+=bid
        
from xxx import backtest

@backtest.before_trading
def before_trading(backtest):
    print(backtest.cash)


@backtest.strategy
def handle_bar(backtest):
    print('x')
    print(backtest.cash)
    backtest.exec_bid(backtest,1000)
    print(backtest.cash)


if __name__=='__main__':
    before_trading
    handle_bar

from quantaxis.

yutiansut avatar yutiansut commented on August 27, 2024

新的回测框架

from quantaxis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.