|
From: Luigi B. <lui...@gm...> - 2024-01-16 10:31:19
|
Hello,
shallow copy is the C++ default, and I'm afraid we never bothered with
deep copy since most of the time ters structures are passed around by
shared_ptr anyway.
If BASE_TS is your derived class, you can implement a copy constructor.
Otherwise, do you really need a copy to add a spread? As an alternative,
you might pass around your original base term structure and add a constant
spread by means of a class like ZeroSpreadedTermStructure (see
https://github.com/lballabio/QuantLib/blob/master/ql/termstructures/yield/zerospreadedtermstructure.hpp
).
Hope this helps,
Luigi
On Tue, Jan 2, 2024 at 6:55 AM Wei Li <ttl...@gm...> wrote:
> Dear all,
>
> Happy new year to all!
>
> In our c++ project we are caching our term structures / vol surfaces
> calibrated from real time market data. And during the calculation we need
> to assign different spread values for different trades. For example, for
> TRADE_A, the risk free term structure would be BASE_TS with a constant 0.01
> spread, and for TRADE_B, it would be the same BASE_TS with a constant 0.02
> spread. And we are caching BASE_TS since it makes only sense to us (we have
> our derived classes of YieldTermStructure and VolTermStructure to add the
> spreads, in case you were wondering).
>
> But how can I make a deep copy of BASE_TS and use this copy with arbitrary
> spread values to the calculation? I tried the (default) copy
> constructors of the classes and they are apparently shallow-copied. So how
> can I achieve this? It doesn't need to be the deep copy of the bases, it
> can also be the deep copy of the shared_ptr / handle, as long as it does
> the trick.
>
> Thank you very much!
>
> Cheers,
> Wei
> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
|