backtestStrategy: rebalance function keeps track of past & current open position

조회 수: 4 (최근 30일)
Hi All,
backtestStrategy provides a great workflow for defining a strategy, which includes the rebalancing function.
As part of the EngineData object, WeightsHistory can be used to derive open positions, entry price and open pnl. Nonetheless ... the same computation takes place also within the backtestEngine's runBacktest function, which provides access to a Positions table for each strategy.
Hoping not having to re-invent the wheel, is there a way to pass the Positions table into the rebalancing function, for a given strategy? This would be a good fit for an additional field into the engineData structure. Thx

채택된 답변

Andy
Andy 2024년 4월 27일
best way to do that currently is to use the engineDataList and within the rebalancing function, compute:
positions = engineData.PortfolioValue .* engineData.WeightsHistory;
then look for the relevant ticker's history.

추가 답변 (1개)

Akshat Dalal
Akshat Dalal 2024년 4월 10일
Hi Andy,
I believe you could use the 'UserData' field in the rebalance function to pass the Position's Table as an input argument. When you're dealing with portfolio objects or any custom backtesting framework in MATLAB that supports the 'UserData' field, you can leverage this property to include additional information that the standard properties do not cover, such as a Position's Table or any other strategy-specific data you wish to carry through the rebalancing process.
To learn more about 'backtestStrategy' and the 'rebalance' function, you can refer the following documentation: https://www.mathworks.com/help/finance/backtest-investment-strategies.html
Hope this helps!
  댓글 수: 1
Andy
Andy 2024년 4월 20일
편집: Andy 2024년 4월 20일
Hi @Akshat Dalal, thanks for looking into this. Nonetheless ... can you elaborate a bit more, your suggestion relies on UserData having access to Positions' table, which is not the case.
According to https://uk.mathworks.com/help/finance/backteststrategy.html#engine_data_list_argument the below applies, please, highlight any inauracies in the below:
1) Both UserData and EngineDataList are optional backtestStrategy add-on's:
a) EngineDataList is an optional argument that would change the rebalancing function's signature from:
new_weights = rebalanceFcn(current_weights, etc.)
% to:
new_weights = rebalanceFcn(engineData, etc.)
b) UserData is a struct that can optionally be specified as:
bStrategy.UserData = struct(dummyVar = 0);
% and rebalanceFcn signature changes to:
[new_weights, userData] = rebalanceFcn(engineData, tableTT, userData)
And that's where I take you suggest userData gets augmented with elements from the Positions table. Nonetheless, within the rebalancing function, there is no access and no data related to Positions. EngineData only has:
Weights/History,
PortfolioValue/History,
FeesHistory,
TransactionCostHistory,
CashAsset,
DebtAsset
and nothing else.
So, there is no Positions data available within the rebalanceFcn, Positions property comes later, as part of the backtestEngine object. Obviously, the way EngineDataList was "designed" to keep track of PortfolioValue/History, etc., EngineDataList could also be enhanced to keep track of the Positions table ... hence this post.
How do you suggest the Positions table gets visible within the rebalanceFcn, without "creating" it and keeping track of it yourself (i.e., re-inventing the wheel)?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Portfolio Optimization and Asset Allocation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by