Model calibration for different dates (2024)

5 views (last 30 days)

Show older comments

Tevor N on 2 Mar 2023

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/1922070-model-calibration-for-different-dates

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/1922070-model-calibration-for-different-dates

Answered: Peter Perkins on 13 Mar 2023

Open in MATLAB Online

Hi guys,

I want to calibrate the Heston model (a financial option pricing model) daily for more than 1000 days and store the optimal parameters for each day in a matrix. I have a large dataframe made with pandas where I have all the necessary information for the price calculation in the columns (i.e. Strike Price, Maturity etc), with also a 'DATE' column. I have +- 1400 option observations per day, so I want to calibrate the Heston model for observations with the same 'DATE' value. My dataframe has over a million observations and I want to calibrate it for options with the same 'DATE' value. I have already loaded this dataframe in MATLAB and daily calibration happens quite fast, but now I want to calibrate my whole dataset with all the dates.

My idea was to make some kind of loop over my different dates such that when the calibration for one particular date is done, MATLAB loops to the next date and starts calibrating it, until daily calibration is done for all my days. I do not really know how I should approach this. With Python I work often with 'groupby, on='DATE'', but I am not very experienced with MATLAB.

The code below works for one date, so I load option data for one date (which are vectors of length 1400) and calibrate it, which works fine. Now I want to load my whole dataset (more than a million observations), group them by date and calibrate it with some sort of loop.

Thanks in advance for the help!

tic

startparameters = x; %[0.054 0.046 -0.53 2.3 0.0825]

options = optimoptions('lsqnonlin', 'Display', 'iter');

xopt = lsqnonlin(@(x) option_function2(distr, S0, K, x, T, CP, sv1, sv2, sv3, rf, q, N, L) - MarketPrice,...

startparameters, ... %start values

... % rho,theta,kappa,sigma

[ -1+eps eps eps eps eps 0 0 0 0 0 0 0 0 ], ... % lower bound for parameter vector

[ 1+eps inf inf inf inf 0 0 0 0 0 0 0 0 ], ... % upper bound for parameter vector

options);

toc

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (2)

Jasvin on 6 Mar 2023

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1922070-model-calibration-for-different-dates#answer_1185970

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1922070-model-calibration-for-different-dates#answer_1185970

You can use the findgroups() and splitapply() functions in tandem to achieve the desired functionality.

Their use case is defined in this documentation page,

https://www.mathworks.com/help/matlab/ref/findgroups.html?s_tid=doc_ta

So first you call findgroups() on your dataset's Date column to obtain the group numbers for each entry and the code that you wrote which works for one date can be converted to a function which you pass in as a function handle to the spltiapply() call.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Peter Perkins on 13 Mar 2023

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1922070-model-calibration-for-different-dates#answer_1192305

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1922070-model-calibration-for-different-dates#answer_1192305

I would think that the best way to do this would be to put your data into a timetable, and use the rowfun function with the date as your grouping variable set to the date. If your timestamps are intraday, you'd need to create that grouping variable using dateshift.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

Computational FinanceFinancial Toolbox

Find more on Financial Toolbox in Help Center and File Exchange

Tags

  • calibration
  • lsqnonlin
  • loop
  • optimization
  • datetime
  • time series
  • finance
  • options

Products

  • Financial Derivatives Toolbox

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Model calibration for different dates (4)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

Model calibration for different dates (2024)
Top Articles
Latest Posts
Article information

Author: Carlyn Walter

Last Updated:

Views: 5752

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Carlyn Walter

Birthday: 1996-01-03

Address: Suite 452 40815 Denyse Extensions, Sengermouth, OR 42374

Phone: +8501809515404

Job: Manufacturing Technician

Hobby: Table tennis, Archery, Vacation, Metal detecting, Yo-yoing, Crocheting, Creative writing

Introduction: My name is Carlyn Walter, I am a lively, glamorous, healthy, clean, powerful, calm, combative person who loves writing and wants to share my knowledge and understanding with you.