tweaking ffi bindings, bumping version
This commit is contained in:
parent
8ff7e0ca3c
commit
e74c266a6e
.gitea/workflows
Cargo.lockCargo.tomlFinLib.NET/FinLib
finlib-cpp/include
finlib-ffi
finlib/src/options/blackscholes
@ -131,7 +131,7 @@ jobs:
|
||||
|
||||
- name: Push
|
||||
working-directory: ./FinLib.NET/FinLib
|
||||
run: dotnet nuget push --source gitea ./bin/Release/FinLib.NET.0.0.3.nupkg
|
||||
run: dotnet nuget push --source gitea ./bin/Release/FinLib.NET.0.0.4.nupkg
|
||||
|
||||
buildWASM:
|
||||
name: Build WASM
|
||||
|
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -259,7 +259,7 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||
|
||||
[[package]]
|
||||
name = "finlib"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
dependencies = [
|
||||
"getrandom 0.2.15",
|
||||
"log",
|
||||
@ -274,7 +274,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "finlib-ffi"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
dependencies = [
|
||||
"cbindgen",
|
||||
"csbindgen",
|
||||
@ -283,7 +283,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "finlib-wasm"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"console_log",
|
||||
@ -606,7 +606,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pyfinlib"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
dependencies = [
|
||||
"finlib",
|
||||
"log",
|
||||
|
@ -14,7 +14,7 @@ default-members = [
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
authors = ["sarsoo <andy@sarsoo.xyz>"]
|
||||
description = "Quant finance functions implemented in Rust"
|
||||
edition = "2021"
|
||||
|
@ -7,8 +7,5 @@ namespace FinLib.Interest;
|
||||
|
||||
public static class Interest
|
||||
{
|
||||
public static double Compound(double principal, double rate, double time, double n)
|
||||
{
|
||||
return NativeMethods.interest_compound(principal, rate, time, n);
|
||||
}
|
||||
public static double Compound(double principal, double rate, double time, double n) => NativeMethods.interest_compound(principal, rate, time, n);
|
||||
}
|
@ -30,4 +30,6 @@ public static class ValueAtRisk
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static double ScaleValueAtRisk(double initialValue, nint timeCycles) => NativeMethods.scale_value_at_risk(initialValue, timeCycles);
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageId>FinLib.NET</PackageId>
|
||||
<Version>0.0.4</Version>
|
||||
<Authors>sarsoo</Authors>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageId>FinLib.NET</PackageId>
|
||||
<Version>0.0.1</Version>
|
||||
<Authors>sarsoo</Authors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<Content Include="..\..\target\debug\libfinlib_ffi.*">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
@ -28,9 +28,48 @@ namespace FinLib
|
||||
[DllImport(__DllName, EntryPoint = "varcovar_value_at_risk", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
internal static extern double* varcovar_value_at_risk(double* arr, nuint len, double confidence);
|
||||
|
||||
[DllImport(__DllName, EntryPoint = "scale_value_at_risk", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
internal static extern double scale_value_at_risk(double initial_value, nint time_cycles);
|
||||
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe partial struct Portfolio
|
||||
{
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe partial struct PortfolioAsset
|
||||
{
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe partial struct OptionVariables
|
||||
{
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe partial struct CallOption
|
||||
{
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe partial struct PutOption
|
||||
{
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe partial struct OptionGreeks
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
internal enum ValueType : byte
|
||||
{
|
||||
Absolute,
|
||||
RateOfChange,
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ const double *historical_value_at_risk(const double *arr, size_t len, double con
|
||||
|
||||
double interest_compound(double principal, double rate, double time, double n);
|
||||
|
||||
double scale_value_at_risk(double initial_value, ptrdiff_t time_cycles);
|
||||
|
||||
const double *varcovar_value_at_risk(const double *arr, size_t len, double confidence);
|
||||
|
||||
} // extern "C"
|
||||
|
@ -19,7 +19,18 @@ fn main() {
|
||||
csbindgen::Builder::default()
|
||||
.input_extern_file("src/lib.rs")
|
||||
.input_extern_file("../finlib/src/lib.rs")
|
||||
.input_extern_file("../finlib/src/risk/portfolio.rs")
|
||||
.input_extern_file("../finlib/src/options/blackscholes/mod.rs")
|
||||
.csharp_dll_name("libfinlib_ffi")
|
||||
.always_included_types([
|
||||
"Portfolio",
|
||||
"ValueType",
|
||||
"PortfolioAsset",
|
||||
"OptionVariables",
|
||||
"CallOption",
|
||||
"PutOption",
|
||||
"OptionGreeks",
|
||||
])
|
||||
.csharp_namespace("FinLib")
|
||||
.generate_csharp_file("../FinLib.NET/FinLib/NativeMethods.g.cs")
|
||||
.unwrap();
|
||||
|
@ -144,11 +144,11 @@ bitflags = false
|
||||
############## Options for How Your Rust library Should Be Parsed ##############
|
||||
|
||||
[parse]
|
||||
parse_deps = false
|
||||
# include = []
|
||||
exclude = []
|
||||
parse_deps = true
|
||||
include = ["finlib"]
|
||||
#exclude = []
|
||||
clean = false
|
||||
extra_bindings = []
|
||||
extra_bindings = ["finlib"]
|
||||
|
||||
|
||||
|
||||
|
@ -44,3 +44,9 @@ pub unsafe extern "C" fn varcovar_value_at_risk(arr: *const f64, len: usize, con
|
||||
|
||||
Box::into_raw(Box::new(finlib::risk::var::varcovar::value_at_risk_percent(input_array, confidence)))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn scale_value_at_risk(initial_value: f64, time_cycles: isize) -> f64 {
|
||||
|
||||
finlib::risk::var::varcovar::scale_value_at_risk(initial_value, time_cycles)
|
||||
}
|
||||
|
@ -255,11 +255,11 @@ pub fn vega(v: &OptionVariables) -> f64 {
|
||||
#[cfg_attr(feature = "ffi", repr(C))]
|
||||
#[derive(Debug, Copy, Clone, Default, PartialEq, PartialOrd)]
|
||||
pub struct OptionGreeks {
|
||||
delta: f64,
|
||||
gamma: f64,
|
||||
vega: f64,
|
||||
theta: f64,
|
||||
rho: f64
|
||||
pub delta: f64,
|
||||
pub gamma: f64,
|
||||
pub vega: f64,
|
||||
pub theta: f64,
|
||||
pub rho: f64
|
||||
}
|
||||
|
||||
impl OptionGreeks {
|
||||
|
Loading…
x
Reference in New Issue
Block a user