2. Simple equity basket strategy
Create a simple basket strategy that maintains specific weightings for two different equity instruments.
In this example, you will create a simple basket strategy to hedge investment in Apple stock against market risk. The basket strategy will long Apple and short S&P 500 ETF.
In SigTech's Research environment, create a new notebook and run the following code blocks:
Note that for this tutorial we will need the pandas library:
# Import necessary libraries
import sigtech.framework as sig
import datetime as dtm
import pandas as pd
from uuid import uuid4
# Initalise the environment
As you'll need to use the start and end dates multiple times, store them as variables:
start_date = dtm.date(2016, 1, 1)
end_date = dtm.date(2020, 12, 31)
This time, you will define two
ReinvestmentStrategyinstances—one for the Apple stock and one for the S&P 500 ETF.
apple_rs = sig.ReinvestmentStrategy(
spy_rs = sig.ReinvestmentStrategy(
underlyer='SPY UP EQUITY',
BasketStrategybuilding block is a strategy of strategies—it is a container for managing multiple sub-strategies.
With the following code build a
BasketStrategyto manage the two
ReinvestmentStrategyinstances created above:
my_bs = sig.BasketStrategy(
# Long apple, short SPX, equal weighting
# Rebalance the basket every month
# Set the initial cash to be invested
From a simple plot it looks like this strategy has performed well.
As you will see from running this code, the return of your basket strategy is much worse than just investing in the Apple stock alone:
# Compare the basket strategy's perfomance with that of the Apple stock alone
Running the following two blocks of code will reveal deeper insights about the performance of both your basket strategy and the Apple stock. If you look at market risk instead of return, you can see that your basket strategy has partially hedged against market risk.
Add an additional instrument and indicate whether to long or short it.
Last modified 1yr ago