Coder Social home page Coder Social logo

onepy's Introduction

Onepy 2.00

Onepy is an event-driven algorithmic trading Python library.

知乎专栏:OnePy-基于Python的量化回测框架

更新日志:Change Log

1.x版本请查看OnePy 1.52

PS. 缓慢更新中~

Install

Onepy is developed using Python 3.6.x. You can install by pip and make sure they are up-to-date

pip install pandas
pip install plotly
pip install funcy
pip install arrow
pip install pymongo
pip install dataclasses # 将在python 3.7中成为标准库

pip install OnePy_trader
pip install --upgrade OnePy_trader
# pip的OnePy_trader有可能有时不是最新,建议将库克隆到本地使用。

Getting Started

请参考examples中的Tutorial.

import OnePy as op
from OnePy.builtin_module.recorders.stock_recorder import StockRecorder
from OnePy.custom_module.cleaner_sma import SMA


class SmaStrategy(op.StrategyBase):

    def __init__(self):

        super().__init__()
        self.sma1 = SMA(3, 40).calculate
        self.sma2 = SMA(5, 40).calculate

        self.sma3 = SMA(15, 40).calculate
        self.sma4 = SMA(30, 60).calculate

    def handle_bar(self):
        if self.sma1('000001') > self.sma2('000001'):
            self.buy(100, '000001', takeprofit=15,
                     stoploss=100, trailingstop_pct=0.1)
        else:
            self.sell(100, '000001')

        if self.sma3('000001') < self.sma4('000001'):
            self.short_sell(100, '000001', takeprofit=15,
                            stoploss=100, trailingstop_pct=0.1)
        else:
            self.short_cover(100, '000001')


op.data_readers.MongodbReader(
    database='tushare', collection='000001', ticker='000001',
    fromdate='2017-05-25', todate='2018-03-09')

SmaStrategy()

op.RiskManagerBase()
op.BrokerBase()

StockRecorder().set_setting(initial_cash=100000,
                            comm=1, comm_pct=None, margin_rate=0.1)
go = op.OnePiece()
go.logger.set_info(file=False)
go.sunny()
# go.output.show_setting()
go.output.plot('000001')
print(go.output.trade_log())
+--------------------------+
| Final_Value  | $99805.90 |
| Total_return | -0.19410% |
| Max_Drawdown | 0.49000%  |
| Duration     |     359.0 |
| Sharpe_Ratio | -0.38212  |
+--------------------------+

Plot Log

Road Map

执行过程

Contact

I'm very interested in your experience with Onepy.Please feel free to contact me via [email protected]

Chandler_Chan

onepy's People

Contributors

chandlercjy avatar

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.