StateOfTheArt-quant / sharpe

Licence: other
sharpe is a unified, interactive, general-purpose environment for backtesting or applying machine learning(supervised learning and reinforcement learning) in the context of quantitative trading

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to sharpe

QuantResearch
Quantitative analysis, strategies and backtests
Stars: ✭ 1,013 (+2969.7%)
Mutual labels:  quantitative-finance, backtesting-trading-strategies
FinancialToolbox.jl
Useful functions for Black–Scholes Model in the Julia Language
Stars: ✭ 31 (-6.06%)
Mutual labels:  quantitative-finance
Quant-Finance
Some notebooks with powerful trading strategies.
Stars: ✭ 42 (+27.27%)
Mutual labels:  quantitative-finance
AltoTrader
Automated crypto currency trading bot
Stars: ✭ 29 (-12.12%)
Mutual labels:  quantitative-finance
ML-Agents-with-Google-Colab
Train reinforcement learning agent using ML-Agents with Google Colab.
Stars: ✭ 27 (-18.18%)
Mutual labels:  reinforcement-learning-environments
qwack
A modern quantitative finance framework that makes the complex simple
Stars: ✭ 18 (-45.45%)
Mutual labels:  quantitative-finance
ib dl
Historical market data downloader using Interactive Brokers TWS
Stars: ✭ 43 (+30.3%)
Mutual labels:  quantitative-finance
quanttrader
Backtest and live trading in Python
Stars: ✭ 139 (+321.21%)
Mutual labels:  backtesting-trading-strategies
ml monorepo
super-monorepo for machine learning and algorithmic trading
Stars: ✭ 43 (+30.3%)
Mutual labels:  quantitative-finance
gym-hybrid
Collection of OpenAI parametrized action-space environments.
Stars: ✭ 26 (-21.21%)
Mutual labels:  reinforcement-learning-environments
AI4U
AI4U is a multi-engine plugin (Unity and Godot) that allows you to specify agents with reinforcement learning visually. Non-Player Characters (NPCs) of games can be designed using ready-made components. In addition, AI4U has a low-level API that allows you to connect the agent to any algorithm made available in Python by the reinforcement learni…
Stars: ✭ 34 (+3.03%)
Mutual labels:  reinforcement-learning-environments
storage
Multi-Factor Least Squares Monte Carlo energy storage valuation model (Python and .NET).
Stars: ✭ 24 (-27.27%)
Mutual labels:  quantitative-finance
MFLL
Use fuzzy logic control with PL/EL in MultiCharts
Stars: ✭ 19 (-42.42%)
Mutual labels:  quantitative-finance
PyFENG
Python Financial ENGineering (PyFENG package in PyPI.org)
Stars: ✭ 51 (+54.55%)
Mutual labels:  quantitative-finance
Black-Scholes-Option-Pricing-Model
Black Scholes Option Pricing calculator with Greeks and implied volatility computations. Geometric Brownian Motion simulator with payoff value diagram and volatility smile plots. Java GUI.
Stars: ✭ 25 (-24.24%)
Mutual labels:  quantitative-finance
portfolio allocation js
A JavaScript library to allocate and optimize financial portfolios.
Stars: ✭ 145 (+339.39%)
Mutual labels:  quantitative-finance
okama
Investment portfolio and stocks analyzing tools for Python with free historical data
Stars: ✭ 87 (+163.64%)
Mutual labels:  quantitative-finance
support resistance line
A well-tuned algorithm to generate & draw support/resistance line on time series. 根据时间序列自动生成支撑线压力线
Stars: ✭ 53 (+60.61%)
Mutual labels:  quantitative-finance
vsrl-framework
The Verifiably Safe Reinforcement Learning Framework
Stars: ✭ 42 (+27.27%)
Mutual labels:  reinforcement-learning-environments
HistoricalVolatility
A framework for historical volatility estimation and analysis.
Stars: ✭ 22 (-33.33%)
Mutual labels:  quantitative-finance

