scoped npm package, running wasm locally
This commit is contained in:
parent
e13c5e3ac4
commit
1cefa6f756
5
finlib-wasm/js-local/bootstrap.js
vendored
Normal file
5
finlib-wasm/js-local/bootstrap.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// A dependency graph that contains any wasm must all be imported
|
||||||
|
// asynchronously. This `bootstrap.js` file does the single async import, so
|
||||||
|
// that no one else needs to worry about it again.
|
||||||
|
import("./index.js")
|
||||||
|
.catch(e => console.error("Error importing `index.js`:", e));
|
14
finlib-wasm/js-local/index.html
Normal file
14
finlib-wasm/js-local/index.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>finlib</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<script src="./bootstrap.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
4
finlib-wasm/js-local/index.js
Normal file
4
finlib-wasm/js-local/index.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import { ValueAtRisk } from "finlib";
|
||||||
|
|
||||||
|
console.log(ValueAtRisk.varcovar([1, 2, 3, 4], 0.1));
|
||||||
|
console.log(ValueAtRisk.varcovar([1, 2, 3, 4], 0.05));
|
23
finlib-wasm/js-local/package.json
Normal file
23
finlib-wasm/js-local/package.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "finlib-test",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "webpack --config webpack.prod.js --env production",
|
||||||
|
"devbuild": "webpack --config webpack.dev.js",
|
||||||
|
"start": "webpack serve --config webpack.dev.js --progress"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"finlib": "file:../pkg"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"description": "",
|
||||||
|
"devDependencies": {
|
||||||
|
"copy-webpack-plugin": "^11.0.0",
|
||||||
|
"webpack": "^5.88.2",
|
||||||
|
"webpack-cli": "^5.1.4",
|
||||||
|
"webpack-dev-server": "^4.15.1",
|
||||||
|
"webpack-merge": "^5.9.0"
|
||||||
|
}
|
||||||
|
}
|
22
finlib-wasm/js-local/webpack.common.js
Normal file
22
finlib-wasm/js-local/webpack.common.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: "./bootstrap.js",
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, "dist"),
|
||||||
|
filename: "bootstrap.js",
|
||||||
|
},
|
||||||
|
experiments: {
|
||||||
|
asyncWebAssembly: true
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new CopyWebpackPlugin({
|
||||||
|
patterns: [
|
||||||
|
{
|
||||||
|
from: path.resolve(__dirname, "index.html")
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
],
|
||||||
|
};
|
8
finlib-wasm/js-local/webpack.dev.js
Normal file
8
finlib-wasm/js-local/webpack.dev.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const { merge } = require('webpack-merge');
|
||||||
|
const common = require('./webpack.common.js');
|
||||||
|
|
||||||
|
module.exports = merge(common, {
|
||||||
|
mode: 'development',
|
||||||
|
devtool: 'inline-source-map',
|
||||||
|
watch: true
|
||||||
|
});
|
7
finlib-wasm/js-local/webpack.prod.js
Normal file
7
finlib-wasm/js-local/webpack.prod.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
const { merge } = require('webpack-merge');
|
||||||
|
const common = require('./webpack.common.js');
|
||||||
|
|
||||||
|
module.exports = merge(common, {
|
||||||
|
mode: 'production',
|
||||||
|
devtool: 'source-map'
|
||||||
|
});
|
5
finlib-wasm/js-repo/bootstrap.js
vendored
Normal file
5
finlib-wasm/js-repo/bootstrap.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// A dependency graph that contains any wasm must all be imported
|
||||||
|
// asynchronously. This `bootstrap.js` file does the single async import, so
|
||||||
|
// that no one else needs to worry about it again.
|
||||||
|
import("./index.js")
|
||||||
|
.catch(e => console.error("Error importing `index.js`:", e));
|
14
finlib-wasm/js-repo/index.html
Normal file
14
finlib-wasm/js-repo/index.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>finlib</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<script src="./bootstrap.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
4
finlib-wasm/js-repo/index.js
Normal file
4
finlib-wasm/js-repo/index.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import { ValueAtRisk } from "finlib";
|
||||||
|
|
||||||
|
console.log(ValueAtRisk.varcovar([1, 2, 3, 4], 0.1));
|
||||||
|
console.log(ValueAtRisk.varcovar([1, 2, 3, 4], 0.05));
|
23
finlib-wasm/js-repo/package.json
Normal file
23
finlib-wasm/js-repo/package.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "finlib-test",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "webpack --config webpack.prod.js --env production",
|
||||||
|
"devbuild": "webpack --config webpack.dev.js",
|
||||||
|
"start": "webpack serve --config webpack.dev.js --progress"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@sarsoo/finlib": "0.0.1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"description": "",
|
||||||
|
"devDependencies": {
|
||||||
|
"copy-webpack-plugin": "^11.0.0",
|
||||||
|
"webpack": "^5.88.2",
|
||||||
|
"webpack-cli": "^5.1.4",
|
||||||
|
"webpack-dev-server": "^4.15.1",
|
||||||
|
"webpack-merge": "^5.9.0"
|
||||||
|
}
|
||||||
|
}
|
22
finlib-wasm/js-repo/webpack.common.js
Normal file
22
finlib-wasm/js-repo/webpack.common.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: "./bootstrap.js",
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, "dist"),
|
||||||
|
filename: "bootstrap.js",
|
||||||
|
},
|
||||||
|
experiments: {
|
||||||
|
asyncWebAssembly: true
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new CopyWebpackPlugin({
|
||||||
|
patterns: [
|
||||||
|
{
|
||||||
|
from: path.resolve(__dirname, "index.html")
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
],
|
||||||
|
};
|
8
finlib-wasm/js-repo/webpack.dev.js
Normal file
8
finlib-wasm/js-repo/webpack.dev.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const { merge } = require('webpack-merge');
|
||||||
|
const common = require('./webpack.common.js');
|
||||||
|
|
||||||
|
module.exports = merge(common, {
|
||||||
|
mode: 'development',
|
||||||
|
devtool: 'inline-source-map',
|
||||||
|
watch: true
|
||||||
|
});
|
7
finlib-wasm/js-repo/webpack.prod.js
Normal file
7
finlib-wasm/js-repo/webpack.prod.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
const { merge } = require('webpack-merge');
|
||||||
|
const common = require('./webpack.common.js');
|
||||||
|
|
||||||
|
module.exports = merge(common, {
|
||||||
|
mode: 'production',
|
||||||
|
devtool: 'source-map'
|
||||||
|
});
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "finlib",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"draught": "file:../pkg"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"description": ""
|
|
||||||
}
|
|
@ -1 +1 @@
|
|||||||
sed -i -e 's/"name": "finlib-wasm"/"name": "finlib"/g' pkg/package.json
|
sed -i -e 's/"name": "finlib-wasm"/"name": "@sarsoo\/finlib"/g' pkg/package.json
|
@ -1,11 +1,35 @@
|
|||||||
use wasm_bindgen::prelude::wasm_bindgen;
|
use wasm_bindgen::prelude::wasm_bindgen;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn compound(principal: f64, rate: f64, time: f64, n: f64) -> f64 {
|
pub struct Interest { }
|
||||||
finlib::interest::compound(principal, rate, time, n)
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
impl Interest {
|
||||||
|
pub fn compound(principal: f64, rate: f64, time: f64, n: f64) -> f64 {
|
||||||
|
finlib::interest::compound(principal, rate, time, n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn covariance(slice: Vec<f64>, slice_two: Vec<f64>) -> Option<f64> {
|
pub struct ValueAtRisk { }
|
||||||
finlib::stats::covariance(&slice, &slice_two)
|
|
||||||
}
|
#[wasm_bindgen]
|
||||||
|
impl ValueAtRisk {
|
||||||
|
pub fn historical(values: Vec<f64>, confidence: f64) -> f64 {
|
||||||
|
finlib::risk::var::historical::value_at_risk(&values, confidence)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn varcovar(values: Vec<f64>, confidence: f64) -> f64 {
|
||||||
|
finlib::risk::var::varcovar::value_at_risk(&values, confidence)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub struct Stats { }
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
impl Stats {
|
||||||
|
pub fn covariance(slice: Vec<f64>, slice_two: Vec<f64>) -> Option<f64> {
|
||||||
|
finlib::stats::covariance(&slice, &slice_two)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user