-
Notifications
You must be signed in to change notification settings - Fork 0
/
SFSDK.cs
2282 lines (1943 loc) · 164 KB
/
SFSDK.cs
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region License
// <copyright file="SFSDK.cs" company="Spider Financial Corp">
// (c) 2007-2014 Spider Financial Corp.
// All rights reserved.
// </copyright>
//
//
#endregion
#region Using Directives
using System;
using System.Text;
using System.Runtime.InteropServices;
#endregion
namespace NumXLAPI
{
/// <summary>
/// Supported statistical test outputs
/// </summary>
public enum TEST_RETURN
{
TEST_PVALUE=1,
TEST_SCORE=2,
TEST_CRITICALVALUE=3
}
/// <summary>
/// multi-colinearity test method
/// </summary>
public enum COLNRTY_TEST_TYPE
{
COLNRTY_CN = 1,
COLNRTY_VIF = 2,
COLNRTY_DET = 3,
COLNRTY_EIGEN = 4
}
/// <summary>
/// NDK_ARMA_GOF
/// </summary>
public enum GOODNESS_OF_FIT_FUNC
{
GOF_LLF=1,
GOF_AIC=2,
GOF_BIC=3,
GOF_HQC=4,
GOF_RSQ=5,
GOF_ARSQ=6
};
/// <summary>
/// NDK_ARMA_FIT
/// </summary>
public enum FIT_RETVAL_FUNC
{
FIT_MEAN=1,
FIT_STDEV=2,
FIT_RESID=3,
FIT_STD_RESID=4
};
/// <summary>
/// NDK_ARMA_RESID
/// </summary>
public enum RESID_RETVAL_FUNC
{
RESIDS_STD=1,
RESIDS_RAW=2
}
/// <summary>
/// NDK_ARMA_PARAM
/// </summary>
public enum MODEL_RETVAL_FUNC
{
PARAM_GUESS=1,
PARAM_CALIBRATE=2,
PARAM_ERROR=3
};
/// <summary>
/// NDK_ARMA_FORE
/// </summary>
public enum FORECAST_RETVAL_FUNC
{
FORECAST_MEAN=1,
FORECAST_STDEV=2,
FORECAST_TS_STDEV=3,
FORECAST_LL=4,
FORECAST_UL=5
};
/// <summary>
/// NDK_NORMALTEST
/// </summary>
public enum NORMALTEST_METHOD
{
NORMALTEST_JB=1,
NORMALTEST_WS=2,
NORMALTEST_CHISQ=3
};
/// <summary>
/// NDK_XCFTEST and NDK_XCF
/// </summary>
public enum CORRELATION_METHOD
{
XCF_PEARSON=1,
XCF_SPEARMAN=2,
XCF_KENDALL=3
}
/// <summary>
/// NDK_GLM_GOF
/// </summary>
public enum GLM_LINK_FUNC
{
GLM_LVK_IDENTITY=1,
GLM_LVK_LOG=2,
GLM_LVK_LOGIT=3,
GLM_LVK_PROBIT=4,
GLM_LVK_CLOGLOG=5
};
/// <summary>
/// NDK_GARCH_PARAM
/// </summary>
public enum INNOVATION_TYPE
{
INNOVATION_GAUSSIAN=1,
INNOVATION_TDIST=2,
INNOVATION_GED=3
};
/// <summary>
/// NDK_TREND
/// </summary>
public enum TREND_TYPE
{
TREND_LINEAR=1,
TREND_POLYNOMIAL=2,
TREND_EXPONENTIAL=3,
TREND_LOGARITHMIC=4,
TREND_POWER=5
}
/// <summary>
/// Warpper class for C-API in SFSDK.dll
/// SFSDK provides access to NumXL SDK time series and statistics functionality.
/// </summary>
public class SFSDK
{
const string DLLName = "SFSDK.dll";
/// <summary> Initializes the SFSDK dll and verifies the license key for the current host</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#100", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int NDK_Init(string szAppName, /// <param name="szAppName">User-defined application name</param>
string szKey, /// <param name="szKey">NumXL License key</param>
string szActCode,
string szLogDir);
/// <summary>
/// Wrap the NDK_INIT API function with a CLS compliant function
/// </summary>
/// <param name="szAppName">User-defined application name</param>
/// <param name="szKey">NumXL License key</param>
/// <param name="szActCode">Activation code</param>
/// <param name="szLogDir">Temporary files and Logging directory</param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
public static NDK_RETCODE Init(string szAppName, string szKey, string szActCode, string szLogDir)
{
int nRet = NDK_Init(szAppName, szKey, szActCode, szLogDir);
return (NDK_RETCODE)nRet;
}
/// <summary> shutdown the SFSDK module and release allocated resources.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#105", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int NDK_Shutdown();
/// <summary>
/// Wrap the NDK_Shutdown API function with a CLS compliant function
/// </summary>
/// <returns></returns>
public static NDK_RETCODE Shutdown()
{
int nRet = NDK_Shutdown();
return (NDK_RETCODE)nRet;
}
/// <summary> Query NumXL SDK for environment information.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#110", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_INFO(int nRetType, StringBuilder szMsg, int nSize);
/// <summary> Returns an array of cells for the backward shifted, backshifted or lagged time series.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
/// <seealso cref="NDK_DIFF"/>
[DllImport(DLLName, EntryPoint = "#1000", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_LAG( [MarshalAs(UnmanagedType.LPArray)] double[] data, UIntPtr nLen, UIntPtr lag);
/// <summary> Returns an array of cells for the differenced time series (i.e. (1-L^S)^D).</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
/// <seealso cref="NDK_LAG"/>
/// <seealso cref="NDK_INTEG"/>
[DllImport(DLLName, EntryPoint = "#1005", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_DIFF([MarshalAs(UnmanagedType.LPArray)] double[] data, UIntPtr nSize, UIntPtr nLag, UIntPtr nDifference);
/// <summary> Returns an array of cells for the integrated time series (inverse operator of NDK_DIFF). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
/// <seealso cref="NDK_DIFF"/>
/// <seealso cref="NDK_LAG"/>
[DllImport(DLLName, EntryPoint = "#1010", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_INTEG([MarshalAs(UnmanagedType.LPArray)] double[] data, UIntPtr nSize, UIntPtr nLag, UIntPtr nDifference, [MarshalAs(UnmanagedType.LPArray)] double[] pX0, UIntPtr nX0Len);
/// <summary> Returns an array of cells of a time series after removing all missing values.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#1010", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_RMNA([MarshalAs(UnmanagedType.LPArray)] double[] data, out UIntPtr nSize);
/// <summary> Returns the time-reversed order time series (i.e. the first observation is swapped with the last observation, etc.): both missing and non-missing values.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#1024", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_REVERSE([MarshalAs(UnmanagedType.LPArray)] double[] data, UIntPtr nSize);
/// <summary> Returns an array of cells for the scaled time series.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#1023", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SCALE([MarshalAs(UnmanagedType.LPArray)] double[] data, UIntPtr nSize, double factor);
/// <summary> Returns an array of the difference between two time series.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#1022", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SUB([MarshalAs(UnmanagedType.LPArray)] double[] data, UIntPtr nSize1, [MarshalAs(UnmanagedType.LPArray)] double[] data2, UIntPtr nSize2);
/// <summary>Returns an array of cells for the sum of two time series..</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#1021", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_ADD([MarshalAs(UnmanagedType.LPArray)] double[] data1, UIntPtr nSize1, [MarshalAs(UnmanagedType.LPArray)] double[] data2, UIntPtr nSize2);
/// <summary> Time series convolution orderator.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#1032", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_CONVOLUTION([MarshalAs(UnmanagedType.LPArray)] double[] pData1, UIntPtr nSize1, [MarshalAs(UnmanagedType.LPArray)] double[] pData2, UIntPtr nSize2, out double pResult, out UIntPtr nWindowSize);
/// <summary> Inverse discrete fourier transform.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#1031", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_IDFT([MarshalAs(UnmanagedType.LPArray)] double[] amp,[MarshalAs(UnmanagedType.LPArray)] double[] phase, UIntPtr nSize, [MarshalAs(UnmanagedType.LPArray)] double[] data, UIntPtr nWindowSize);
/// <summary> discrete fourier transform.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#1030", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_DFT([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short component, short argRetType, out double retVal);
/// <summary> Computes the complementary log-log transformation, including its inverse.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#4005", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_CLOGLOG([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argRetType);
/// <summary> Computes the probit transformation, including its inverse.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#4004", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_PROBIT([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argRetType);
/// <summary> Computes the logit transformation, including its inverse.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#4003", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_LOGIT([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argRetType);
/// <summary> Computes the Box-Cox transformation, including its inverse.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#4002", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_BOXCOX([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, out double lambda, out double fAlpha, int argRetType, out double retVal);
/// <summary> Detrends a time series using a regression of y against a polynomial time trend of order p. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#4010", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_DETREND([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short polyOrder);
/// <summary> Returns an array of the deseasonalized time series, assuming a linear model. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#4017", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_RMSEASONAL([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, UIntPtr period);
/// <summary> Returns an array of a time series after substituting all missing values with the mean/median. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#4000", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_INTERP_NAN([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short nMethod, double plug);
/// <summary> Imput missing values using brownian bridge </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#4015", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_INTERP_BROWN([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize);
/// <summary> Examine whether the given array has one or more missing values. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#4018", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_HASNA([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short intermediate);
/// <summary> Calculates the sample autocorrelation function (ACF) of a stationary time series </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#200", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_ACF([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, int nLag, out double retVal);
/// <summary> Calculates the standard error in the sample autocorrelation function. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#205", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_ACF_ERROR([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, int nLag, out double retVal);
/// <summary> Calculates the confidence interval limits (upper/lower) for the autocorrelation function. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#210", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_ACFCI([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, int nLag, double alpha, out double retUpper, out double retLower);
/// <summary> Calculates the sample partial autocorrelation function (PACF). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#215", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_PACF([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, int nLag, out double retVal);
/// <summary> Calculates the standard error of the sample partial autocorrelation function (PACF). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#220", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_PACF_ERROR([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, int nLag, out double retVal);
/// <summary> Calculates the confidence interval limits (upper/lower) for the partial-autocorrelation function. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#225", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_PACFCI([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, int nLag, double alpha, out double retUpper, out double retLower);
/// <summary> Calculates the estimated value of the exponential-weighted volatility (EWV). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#1015", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_EWMA([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, double lambda, UIntPtr nStep, out double retVal);
/// <summary> Computes the correlation factor using the exponential-weighted correlation function. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#1020", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_EWXCF([MarshalAs(UnmanagedType.LPArray)] double[] pData1, [MarshalAs(UnmanagedType.LPArray)] double[] pData2, UIntPtr nSize, double lambda, UIntPtr nStep, out double retVal);
/// <summary> Interpolate function </summary>
[DllImport(DLLName, EntryPoint = "#3000", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_INTERPOLATE([MarshalAs(UnmanagedType.LPArray)] double[] pXData, UIntPtr nXSize, [MarshalAs(UnmanagedType.LPArray)] double[] pYData, UIntPtr nYSize, [MarshalAs(UnmanagedType.LPArray)] double[] pXTargets, UIntPtr nXTargetSize, short nMethod, bool allowExtrp,[MarshalAs(UnmanagedType.LPArray)] double[] pYTargets, UIntPtr nYTargetSize);
// Statistical testing
/// <summary> Calculates the p-value of the statistical test for the population autocorrelation function. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#300", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_ACFTEST([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, int nLag, double targetVal, double alpha, UInt16 method, UInt16 retType, out double retVal);
/// <summary> Returns the p-value of the normality test (i.e. whether a data set is well-modeled by a normal distribution). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#301", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_NORMALTEST([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, double alpha, UInt16 method, UInt16 retType, out double retVal);
/// <summary> Computes the p-value of the statistical portmanteau test (i.e. whether any of a group of autocorrelations of a time series are different from zero). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#302", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_WNTEST([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, int nLag, double alpha, UInt16 argMethod, UInt16 retType, out double retVal);
/// <summary> Calculates the p-value of the ARCH effect test (i.e. the white-noise test for the squared time series). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#303", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_ARCHTEST([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, int nLag, double alpha, UInt16 argMethod, UInt16 retType, out double retVal);
/// <summary> Calculates the p-value of the statistical test for the population mean. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#304", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_MEANTEST([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, double target, double alpha, UInt16 argMethod, UInt16 retType, out double retVal);
/// <summary> Calculates the p-value of the statistical test for the population standard deviation. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#305", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_STDEVTEST([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, double target, double alpha, UInt16 argMethod, UInt16 retType, out double retVal);
/// <summary> Calculates the p-value of the statistical test for the population skew (i.e. 3rd moment) </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#306", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SKEWTEST([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, double alpha, UInt16 argMethod, UInt16 retType, out double retVal);
/// <summary> Calculates the p-value of the statistical test for the population excess kurtosis (4th moment). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#307", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_XKURTTEST([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, double alpha, UInt16 argMethod, UInt16 retType, out double retVal);
/// <summary> Calculates the test stats, p-value or critical value of the correlation test. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#308", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_XCFTEST( [MarshalAs(UnmanagedType.LPArray)] double[] pData1, [MarshalAs(UnmanagedType.LPArray)] double[] pData2,
UIntPtr nSize, int nLag, double target, double alpha, UInt16 method, UInt16 retTYpe, out double retVal);
/// <summary> Returns the p-value of the Augmented Dickey-Fuller (ADF) test, which tests for a unit root in the time series sample. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#309", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_ADFTEST([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, UInt16 maxOrder, UInt16 option, bool testDown, double alpha, UInt16 argMethod, UInt16 retType, out double retVal);
/// <summary> KPSS (stationary) test function </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#310", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_KPSSTEST([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short maxOrder, short option, bool testDown, short argMethod, short retType, double alpha, out double retVal);
/// <summary> Returns the Johansen (cointegration) test statistics for two or more time series. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
// TODO: We need to check this function declaration
[DllImport(DLLName, EntryPoint = "#311", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int NDK_JOHANSENTEST(IntPtr pData,
UIntPtr nSize,
UIntPtr nVars,
UIntPtr maxOrder,
short nPolyOrder,
bool tracetest,
UInt16 nNoRelations,
double alpha,
ref double retStat,
ref double retCV);
/// <summary>
/// Returns the Johansen (cointegration) test statistics for two or more time series.
/// </summary>
/// <param name="pData"></param>
/// <param name="maxOrder"></param>
/// <param name="nPolyOrder"></param>
/// <param name="tracetest"></param>
/// <param name="nNoRelations"></param>
/// <param name="alpha"> significiance level</param>
/// <param name="retStat"> test statistics (aka Z-score)</param>
/// <param name="retCV"> test critical value. </param>
/// <returns></returns>
public static NDK_RETCODE JohansenTest(double[,] pData,
UIntPtr maxOrder,
short nPolyOrder,
bool tracetest,
UInt16 nNoRelations,
double alpha,
ref double retStat,
ref double retCV)
{
NDK_RETCODE retVal = NDK_RETCODE.NDK_FAILED;
// Ready to call Johansen test
retStat = double.NaN;
retCV = double.NaN;
int iRow = pData.GetLength(0); // number of rows
int iCol = pData.GetLength(1); // number of columns
IntPtr[] p2dArray = new IntPtr[iRow];
for (int i = 0; i < iRow; i++)
{
double[] pdArray = new double[iCol];
// Fill row (array)
for (int j = 0; j < iCol; j++)
{
pdArray[j] = pData[i, j];
}
p2dArray[i] = Marshal.AllocCoTaskMem(Marshal.SizeOf(pdArray[0]) * iCol);
Marshal.Copy(pdArray, 0, p2dArray[i], iCol);
}
IntPtr vars = (IntPtr)0;
IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(vars) * iRow);
Marshal.Copy(p2dArray, 0, buffer, iRow);
retVal = (NDK_RETCODE)SFSDK.NDK_JOHANSENTEST(buffer,
(UIntPtr)iRow, (UIntPtr)iCol, maxOrder,
nPolyOrder, tracetest, nNoRelations, alpha, ref retStat, ref retCV);
// Free the memory allocated
for (int i = 0; i < iRow; i++)
{
// Free individual rows
Marshal.FreeCoTaskMem(p2dArray[i]);
}
// Free array holding row addresses
Marshal.FreeCoTaskMem(buffer);
return retVal;
}
/// <summary> Returns the Johansen (cointegration) test statistics for two or more time series. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
// TODO: We need to check this function declaration
[DllImport(DLLName, EntryPoint = "#312", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_COLNRTY_TEST(ref UIntPtr pData, UIntPtr nSize, UIntPtr nVars,
Byte[] mask, UIntPtr nMaskLen,
COLNRTY_TEST_TYPE nMethod, short nColIndex, ref double retVal);
/// <summary> Returns the p-value of the regression stability test (i.e. whether the coefficients in two linear regressions on different data sets are equal). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#313", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_CHOWTEST(ref UIntPtr XX1,
UIntPtr M,
double[] Y1,
UIntPtr N1,
ref UIntPtr XX2,
double[] Y2,
UIntPtr N2,
Byte[] mask, UIntPtr nMaskLen,
double intercept,
TEST_RETURN retType,
ref double retVal);
// Statistical distribution
/// <summary> Calculates the excess kurtosis of the generalized error distribution (GED) </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#500", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_GED_XKURT(double df, ref double retVal);
/// <summary> Calculates the excess kurtosis of the student's t-distribution. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#501", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_TDIST_XKURT(double df, ref double retVal);
/// <summary> Calculates the empirical distribution function (or empirical cdf) of the sample data. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#502", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_EDF([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, double targetVal, short retType, ref double retVal);
/// <summary> Returns the number of histogram bins using a given method. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#503", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_HIST_BINS([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMethod, ref UIntPtr retVal);
/// <summary> Returns the upper/lower limit or center value of the k-th histogram bin.</summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#504", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_HIST_BIN_LIMIT([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, UIntPtr nBins, UIntPtr index, short argRetTYpe, ref double retVal);
/// <summary> Calculates the histogram or cumulative histogram function for a given bin. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#505", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_HISTOGRAM([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, UIntPtr nBins, UIntPtr index, short argRetTYpe, ref double retVal);
/// <summary> Returns the upper/lower limit or center value of the k-th histogram bin. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#506", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_KERNEL_DENSITY_ESTIMATE([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, double targetVal, double bandwidth, short argKernelFunc, ref double retVal);
/// <summary> Returns a sequence of random numbers drawn from Normal distribution. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#520", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_GAUSS_RNG(double mean, double stdev, UIntPtr seed, [MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize);
/// <summary> Returns the upper & lower limit of the confidence interval for the Gaussian distribution. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#507", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_GAUSS_FORECI(double mean, double stdev, double alpha, short upper, ref double retVal);
/// <summary> Returns the upper & lower limit of the confidence interval for the student\'s t-distribution. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#508", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_TSTUDENT_FORECI(double mean, double stdev, double df, double alpha, short upper, ref double retVal);
/// <summary> Returns the upper & lower limit of the confidence interval for the Generalized Error Distribution (GED) distribution. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#509", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_GED_FORECI(double mean, double stdev, double df, double alpha, short upper, ref double retVal);
// General Statistics
/// <summary> Compute the kernel density distribution function </summary>
[DllImport(DLLName, EntryPoint = "#403", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_XKURT([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMenthod, ref double retVal);
/// <summary> Compute sample skewness function </summary>
[DllImport(DLLName, EntryPoint = "#404", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SKEW([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMenthod, ref double retVal);
/// <summary> Compute sample skewness function </summary>
[DllImport(DLLName, EntryPoint = "#405", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_AVERAGE([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMenthod, ref double retVal);
/// <summary> Compute sample skewness function </summary>
[DllImport(DLLName, EntryPoint = "#406", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_VARIANCE([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMenthod, ref double retVal);
/// <summary> Compute sample skewness function </summary>
[DllImport(DLLName, EntryPoint = "#407", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_MIN([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMenthod, ref double retVal);
/// <summary> Compute sample skewness function </summary>
[DllImport(DLLName, EntryPoint = "#408", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_MAX([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMenthod, ref double retVal);
/// <summary> Compute sample skewness function </summary>
[DllImport(DLLName, EntryPoint = "#410", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_QUANTILE([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, double argPct, ref double retVal);
/// <summary> Compute sample skewness function </summary>
[DllImport(DLLName, EntryPoint = "#411", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_IQR([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, ref double retVal);
/// <summary> Returns the sorted sample data </summary>
/// <param name="pData">is the input data sample (a one dimensional array)</param>
/// <param name="nSize">is the number of observations in pData</param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#422", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SORT_ASC([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize);
/// <summary> Calculates the Hurst exponent (a measure of persistence or long memory) for time series. </summary>
/// <param name="pData">is the input data sample (a one dimensional array)</param>
/// <param name="nSize">is the number of observations in pData</param>
/// <param name="alpha">is the statistical significance level (1%, 5%, 10%). If missing, a default of 5% is assumed.</param>
/// <param name="retType">is a number that determines the type of return value:
/// <list type="number">
/// <item>1 = Empirical Hurst exponent (R/S method)</item>
/// <item>2 = Anis-Lloyd/Peters corrected Hurst exponent</item>
/// <item>3 = Theoretical Hurst exponent</item>
/// <item>4 = Upper limit of the confidence interval</item>
/// <item>5 = Lower limit of the confidence interval</item>
/// </list>
/// </param>
/// <param name="retVal">is the calculated value of this function.</param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#409", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_HURST_EXPONENT([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, double alpha, short retType, ref double retVal);
/// <summary> Returns the sample Gini coefficient, a measure of statistical dispersion. </summary>
/// <param name="pData">is the input data sample (a one dimensional array)</param>
/// <param name="nSize">is the number of observations in pData</param>
/// <param name="retVal">is the calculated value of this function.</param>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
/// <remarks>
/// <list type="bullet">
/// <item><description>A low Gini coefficient indicates a more equal distribution, with 0 corresponding to complete equality. Higher Gini coefficients indicate more unequal distributions, with 1 corresponding to complete inequality.</description></item>
/// <item><description>The input data series may include missing values (NaN), but they will not be included in the calculations.</description></item>
/// <item><description>The values in the input data series must be non-negative.</description></item>
/// </list>
/// </remarks>
[DllImport(DLLName, EntryPoint = "#400", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_GINI([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, ref double retVal);
/// <summary> Calculates the cross-correlation function between two time series </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#401", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_XCF([MarshalAs(UnmanagedType.LPArray)] double[] pData1, [MarshalAs(UnmanagedType.LPArray)] double[] pData2, UIntPtr nSize, UIntPtr nLag, short nMethod, short retType, ref double retVal);
/// <summary> Returns the sample root mean square (RMS). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#412", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_RMS([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMenthod, ref double retVal);
/// <summary> Returns the mean difference of the input data series. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#413", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_MD([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMenthod, ref double retVal);
/// <summary> Returns the sample relative mean difference. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#414", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_RMD([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMenthod, ref double retVal);
/// <summary> Returns the sample median of absolute deviation (MAD) </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#415", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_MAD([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, short argMenthod, ref double retVal);
/// <summary> Returns the long-run variance using a Bartlett kernel with window size k. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#416", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_LRVAR([MarshalAs(UnmanagedType.LPArray)] double[] pData, UIntPtr nSize, UIntPtr argWindow, ref double retVal);
/// <summary> Calculates the sum of absolute errors (SAE) between the forecast and the eventual outcomes. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#417", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SAD([MarshalAs(UnmanagedType.LPArray)] double[] pData1, [MarshalAs(UnmanagedType.LPArray)] double[] pData2, UIntPtr nSize, ref double retVal);
/// <summary> Calculates the mean absolute error function for the forecast and the eventual outcomes. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#418", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_MAE([MarshalAs(UnmanagedType.LPArray)] double[] pData1, [MarshalAs(UnmanagedType.LPArray)] double[] pData2, UIntPtr nSize, ref double retVal);
/// <summary> Calculates the mean absolute percentage error (deviation) function for the forecast and the eventual outcomes. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#419", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_MAPE([MarshalAs(UnmanagedType.LPArray)] double[] pData1, [MarshalAs(UnmanagedType.LPArray)] double[] pData2, UIntPtr nSize, short retType, ref double retVal);
/// <summary> Calculates the root mean squared error (aka root mean squared deviation (RMSD)) function. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#420", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_RMSE([MarshalAs(UnmanagedType.LPArray)] double[] pData1, [MarshalAs(UnmanagedType.LPArray)] double[] pData2, UIntPtr nSize, short retType, ref double retVal);
/// <summary> Calculates the sum of the squared errors of the prediction function. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#421", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SSE([MarshalAs(UnmanagedType.LPArray)] double[] pData1, [MarshalAs(UnmanagedType.LPArray)] double[] pData2, UIntPtr nSize, ref double retVal);
// Smoothing API functions calls
/// <summary>
/// Returns the weighted moving (rolling/running) average using the previous m data points.
/// </summary>
///
/// <seealso cref="NDK_SESMTH"/>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#2000", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_WMA([MarshalAs(UnmanagedType.LPArray)] double[] pData, int nSize, bool bAscending, [MarshalAs(UnmanagedType.LPArray)] double[] pWeights, int nwSize, int nHorizon, ref double retVal);
/// <summary> Returns the (Brown's) simple exponential (EMA) smoothing estimate of the value of X at time t+m (based on the raw data up to time t). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#2005", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SESMTH([MarshalAs(UnmanagedType.LPArray)] double[] pData, int nSize, bool bAscending, ref double alpha, int nHorizon, bool bOptimize, ref double retVal);
/// <summary> Returns the (Holt-Winter's) double exponential smoothing estimate of the value of X at time T+m. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#2010", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_DESMTH([MarshalAs(UnmanagedType.LPArray)] double[] pData, int nSize, bool bAscending, ref double alpha, ref double beta, int xlHorizon, bool bOptimize, ref double retVal);
/// <summary> Returns the (Brown's) linear exponential smoothing estimate of the value of X at time T+m (based on the raw data up to time t). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#2015", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_LESMTH([MarshalAs(UnmanagedType.LPArray)] double[] pData, int nSize, bool bAscending, ref double alpha, int xlHorizon, bool bOptimize, ref double retVal);
/// <summary> Returns the (Winters's) triple exponential smoothing estimate of the value of X at time T+m. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#2020", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_TESMTH([MarshalAs(UnmanagedType.LPArray)] double[] pData, int nSize, bool bAscending, ref double alpha, ref double beta, ref double gamma, int seasonLength, int nHorizon, bool bOptimize, ref double retVal);
/// <summary> Returns values along a trend curve (e.g. linear, quadratic, exponential, etc.) at time T+m. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#2021", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_TREND([MarshalAs(UnmanagedType.LPArray)] double[] pData, int nSize, bool bAscending, short nTrendType, short argPolyOrder, bool AllowIntercep, double InterceptVal, int nHorizon, short argRetType, double argAlpha, ref double retVal);
// SLR
/// <summary> Calculates the OLS regression coefficients values </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#720", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SLR_PARAM( [MarshalAs(UnmanagedType.LPArray)] double[] pXData, UIntPtr nXSize,
[MarshalAs(UnmanagedType.LPArray)] double[] pYData, UIntPtr nYSize,
double intercept,
double alpha,
short nRetType,
short ParamIndex,
ref double retVal);
/// <summary> Calculates the forecast mean, error and confidence interval. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#721", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SLR_FORE([MarshalAs(UnmanagedType.LPArray)] double[] pXData, UIntPtr nXSize,
[MarshalAs(UnmanagedType.LPArray)] double[] pYData, UIntPtr nYSize,
double intercept,
double target,
double alpha,
short nRetType,
ref double retVal);
/// <summary> Returns the fitted values of the conditional mean, residuals or leverage measures. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#722", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SLR_FITTED([MarshalAs(UnmanagedType.LPArray)] double[] pXData, UIntPtr nXSize,
[MarshalAs(UnmanagedType.LPArray)] double[] pYData, UIntPtr nYSize,
double intercept,
short nRetType);
/// <summary> Returns the fitted values of the conditional mean, residuals or leverage measures. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#723", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SLR_ANOVA([MarshalAs(UnmanagedType.LPArray)] double[] pXData, UIntPtr nXSize,
[MarshalAs(UnmanagedType.LPArray)] double[] pYData, UIntPtr nYSize,
double intercept,
short nRetType);
/// <summary> Calculates a measure for the goodness of fit (e.g. R^2). </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#724", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int NDK_SLR_GOF([MarshalAs(UnmanagedType.LPArray)] double[] pXData, UIntPtr nXSize,
[MarshalAs(UnmanagedType.LPArray)] double[] pYData, UIntPtr nYSize,
double intercept,
short nRetType,
ref double retVal);
// MLR
/// <summary> Calculates the OLS regression coefficients values </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#730", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int NDK_MLR_PARAM(IntPtr pXData, UIntPtr nXSize,UIntPtr nXVars,
[MarshalAs(UnmanagedType.LPArray)] byte[] mask, UIntPtr nMaskLen,
[MarshalAs(UnmanagedType.LPArray)] double[] pYData, UIntPtr nYSize,
double intercept,
double alpha,
short nRetType,
short ParamIndex,
ref double retVal);
/// <summary>
/// Calculates the OLS regression coefficients values
/// </summary>
/// <param name="pXData">is the independent (explanatory) variables data matrix, such that each column represents one variable.</param>
/// <param name="mask">is the boolean array to choose the explanatory variables in the model. If missing, all variables in X are included.</param>
/// <param name="pYData">is the response or the dependent variable data array (one dimensional array of cells).</param>
/// <param name="intercept">is the constant or intercept value to fix (e.g. zero). If missing (i.e. NaN), an intercept will not be fixed and is computed normally.</param>
/// <param name="alpha">is the statistical significance of the test (i.e. alpha). If missing or omitted, an alpha value of 5% is assumed.</param>
/// <param name="nRetType">is a switch to select the return output (1=value (default), 2=std. error, 3=t-stat, 4=P-value, 5=upper limit (CI), 6=lower limit (CI)):</param>
/// <param name="ParamIndex">is a switch to designate the target parameter (0=intercept (default), 1=first variable, 2=2nd variable, etc.).</param>
/// <param name="retVal">is the computed statistics of the regression coefficient.</param>
/// <returns></returns>
public static NDK_RETCODE MLR_PARAM(double[,] pXData,
byte[] mask,
double[] pYData,
double intercept,
double alpha,
short nRetType,
short ParamIndex,
ref double retVal)
{
NDK_RETCODE retCode = NDK_RETCODE.NDK_FAILED;
retVal = Double.NaN;
int iRow = pXData.GetLength(0); // number of rows
int iCol = pXData.GetLength(1); // number of columns
int nMaskLen = mask.GetLength(0);
int nYSize = pYData.GetLength(0);
IntPtr[] p2dArray = new IntPtr[iRow];
for (int i = 0; i < iRow; i++)
{
double[] pdArray = new double[iCol];
// Fill row (array)
for (int j = 0; j < iCol; j++)
{
pdArray[j] = pXData[i, j];
}
p2dArray[i] = Marshal.AllocCoTaskMem(Marshal.SizeOf(pdArray[0]) * iCol);
Marshal.Copy(pdArray, 0, p2dArray[i], iCol);
}
IntPtr vars = (IntPtr)0;
IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(vars) * iRow);
Marshal.Copy(p2dArray, 0, buffer, iRow);
retCode = (NDK_RETCODE)SFSDK.NDK_MLR_PARAM(buffer, (UIntPtr)iRow, (UIntPtr)iCol, mask, (UIntPtr)nMaskLen, pYData, (UIntPtr)nYSize, intercept,
alpha, nRetType, ParamIndex, ref retVal);
// Free the memory allocated
for (int i = 0; i < iRow; i++)
{
// Free individual rows
Marshal.FreeCoTaskMem(p2dArray[i]);
}
// Free array holding row addresses
Marshal.FreeCoTaskMem(buffer);
return retCode;
}
/// <summary> Calculates the forecast mean, error and confidence interval. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#731", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int NDK_MLR_FORE( IntPtr pXData, UIntPtr nXSize, UIntPtr nXVars,
[MarshalAs(UnmanagedType.LPArray)] byte[] mask, UIntPtr nMaskLen,
[MarshalAs(UnmanagedType.LPArray)] double[] pYData, UIntPtr nYSize,
double intercept,
double target,
double alpha,
short nRetType,
ref double retVal);
/// <summary>
/// Calculates the forecast mean, error and confidence interval.
/// </summary>
/// <param name="pXData">is the independent (explanatory) variables data matrix, such that each column represents one variable.</param>
/// <param name="mask">is the boolean array to choose the explanatory variables in the model. If missing, all variables in X are included.</param>
/// <param name="pYData">is the response or the dependent variable data array (one dimensional array of cells).</param>
/// <param name="intercept">is the constant or intercept value to fix (e.g. zero). If missing (i.e. NaN), an intercept will not be fixed and is computed normally.</param>
/// <param name="target">is the value of the explanatory variables (a one dimensional array).</param>
/// <param name="alpha">is the statistical significance of the test (i.e. alpha). If missing or omitted, an alpha value of 5% is assumed.</param>
/// <param name="nRetType">is a switch to select the return output (1=forecast (default), 2=error, 3=upper limit, 4=lower limit):</param>
/// <param name="retVal">is the computed forecast statistics.</param>
/// <returns></returns>
public static NDK_RETCODE MLR_FORE(double[,] pXData,
byte[] mask,
double[] pYData,
double intercept,
double target,
double alpha,
short nRetType,
ref double retVal)
{
NDK_RETCODE retCode = NDK_RETCODE.NDK_FAILED;
retVal = Double.NaN;
int iRow = pXData.GetLength(0); // number of rows
int iCol = pXData.GetLength(1); // number of columns
int nMaskLen = mask.GetLength(0);
int nYSize = pYData.GetLength(0);
IntPtr[] p2dArray = new IntPtr[iRow];
for (int i = 0; i < iRow; i++)
{
double[] pdArray = new double[iCol];
// Fill row (array)
for (int j = 0; j < iCol; j++)
{
pdArray[j] = pXData[i, j];
}
p2dArray[i] = Marshal.AllocCoTaskMem(Marshal.SizeOf(pdArray[0]) * iCol);
Marshal.Copy(pdArray, 0, p2dArray[i], iCol);
}
IntPtr vars = (IntPtr)0;
IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(vars) * iRow);
Marshal.Copy(p2dArray, 0, buffer, iRow);
retCode = (NDK_RETCODE)SFSDK.NDK_MLR_FORE(buffer, (UIntPtr)iRow, (UIntPtr)iCol, mask, (UIntPtr)nMaskLen, pYData, (UIntPtr)nYSize, intercept,
target, alpha, nRetType, ref retVal);
// Free the memory allocated
for (int i = 0; i < iRow; i++)
{
// Free individual rows
Marshal.FreeCoTaskMem(p2dArray[i]);
}
// Free array holding row addresses
Marshal.FreeCoTaskMem(buffer);
return retCode;
}
/// <summary> Returns the fitted values of the conditional mean, residuals or leverage measures. </summary>
/// <returns> an integer value for the status of the call. For a full list, see <see cref="NDK_RETCODE"/>.</returns>
[DllImport(DLLName, EntryPoint = "#732", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int NDK_MLR_FITTED(IntPtr pXData, UIntPtr nXSize, UIntPtr nXVars,
[MarshalAs(UnmanagedType.LPArray)] byte[] mask, UIntPtr nMaskLen,
[MarshalAs(UnmanagedType.LPArray)] double[] pYData, UIntPtr nYSize,
double intercept,
short nRetType);
/// <summary>
/// Returns the fitted values of the conditional mean, residuals or leverage measures.
/// </summary>
/// <param name="pXData">is the independent (explanatory) variables data matrix, such that each column represents one variable.</param>
/// <param name="mask">is the boolean array to choose the explanatory variables in the model. If missing, all variables in X are included.</param>
/// <param name="pYData">is the response or the dependent variable data array (one dimensional array of cells).</param>
/// <param name="intercept">is the constant or intercept value to fix (e.g. zero). If missing (i.e. NaN), an intercept will not be fixed and is computed normally.</param>
/// <param name="nRetType">is a switch to select the return output (1=fitted values (default), 2=residuals, 3=standardized residuals, 4=leverage, 5=Cook's distance).</param>
/// <returns>status code of the operation</returns>
public static NDK_RETCODE MLR_FITTED( double[,] pXData,
byte[] mask,
double[] pYData,
double intercept,
short nRetType)
{
NDK_RETCODE retCode = NDK_RETCODE.NDK_FAILED;
int iRow = pXData.GetLength(0); // number of rows
int iCol = pXData.GetLength(1); // number of columns
int nMaskLen = mask.GetLength(0);
int nYSize = pYData.GetLength(0);
IntPtr[] p2dArray = new IntPtr[iRow];
for (int i = 0; i < iRow; i++)
{
double[] pdArray = new double[iCol];
// Fill row (array)
for (int j = 0; j < iCol; j++)
{
pdArray[j] = pXData[i, j];
}