strand-package: strand: a framework for investment strategy simulation

Description Author(s) Examples

Description

The strand package 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.

For an introduction to running simulations using the package, see vignette("strand"). For details on available methods see the documentation for the Simulation class.

Author(s)

Jeff Enos jeffrey.enos@gmail.com and David Kane dave.kane@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Load up sample data
data(sample_secref)
data(sample_pricing)
data(sample_inputs)

# Load sample configuration
config <- example_strategy_config()

# Override config file end date to run a one-week sim
config$to <- as.Date("2020-06-05")

# 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()

# Access tabular result data
head(sim$getSimSummary())
head(sim$getSimDetail())
head(sim$getPositionSummary())
head(sim$getInputStats())
head(sim$getOptimizationSummary())
head(sim$getExposures())

# Plot results
## Not run: 
sim$plotPerformance()
sim$plotMarketValue()
sim$plotCategoryExposure("sector") 
sim$plotFactorExposure(c("value", "size"))
sim$plotNumPositions()

## End(Not run)

Example output

                           Item  Gross       Net
1                     Total P&L 53,576    51,516
2       Total Return on GMV (%)    2.9       2.7
3  Annualized Return on GMV (%)  144.3     136.1
4            Annualized Vol (%)    5.8       6.4
5             Annualized Sharpe  24.86     21.21
6              Max Drawdown (%)    0.8       0.8
7                       Avg GMV        1,666,104
8                       Avg NMV           17,740
9                     Avg Count              164
10           Avg Daily Turnover          376,989
11      Holding Period (months)              0.4
# A tibble: 6 x 25
  strategy market_fill_nmv transfer_fill_nstart_nmv end_nmv market_order_gmv
  <chr>              <dbl>            <dbl>     <dbl>   <dbl>            <dbl>
1 joint              2734.                0        0    2734.         1017629.
2 strateg2734.                0        0    2734.         1017629.
3 joint              -675.                0     2734.   8418.          496977.
4 strateg-675.                0     2734.   8418.          496977.
5 joint             -3530.                0     8418.  19101.          243155.
6 strateg-3530.                0     8418.  19101.          243155.
# … with 19 more variables: market_fill_gmv <dbl>, transfer_fill_gmv <dbl>,
#   end_gmv <dbl>, position_pnl <dbl>, trading_pnl <dbl>, gross_pnl <dbl>,
#   net_pnl <dbl>, trade_costs <dbl>, financing_costs <dbl>,
#   fill_rate_pct <dbl>, end_lmv <dbl>, end_smv <dbl>, start_lmv <dbl>,
#   start_smv <dbl>, end_num <int>, end_num_long <int>, end_num_short <int>,
#   num_investable <int>, sim_date <date>
# A tibble: 6 x 38
  id    strategy shares order_shares int_shares ext_shares market_order_sh<chr> <chr>     <dbl>        <dbl>      <dbl>      <dbl>            <int>
1 AAL   strateg0         -952          0          0             -952
2 ABBV  strateg0         -108          0          0             -108
3 ADM   strateg0          254          0          0              254
4 ADSK  strateg0          -48          0          0              -48
5 AIG   strateg0          333          0          0              333
6 ALLE  strateg0         -100          0          0             -100
# … with 31 more variables: transfer_order_shares <int>,
#   market_fill_shares <int>, transfer_fill_shares <int>, end_int_shares <int>,
#   end_ext_shares <int>, fill_shares <int>, end_shares <dbl>,
#   start_price <dbl>, end_price <dbl>, dividend <dbl>, distribution <dbl>,
#   investable <lgl>, delisting <lgl>, value <dbl>, position_pnl <dbl>,
#   trading_pnl <dbl>, trade_costs <dbl>, financing_costs <dbl>,
#   gross_pnl <dbl>, net_pnl <dbl>, market_order_gmv <dbl>,
#   market_fill_nmv <dbl>, market_fill_gmv <dbl>, transfer_fill_nmv <dbl>,
#   transfer_fill_gmv <dbl>, start_nmv <dbl>, end_nmv <dbl>, end_gmv <dbl>,
#   max_pos_lmv <dbl>, max_pos_smv <dbl>, sim_date <date>
# A tibble: 6 x 9
# Groups:   id [3]
  id    strategy gross_pnl net_pnl average_market_total_trading trade_costs
  <chr> <chr>        <dbl>   <dbl>            <dbl>         <dbl>       <dbl>
