1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// option pricing functions add in
// most parts of this files are technical UNO details which are
// all copied from ../datefunc/datefunc.hxx
// to avoid having to rename all classes to do with UNO
// technicalities we use our own namespace
#ifndef INCLUDED_SCADDINS_SOURCE_PRICING_PRICING_HXX
#define INCLUDED_SCADDINS_SOURCE_PRICING_PRICING_HXX
#include <string.h>
#include <vector>
#include <com/sun/star/lang/XServiceName.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/sheet/XAddIn.hpp>
#include <com/sun/star/sheet/XCompatibilityNames.hpp>
#include <com/sun/star/sheet/addin/XPricingFunctions.hpp>
#include <cppuhelper/implbase.hxx>
#include <tools/resid.hxx>
#include <tools/rc.hxx>
#include <tools/resary.hxx>
#define RETURN_FINITE(d) if( ::rtl::math::isFinite( d ) ) return d; else throw css::lang::IllegalArgumentException()
namespace sca {
namespace pricing {
class ScaResId : public ResId
{
public:
ScaResId( sal_uInt16 nResId, ResMgr& rResMgr );
};
class ScaResStringLoader
{
private:
OUString aStr;
public:
ScaResStringLoader(sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr)
{
ResStringArray aStrArray(ScaResId(nResId, rResMgr));
aStr = aStrArray.GetString(aStrArray.FindIndex(nStrId));
}
const OUString& GetString() const { return aStr; }
};
class ScaResStringArrLoader : public Resource
{
private:
ResStringArray aStrArray;
public:
inline ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr );
inline const ResStringArray& GetStringArray() const { return aStrArray; }
};
inline ScaResStringArrLoader::ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr ) :
Resource( ScaResId( nResId, rResMgr ) ),
aStrArray( ScaResId( nArrayId, rResMgr ) )
{
FreeResource();
}
class ScaResPublisher : public Resource
{
public:
explicit ScaResPublisher( const ScaResId& rResId ) : Resource( rResId ) {}
using Resource::IsAvailableRes;
using Resource::FreeResource;
};
class ScaFuncRes : public Resource
{
public:
ScaFuncRes(ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet);
};
enum class ScaCategory
{
DateTime,
Text,
Finance,
Inf,
Math,
Tech
};
struct ScaFuncDataBase
{
const sal_Char* pIntName; // internal name (get***)
sal_uInt16 nUINameID; // resource ID to UI name
sal_uInt16 nDescrID; // resource ID to description, parameter names and ~ description
sal_uInt16 nCompListID; // resource ID to list of valid names
sal_uInt16 nParamCount; // number of named / described parameters
ScaCategory eCat; // function category
bool bDouble; // name already exist in Calc
bool bWithOpt; // first parameter is internal
};
class ScaFuncData final
{
private:
OUString aIntName; // internal name (get***)
sal_uInt16 nUINameID; // resource ID to UI name
sal_uInt16 nDescrID; // leads also to parameter descriptions!
sal_uInt16 nParamCount; // num of parameters
std::vector<OUString> aCompList; // list of all valid names
ScaCategory eCat; // function category
bool bDouble; // name already exist in Calc
bool bWithOpt; // first parameter is internal
public:
ScaFuncData( const ScaFuncDataBase& rBaseData, ResMgr& rRscMgr );
~ScaFuncData();
inline sal_uInt16 GetUINameID() const { return nUINameID; }
inline sal_uInt16 GetDescrID() const { return nDescrID; }
inline ScaCategory GetCategory() const { return eCat; }
inline bool IsDouble() const { return bDouble; }
sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
inline bool Is( const OUString& rCompare ) const
{ return aIntName == rCompare; }
inline const std::vector<OUString>& GetCompNameList() const { return aCompList; }
};
typedef std::vector<ScaFuncData> ScaFuncDataList;
void InitScaFuncDataList ( ScaFuncDataList& rMap, ResMgr& rResMgr );
// Predicate for use with std::find_if
struct FindScaFuncData
{
const OUString& m_rId;
explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {}
bool operator() ( ScaFuncData& rCandidate ) const { return rCandidate.Is(m_rId); }
};
} // namespace pricing
} // namespace sca
css::uno::Reference< css::uno::XInterface > SAL_CALL PricingFunctionAddIn_CreateInstance(
const css::uno::Reference< css::lang::XMultiServiceFactory >& );
// AddIn class for pricing functions
class ScaPricingAddIn : public ::cppu::WeakImplHelper<
css::sheet::XAddIn,
css::sheet::XCompatibilityNames,
css::sheet::addin::XPricingFunctions,
css::lang::XServiceName,
css::lang::XServiceInfo >
{
private:
css::lang::Locale aFuncLoc;
css::lang::Locale* pDefLocales;
ResMgr* pResMgr;
sca::pricing::ScaFuncDataList* pFuncDataList;
void InitDefLocales();
const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
/// @throws css::uno::RuntimeException
ResMgr& GetResMgr();
void InitData();
/// @throws css::uno::RuntimeException
OUString GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex );
public:
ScaPricingAddIn();
virtual ~ScaPricingAddIn() override;
static OUString getImplementationName_Static();
static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
// XAddIn
virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override;
virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override;
virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) override;
virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) override;
virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) override;
// XCompatibilityNames
virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) override;
// XLocalizable
virtual void SAL_CALL setLocale( const css::lang::Locale& eLocale ) override;
virtual css::lang::Locale SAL_CALL getLocale() override;
// XServiceName
virtual OUString SAL_CALL getServiceName() override;
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() override;
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
// methods from own interfaces start here
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;
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;
virtual double SAL_CALL getOptProbHit( double spot, double vol,
double mu, double T,
double barrier_low, double barrier_up ) override;
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;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|