CI status

sharpe

sharpe is a unified, interactive, general-purpose environment for backtesting or applying machine learning(supervised learning and reinforcement learning) in the context of quantitative trading.

it's designed to allow maximum flexibility and simplicity in the practical research process: raw financial data -> feature engineering -> model training -> trading strategy -> backtesting, come in the reasonable level of abstraction.

core features:

  • unified: unify the supervised learning and reinforcement learning in a framework.
  • interactive: state(feature) -> action(portfolio-weight) -> reward(profit-and-loss/returns) bar-by-bar, allow maximum workflow control.
  • general-purpose: market-independent, instrument-independent, trading-frequency-independent.
sharpe is considered in early alpha release. Stuff might break.

outline

1 Motivation and concept design

Before we walk through an end-to-end example how to backtest a trading stratey with sharpe, let’s take a step back and discuss and understand the difficuties encountering when design a backtest engine for quantitative trading, the answer derives from quantitative researchers own different types of trading philosophy, trade different types of instruments in different markets with different trading frequencies.

  • different types of trading philosophy: rule-based methodology versus factor-based methodology(supervised learning versus reinforcement learning)
  • different types of instruments in different market: stock, index, ETF, future in different countries and markets.
  • different trading frequencies: intra-day trading(seconds, minutes, hours) and inter-day trading(daily, weekly, montly)

trading decison can be viewed as a special case of sequential decision-making, which can be formalized as follows: at each timestamp

  • a agent sees a observation of the state of the environment, that the agent lives in and interacts with
  • and then decides on an action to take, based on a policy(can be also called strategy, a mapping from state to action)
  • The agent perceives a reward signal from the environment, a number that tells it how good or bad the current action is
  • sees the observation of the next state, and iteratively

The goal of the agent is to find a good policy(strategy) to maximize its cumulative reward.

following this concept framwork, sharpe re-conceptualizes the process of trading and provides research with low-level, common tool to develop and backtest trading strategy.

2 Install

$ git clone https://github.com/StateOfTheArt-quant/sharpe
$ cd sharpe
$ python setup.py install

3 Quick Start

The following snippet showcases the whole workflow of trading strategy development in sharpe.

 from sharpe.utils.mock_data import create_toy_feature
 from sharpe.data.data_source import DataSource
 from sharpe.environment import TradingEnv
 from sharpe.mod.sys_account.api import order_target_weights
 import random
 random.seed(111)

 feature_df, price_s = create_toy_feature(order_book_ids_number=2, feature_number=3, start="2020-01-01", end="2020-01-11", random_seed=111)
 data_source = DataSource(feature_df=feature_df, price_s=price_s)

 env= TradingEnv(data_source=data_source, look_backward_window=4, mode="rl")
 print('----------------------------------------------------------------------')

 company_id = "000001.XSHE"


 def your_strategy(state):
      """
      here is a random strategy, only trade the first stock with a random target percent
      """

      target_percent_of_position =  round(random.random(),2)
      target_position_dict = {company_id : target_percent_of_position}
      print("the target portfolio is to be: {}".format(target_position_dict))
      # call trade API
      action = order_target_weights(target_position_dict)
      return action


 state = env.reset()

 while True:
      print("the current trading_dt is: {}".format(env.trading_dt))
      action = your_strategy(state)

      next_state, reward, done, info = env.step(action)
      print("the reward of this action: {}".format(reward))
      print("the next state is \n {}".format(next_state))
      if done:
           break
      else:
           state = next_state
env.render()

assets/images/unit_net_value.png

4 Documentation

5 Examples

6 Communication & Contributing

Working on your first Pull Request? You can learn how from this free series How to Contribute to an Open Source Project on GitHub

7 Acknowledgements

sharpe derived from our initial project trading_gym, which now is a event-driven(or observer) design pattern, the code highly inspired by RQALPHA

This library is named sharpe to respect William F. Sharpe

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].