1 OXY   joint         5389    5377            12406         10661          11
2 OXY   strateg5389    5377            12406         10661          11
3 UAL   joint         4621    4610            12461         10517          11
4 UAL   strateg4621    4610            12461         10517          11
5 PVH   joint         3329    3317            11973         10476          10
6 PVH   strateg3329    3317            11973         10476          10
# … with 2 more variables: financing_costs <dbl>, days_in_portfolio <int>
# A tibble: 0 x 0
    strategy start_smv start_lmv order_gmv   end_smv  end_lmv start_value
1 strategy_1       0.0       0.0 1001199.3 -501006.5 500192.8           0
2      joint       0.0       0.0 1001199.3 -501006.5 500192.8           0
3 strategy_1 -507447.7  510181.3  490646.0 -753446.6 754828.4     1568970
4      joint -507447.7  510181.3  490646.0 -753446.6 754828.4     1568970
5 strategy_1 -759726.1  768143.9  236344.8 -880010.5 884204.3     2013139
6      joint -759726.1  768143.9  236344.8 -880010.5 884204.3     2013139
  end_value start_size  end_size   sim_date
1   1538089      0.000 -9737.629 2020-06-01
2   1538089      0.000 -9737.629 2020-06-01
3   1985717 -10962.781 -9719.187 2020-06-02
4   1985717 -10962.781 -9719.187 2020-06-02
5   2177176  -8034.767 -9810.801 2020-06-03
6   2177176  -8034.767 -9810.801 2020-06-03
    strategy weight_divisor sector_Communication Services
1 strategy_1          1e+06                    0.02025934
2      joint          1e+06                    0.02025934
3 strategy_1          1e+06                    0.02060105
4      joint          1e+06                    0.02060105
5 strategy_1          1e+06                    0.02209832
6      joint          1e+06                    0.02209832
  sector_Consumer Discretionary sector_Consumer Staples sector_Energy
1                   -0.01926901             -0.02034710    0.02062658
2                   -0.01926901             -0.02034710    0.02062658
3                   -0.01981910             -0.01914917    0.02094451
4                   -0.01981910             -0.01914917    0.02094451
5                   -0.01799718             -0.02046579    0.02211464
6                   -0.01799718             -0.02046579    0.02211464
  sector_Financials sector_Health Care sector_Industrials
1        0.02090055        -0.01989795        -0.02034090
2        0.02090055        -0.01989795        -0.02034090
3        0.02204757        -0.02024579        -0.01983724
4        0.02204757        -0.02024579        -0.01983724
5        0.02670573        -0.02068899        -0.01887225
6        0.02670573        -0.02068899        -0.01887225
  sector_Information Technology sector_Materials sector_Real Estate
1                   -0.01992691       0.02008254         0.00027883
2                   -0.01992691       0.02008254         0.00027883
3                   -0.01973070       0.01643217         0.00712367
4                   -0.01973070       0.01643217         0.00712367
5                   -0.01727644       0.01510427         0.00791443
6                   -0.01727644       0.01510427         0.00791443
  sector_Utilities    value        size   sim_date
1       0.02036772 1.567603 -0.01531873 2020-06-01
2       0.02036772 1.567603 -0.01531873 2020-06-01
3       0.02005078 2.014189 -0.01322212 2020-06-02
4       0.02005078 2.014189 -0.01322212 2020-06-02
5       0.02046454 2.249470 -0.01827253 2020-06-03
6       0.02046454 2.249470 -0.01827253 2020-06-03

strand documentation built on Nov. 20, 2020, 1:08 a.m.