LibreOffice Module scaddins (master) 1
pricing.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20// option pricing functions add in
21
22// most parts of this files are technical UNO details which are
23// all copied from ../datefunc/datefunc.hxx
24// to avoid having to rename all classes to do with UNO
25// technicalities we use our own namespace
26
27#pragma once
28
29
30#include <vector>
31#include <memory>
32#include <com/sun/star/lang/XServiceName.hpp>
33#include <com/sun/star/lang/XServiceInfo.hpp>
34#include <com/sun/star/sheet/XAddIn.hpp>
35#include <com/sun/star/sheet/XCompatibilityNames.hpp>
36#include <com/sun/star/sheet/addin/XPricingFunctions.hpp>
38#include <unotools/resmgr.hxx>
39
40namespace com::sun::star::lang { class XMultiServiceFactory; }
41
42
43namespace sca::pricing {
44
45enum class ScaCategory
46{
48 Text,
49 Finance,
50 Inf,
51 Math,
52 Tech
53};
54
56{
57 const char* pIntName; // internal name (get***)
58 TranslateId pUINameID; // resource ID to UI name
59 const TranslateId* pDescrID; // resource ID to description, parameter names and ~ description
60 // pCompName was originally meant to be able to load Excel documents that for
61 // some time were stored with localized function names.
62 // This is not relevant to this add-in, so we only supply the
63 // English function name.
64 // see also: GetExcelName() or GetCompNames() or getCompatibilityNames()
65 const char* pCompName;
66 sal_uInt16 nParamCount; // number of named / described parameters
67 ScaCategory eCat; // function category
68 bool bDouble; // name already exist in Calc
69 bool bWithOpt; // first parameter is internal
70};
71
72class ScaFuncData final
73{
74private:
75 OUString aIntName; // internal name (get***)
76 TranslateId pUINameID; // resource ID to UI name
77 const TranslateId* pDescrID; // leads also to parameter descriptions!
78 sal_uInt16 nParamCount; // num of parameters
79 std::vector<OUString> aCompList; // list of all valid names
80 ScaCategory eCat; // function category
81 bool bDouble; // name already exist in Calc
82 bool bWithOpt; // first parameter is internal
83
84public:
85 ScaFuncData(const ScaFuncDataBase& rBaseData);
86
87 const TranslateId& GetUINameID() const { return pUINameID; }
88 const TranslateId* GetDescrID() const { return pDescrID; }
89 ScaCategory GetCategory() const { return eCat; }
90 bool IsDouble() const { return bDouble; }
91
92 sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
93 bool Is( std::u16string_view rCompare ) const
94 { return aIntName == rCompare; }
95
96 const std::vector<OUString>& GetCompNameList() const { return aCompList; }
97};
98
99
100typedef std::vector<ScaFuncData> ScaFuncDataList;
101
103
104// Predicate for use with std::find_if
106{
107 const OUString& m_rId;
108 explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {}
109 bool operator() ( ScaFuncData const & rCandidate ) const { return rCandidate.Is(m_rId); }
110};
111
112} // namespace sca::pricing
113
114
115// AddIn class for pricing functions
116
117class ScaPricingAddIn : public ::cppu::WeakImplHelper<
118 css::sheet::XAddIn,
119 css::sheet::XCompatibilityNames,
120 css::sheet::addin::XPricingFunctions,
121 css::lang::XServiceName,
122 css::lang::XServiceInfo >
123{
124private:
125 css::lang::Locale aFuncLoc;
126 std::unique_ptr<css::lang::Locale[]> pDefLocales;
127 std::locale aResLocale;
128 std::unique_ptr<sca::pricing::ScaFuncDataList> pFuncDataList;
129
130
131 void InitDefLocales();
132 const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
133 void InitData();
134
136 OUString GetFuncDescrStr(const TranslateId* pResId, sal_uInt16 nStrIndex);
137
138public:
140 virtual ~ScaPricingAddIn() override;
141
142 OUString ScaResId(TranslateId aResId);
143
144 // XAddIn
145 virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override;
146 virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override;
147 virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) override;
148 virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
149 virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
150 virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) override;
151 virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) override;
152
153 // XCompatibilityNames
154 virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) override;
155
156 // XLocalizable
157 virtual void SAL_CALL setLocale( const css::lang::Locale& eLocale ) override;
158 virtual css::lang::Locale SAL_CALL getLocale() override;
159
160 // XServiceName
161 virtual OUString SAL_CALL getServiceName() override;
162
163 // XServiceInfo
164 virtual OUString SAL_CALL getImplementationName() override;
165 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
166 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
167
168
169 // methods from own interfaces start here
170
171
172 virtual double SAL_CALL getOptBarrier( double spot, double vol,
173 double r, double rf, double T, double strike,
174 double barrier_low, double barrier_up, double rebate,
175 const OUString& put_call, const OUString& in_out,
176 const OUString& continuous, const css::uno::Any& greek ) override;
177
178 virtual double SAL_CALL getOptTouch( double spot, double vol,
179 double r, double rf, double T,
180 double barrier_low, double barrier_up,
181 const OUString& for_dom, const OUString& in_out,
182 const OUString& barriercont, const css::uno::Any& greekstr ) override;
183
184 virtual double SAL_CALL getOptProbHit( double spot, double vol,
185 double mu, double T,
186 double barrier_low, double barrier_up ) override;
187
188 virtual double SAL_CALL getOptProbInMoney( double spot, double vol,
189 double mu, double T,
190 double barrier_low, double barrier_up,
191 const css::uno::Any& strikeval, const css::uno::Any& put_call ) override;
192
193};
194
195
196/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames(const OUString &aProgrammaticName) override
Definition: pricing.cxx:281
virtual OUString SAL_CALL getImplementationName() override
Definition: pricing.cxx:143
void InitDefLocales()
Definition: pricing.cxx:103
virtual OUString SAL_CALL getProgrammaticFuntionName(const OUString &aDisplayName) override
Definition: pricing.cxx:172
virtual OUString SAL_CALL getProgrammaticCategoryName(const OUString &aProgrammaticName) override
Definition: pricing.cxx:249
virtual OUString SAL_CALL getFunctionDescription(const OUString &aProgrammaticName) override
Definition: pricing.cxx:199
std::unique_ptr< css::lang::Locale[]> pDefLocales
Definition: pricing.hxx:126
virtual OUString SAL_CALL getDisplayFunctionName(const OUString &aProgrammaticName) override
Definition: pricing.cxx:179
virtual double SAL_CALL getOptBarrier(double spot, double vol, double r, double rf, double T, double strike, double barrier_low, double barrier_up, double rebate, const OUString &put_call, const OUString &in_out, const OUString &continuous, const css::uno::Any &greek) override
Definition: pricing.cxx:409
virtual OUString SAL_CALL getDisplayCategoryName(const OUString &aProgrammaticName) override
Definition: pricing.cxx:274
OUString GetFuncDescrStr(const TranslateId *pResId, sal_uInt16 nStrIndex)
Definition: pricing.cxx:130
virtual double SAL_CALL getOptTouch(double spot, double vol, double r, double rf, double T, double barrier_low, double barrier_up, const OUString &for_dom, const OUString &in_out, const OUString &barriercont, const css::uno::Any &greekstr) override
Definition: pricing.cxx:437
std::unique_ptr< sca::pricing::ScaFuncDataList > pFuncDataList
Definition: pricing.hxx:128
virtual OUString SAL_CALL getServiceName() override
Definition: pricing.cxx:136
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: pricing.cxx:148
virtual double SAL_CALL getOptProbHit(double spot, double vol, double mu, double T, double barrier_low, double barrier_up) override
Definition: pricing.cxx:465
virtual OUString SAL_CALL getDisplayArgumentName(const OUString &aProgrammaticName, sal_Int32 nArgument) override
Definition: pricing.cxx:211
const css::lang::Locale & GetLocale(sal_uInt32 nIndex)
Definition: pricing.cxx:114
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: pricing.cxx:153
virtual OUString SAL_CALL getArgumentDescription(const OUString &aProgrammaticName, sal_Int32 nArgument) override
Definition: pricing.cxx:230
css::lang::Locale aFuncLoc
Definition: pricing.hxx:125
virtual css::lang::Locale SAL_CALL getLocale() override
Definition: pricing.cxx:165
OUString ScaResId(TranslateId aResId)
Definition: pricing.cxx:504
virtual ~ScaPricingAddIn() override
Definition: pricing.cxx:95
virtual double SAL_CALL getOptProbInMoney(double spot, double vol, double mu, double T, double barrier_low, double barrier_up, const css::uno::Any &strikeval, const css::uno::Any &put_call) override
Definition: pricing.cxx:482
virtual void SAL_CALL setLocale(const css::lang::Locale &eLocale) override
Definition: pricing.cxx:159
std::locale aResLocale
Definition: pricing.hxx:127
void InitData()
Definition: pricing.cxx:122
std::vector< OUString > aCompList
Definition: pricing.hxx:79
ScaFuncData(const ScaFuncDataBase &rBaseData)
Definition: pricing.cxx:56
ScaCategory GetCategory() const
Definition: pricing.hxx:89
const TranslateId * pDescrID
Definition: pricing.hxx:77
const std::vector< OUString > & GetCompNameList() const
Definition: pricing.hxx:96
bool IsDouble() const
Definition: pricing.hxx:90
const TranslateId * GetDescrID() const
Definition: pricing.hxx:88
bool Is(std::u16string_view rCompare) const
Definition: pricing.hxx:93
const TranslateId & GetUINameID() const
Definition: pricing.hxx:87
sal_uInt16 GetStrIndex(sal_uInt16 nParam) const
Definition: pricing.cxx:68
std::vector< ScaFuncData > ScaFuncDataList
Definition: pricing.hxx:100
void InitScaFuncDataList(ScaFuncDataList &rMap)
Definition: pricing.cxx:75
FindScaFuncData(const OUString &rId)
Definition: pricing.hxx:108
const OUString & m_rId
Definition: pricing.hxx:107
bool operator()(ScaFuncData const &rCandidate) const
Definition: pricing.hxx:109
const TranslateId * pDescrID
Definition: pricing.hxx:59
unsigned char sal_Bool