InvestOS provides the following optimization strategies:
This guide will explain how to use either of these classes.
To use the RankLongShort
strategy, you will need:
metric_to_rank
: pd.DataFrame,Optional instantiation options you may need:
n_periods_held
: int = 1,Here's a simple instantiation example:
from investos.portfolio.strategy import RankLongShort
actual_returns_df = pd.DataFrame(...) # Assets as columns, datetimes as index
metric_to_rank_df = pd.DataFrame(...) # Assets as columns, datetimes as index
strategy = RankLongShort(
actual_returns=actual_returns_df,
metric_to_rank=metric_to_rank_df,
leverage=1.5,
ratio_long=100,
ratio_short=50,
)
Once instantiated, you can use the generate_trade_list
method to get trades for a given datetime:
holdings = pd.Series(...) # Indexed by asset
t = dt.datetime.today()
trades = strategy.generate_trade_list(holdings, t)
You can also plug the strategy into BacktestController to run a full backtest!
import investos as inv
backtest_controller = inv.portfolio.BacktestController(
strategy=strategy
)
To use the SPO
strategy, you will need:
Optional instantiation options you may need:
cash_column_name
="cash"Here's a simple instantiation example:
actual_returns_df = pd.DataFrame(...) # Assets as columns, datetimes as index
forecast_returns_df = pd.DataFrame(...) # Assets as columns, datetimes as index
strategy = SPO(
actual_returns=actual_returns_df,
forecast_returns=forecast_returns_df
)
Like RankLongShort, or any other InvestOS investment strategy, once instantiated, you can use the generate_trade_list
method to get trades for a given datetime:
holdings = pd.Series(...)
t = dt.datetime.today()
trades = strategy.generate_trade_list(holdings, t)
and plug the strategy into BacktestController to run a full backtest!
import investos as inv
backtest_controller = inv.portfolio.BacktestController(
strategy=strategy
)
For SPO specifically, if the optimization problem is unbounded, infeasible, or if there's an error with the solver, the generate_trade_list
method will return a zero trade for all holdings for the given t
datetime.
Want to explore creating your own custom investment strategy? Check out Custom Investment Strategies.
Want to learn more about using cost models? Check out Cost Models.