Giter Club home page Giter Club logo

strand's Introduction

strand: A framework for investment strategy simulation

CRAN status Build Status codecov

Overview

strand provides a framework for performing discrete (share-level) simulations of investment strategies. Simulated portfolios optimize exposure to an input signal subject to constraints such as position size and factor exposure.

The package vignette provides an in-depth discussion of setup and usage. See vignette("strand").

Features

  • Straightforward data interfaces.
  • Option to load daily data from binary (feather) files for fast access and low memory footprint.
  • Share-level bookkeeping.
  • YAML-based configuration.
  • Position sizing based on portfolio weight and percentage of expected volume.
  • Trade sizing based on percentage of expected volume.
  • Ability to specify constraints on factor exposure, category exposure, and turnover.
  • Automatic loosening of factor and category exposure constraints if no solution is found.
  • Realistic trade filling based on percentage of actual volume.

Tiingo and EDGAR sample data

The package’s sample data set includes value and size factors, as well as daily pricing information, for most of the stocks in the S&P 500 for the period June-August 2020. The source of fundamental data is EDGAR, and all pricing data was downloaded using the Tiingo Stock API. Special thanks to Tiingo for giving permission to release this data.

Installation

# Install the latest version from CRAN:
install.packages("strand")

# Install development version from GitHub using remotes:
install.packages("remotes")
remotes::install_github("strand-tech/strand")

Note on solvers

The strand package uses GLPK as the default solver for portfolio optimization. As a result, it depends on package Rglpk.

It is possible to use SYMPHONY instead, by setting solver: symphony in the simulation’s configuration file and installing the Rsymphony package. Note that you will need to install SYMPHONY on your system first, and on OS X perform a few extra steps to install Rsymphony.

Usage

Four ingredients are required to run a simulation using strand:

  1. Configuration file. A file in yaml format that describes the parameters of the simulation, such as the input signal, risk constraints, trading limits, position limits, the location of data inputs, etc.

  2. Security reference. A listing of all securities allowed in the simulation and any categorical values (such as sector and industry) that can be used in exposure constraints.

  3. Signal, factor, and supplementary data. Data for each day including the input signal (to which exposure is maximized) and any factors that appear in constraints. Supplementary data could include, for example, a daily measure of market capitalization for use in universe construction.

  4. Pricing data. Daily prices, dividends, and trading volume for computing market values and filling orders. Unadjusted prices and accompanying adjustment ratios may be used.

library(strand)

# Load up sample data
data(sample_secref)
data(sample_pricing)
data(sample_inputs)

# Load sample configuration file
config <- example_strategy_config()

# Create the Simulation object and run
sim <- Simulation$new(config,
                      raw_input_data = sample_inputs,
                      raw_pricing_data = sample_pricing,
                      security_reference_data = sample_secref)
sim$run()

# Print overall statistics
sim$overallStatsDf()
##                            Item   Gross       Net
## 1                     Total P&L -32,355   -40,867
## 2       Total Return on GMV (%)    -1.8      -2.3
## 3  Annualized Return on GMV (%)    -6.9      -8.7
## 4            Annualized Vol (%)     8.9       8.8
## 5             Annualized Sharpe   -0.77     -0.98
## 6              Max Drawdown (%)    -6.6      -6.8
## 7                       Avg GMV         1,976,540
## 8                       Avg NMV              -716
## 9                     Avg Count               189
## 10           Avg Daily Turnover            53,022
## 11      Holding Period (months)               3.6

Example shiny application (local)

To run an example shiny application that allows interactively configuring and running a simulation:

library(strand)
example_shiny_app()

Example shiny application (docker)

If you have docker and docker-compose installed, you can run the example shiny application by cloning the github repository and running the following commands from the top-level directory:

$ docker-compose build
$ docker-compose up

The application will run by default on port 80. To configure edit docker-compose.yml.

strand's People

Contributors

jeffreyenos avatar rbthoover avatar bczekanski avatar nbwosm 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.