如何对金融工具的价格(干净或肮脏)进行建模?
我需要帮助对以下情况进行建模:
金融工具总是有价格。然而,某些金融工具(而是某些类型)也具有所谓的“干净”价格,这是一个取决于(除其他外)价格的属性,在这种情况下,价格也称为“脏”价格。有一个计算器服务可以计算价格(或脏价格)和干净价格。如何最好地对这种情况进行概念建模?
我考虑过两种选择:
FinancialInstrument 有价格
金融工具 + 价格: 价格
其中 Price 是具有两个派生类的超类型:DirtyPrice 和 CleanPrice。 CleanPrice 取决于 DirtyPrice
清洁价格 + 肮脏: DirtyPrice
计算器服务将计算金融工具的价格:
计算器服务 +compute_price(FinancialInstrument, ...): 价格
FinancialInstrument 是具有两个派生的超类型:PlainFinancialInstrument(仅具有价格属性)和同时具有干净价格和脏价格的 CleanPriceFinancialInstrument。
金融工具 + 价格:双倍 PlainFinancialInstrument CleanPriceFinancialInstrument + 清洁价格:双倍
计算器服务将有两种方法来计算 PlainSecurity 的价格或 CleanPriceSecurities 的干净和脏价格:
计算器服务 + 计算价格(PlainFinancialInstrument,...):双精度 +compute_price(CleanPriceFinancialInstrument, ...): 对<双精度, 双精度>
这两种方案的权衡是什么?还有其他选择吗?
谢谢。
I need help modeling the following situation:
A financial instrument always has a price. However, some financial instruments (of certain types, rather) also have what's called "clean" price which is an attribute that depends (among other things) on the price, in which case price is also called "dirty" price. There is a calculator service that computes both the price (or dirty price) and the clean price. How best to conceptually model that situation?
I have considered two alternatives:
FinancialInstrument has a Price
FinancialInstrument + price: Price
where Price is a supertype with two derived classes: DirtyPrice and CleanPrice. CleanPrice depends on DirtyPrice
CleanPrice + dirty: DirtyPrice
The Calculator service would then compute the price of a FinancialInstrument:
CalculatorService + compute_price(FinancialInstrument, ...): Price
FinancialInstrument is a supertype with two derivations: PlainFinancialInstrument (only has on price attribute) and CleanPriceFinancialInstrument that has both clean and dirty prices.
FinancialInstrument + price: double PlainFinancialInstrument CleanPriceFinancialInstrument + clean_price: double
The Calculator service would then have two methods to compute price for a PlainSecurity or clean and dirty price for CleanPriceSecurities:
CalculatorService + compute_price(PlainFinancialInstrument, ...): double + compute_price(CleanPriceFinancialInstrument, ...): pair<double, double>
What are the trade-offs of both alternatives? Are there other alternatives?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要单独的计算器服务吗?如果不是怎么办:
如果您不缓存价格,您甚至可能不需要本地私有变量。
调用者可以简单地在任何实例(FinancialInstrument 或 CleanFinancialInstrument)上调用 getPrice(),而不必担心它是什么类型。
嗯。
Do you need to have a separate Calculator Service? If not how about:
You may not even need the local private variables if you're not caching the price.
Callers can simply call getPrice() on any instance (FinancialInstrument or CleanFinancialInstrument) without having to worry about which type it is.
hth.
我不清楚您是在问如何对示例中指定的抽象问题进行建模,还是在尝试在现实世界中对金融工具定价的业务概念进行建模。我认为是后者,因为你说得很具体,所以我就评论一下。但在这种情况下,我怀疑您的两种方法中的任何一种是否都足够复杂,无法满足您的任务需求。我已经在该领域工作了几年。
我不确定您在哪个业务领域工作。在我曾经工作的领域(银行业),干净价格和肮脏价格之间的区别是一个简单的商业概念。例如,对于按摊余成本评估的债券,干净价格是不考虑应计费用和递延费用的贴现现金流量的价值,肮脏价格是清洁价格和应计费用/递延费用的总和。在我所知的所有情况下,干净价格是脏价格与金融工具(简称 FI)的某些关键数据(简称 FI)的某些大多数情况下的简单函数之间的差异,并且干净价格和脏价格都只是相关的关键数据对于某些(但不是全部)类型的金融工具。
另一方面,根据 GAAP 和业务领域,您是否需要提供干净价格或肮脏价格或两者都提供的问题可能还取决于金融工具分配到哪个账簿,例如银行账簿/交易账簿。对于交易账簿,您通常只想检索脏价格,干净价格与银行账簿相关。
更糟糕的是,FI 可能会被重新分配,从而导致一组不同的关键人物变得相关。如果这与您的环境相关,您应该确保您的设计考虑到此类更改的后果。
就我个人而言,我会开始采用如下概述的方法:
为金融工具创建一个抽象类/接口
为每种类型的 FI 定义一个子类
创建可能与您范围内任何可能的 FI 相关的所有关键数据的列表 - 在您的示例中:干净价格和脏价格,并且可能一个代表代表差异的关键数字。另外创建一个虚拟价格关键指标条目。
对于每个关键人物,使用与 KF 相关的方法创建一个关键人物界面。例如计算、更新——这取决于您的整体模型。再次举个例子:干净的价格接口、脏的价格接口、增量接口和价格接口。可能有必要定义它们的更新顺序。价格接口的方法集必须是
对于每种类型的 FI,为与该 FI 类型相关的所有关键指标接口创建一个特定的实现(类),当然,还要考虑到重用。严格避免使用 if/else 或 switch 语句,具体取决于这些实现中的关键数字或 FI 类型,如果事实证明这是必要的,则需要额外的类定义。现在,当您实例化代表 FI 的类时,请使用工厂模式来创建关键指标接口的实例。也就是说,您决定创建 FI 实例时使用哪种方法来计算,FI 实例就知道如何计算 FI 的关键指标。工厂模式的一个好处是,您可以额外考虑正在计算的书籍以及其他参数,甚至在运行时(如果需要)。工厂将让价格关键指标接口简单地指向上下文中相关的实例。
你所说的计算器服务,为了计算价格,会调用price key figue接口的方法,但是该接口指向的实例是由FI实例提供的,因为工厂只是映射了price接口干净价格接口或脏价格接口取决于该特定上下文中该特定金融机构的正确性。
如果您按照建议使用 FI 实例中的相关关键指标和关键指标计算接口实现的列表,您甚至可以在重新分配 FI 时在运行时更新/交换此列表,而无需删除/重新创建 FI 实例。
希望我没有让你的问题比实际情况更复杂。
问候,
托马斯
it is not clear to me whether you are asking how to model the abstract problem which is specified by means of your example or whether you are trying to model the business concept of financial instrument pricing in a real world context. I think it is the latter, because you are quite specific, so I'll comment on that. In this case I doubt, though, that any of your two approaches is sophisticated enough to meet the needs of your task. I've been working for several years in that area.
I'm not sure which business area you are working in. In the area I used to work in (banking) the difference between clean and dirty price is a simple business concept. Eg for bonds valuated by amortized costs the clean price is the value of the discounted cash flow not taking into account accruals and deferrals, the dirty price is the sum of the clean price and the accruals/deferrals. In all cases known to me the clean price is the difference between dirty price and some most of the times simple functions of some key figures of the financial instrument (FI for short), and both clean and dirty price are just key figures which are relevant for some (but not all) kind of financial instruments.
On the other hand, depending on the GAAP and business area, the question whether you need to supply the clean or dirty price or both may depend in addition on which book the financial instrument is assigned to, eg banking book/trading book. For the trading book you usually want to only retrieve the dirty price, the clean price is relevant in the banking book.
To make things worse a FI may be, e.g., reassigned, leading to a different set of keyfigures becoming relevant. You should make sure your design takes the consequences of such changes into account if this is relevant in your context.
Personally, I'd start on an approach outlined as follows:
create an abstract class/interface for financial instrument
for each type of FI, define a subclass
create a list of all key figures which may become relevant for any possible FI you have in your scope -- in your example: clean price and dirty price, and probably one for the key figure representing the difference. Create a dummy price key figure entry in addition.
for each of these key figures, create a key figure interface with methods relevant for the KFs. E.g. calculate, update -- this depends on your overall model. Again for your example: a clean price interface, a dirty price interface, a delta interface and a price interface. It may become necessary to define an order in which they have to be updated. The set of methods of the price interface has to be a subset of clean and dirty price interface
for each type of FI, create a specific implementation (class) for all the key figure interfaces relevant for that FI type, taking, of course, reuse into account. Strictly avoid if/else or switch statements depending on the key figure or FI types in these implementations, if this turns out to be necessary, you need additional class definitions. Now when you instantiate a class representing an FI, use a factory pattern to create instances of the key figure interfaces. That is, you decide on FI instance creaton which method to use to calculate, the FI instance then knows how to calculate the key figures of the FI. The nice feature of the factory pattern is that you may, additionally take into account the book you are calculating for as well as other parameters, even at run time if necessary. The factory will let the price key figure interface simply point to instance which is relevant in the context.
what you called the calulator service will then, to calculate a price, call a method of the price key figue interface, but the instance that interface points to is provided by the FI instance, because the factory has simply mapped the price interface to the clean price interface or the dirty price interface depending on what is correct for that specific FI in that specific context.
If you use, as suggested, a list of relevant key figures and key figure calculation interface implementations in the FI instance you can even update/exchange this at runtime if the FI is reassigned, without having to delete/recreate the FI instance.
Hope I did not make your question more complex than it actually is.
Regards,
Thomas