-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the other parameters convertions and Historical and Variance Co…
…variance methods of VaR computation
- Loading branch information
Showing
6 changed files
with
242 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
# RiskJS | ||
|
||
The goal of this project is to port [Calvin456/VaR](https://github.com/calvin456/VaR) library into JavaScript for Value at Risk calculation. | ||
The goal of this project is to port [Calvin456/VaR](https://github.com/calvin456/VaR) library into JavaScript for Portfolio Value at Risk calculation. | ||
|
||
This library for now includes CVaR computation using the following methods: | ||
- Historical | ||
- Monte Carlo | ||
- Variance Covariance (used now in Vigor project) | ||
|
||
Many other quantitative finance computations might be added in the future to facilitate the use of such functionality in JavaScript Blockchain Oracles. | ||
|
||
This is part of our team work to participate in LiquidApps Global Hackathon 2019. | ||
|
||
|
@@ -26,21 +33,31 @@ There is a small but important suite of tests to check that this code runs corre | |
```bash | ||
$ npm run test | ||
|
||
> [email protected].1 test ./vigorish/riskjs | ||
> [email protected].5 test ./vigorish/riskjs | ||
> mocha test/*.js | ||
|
||
Loading data from "./test/data.csv" | ||
Loading data from "./test/data.csv" | ||
Loading data from "./test/data.csv" | ||
|
||
|
||
Portfolio Monte Carlo VaR | ||
✓ RiskJS.portfolioMonteCarloVaR() should be a function | ||
✓ Should throw error when tried with wrong arguments (103ms) | ||
✓ Should return a string with the same result value (104ms) | ||
CVaR Historical | ||
✓ RiskJS.CVaRHistorical() should be a function | ||
✓ Should throw error when tried with wrong arguments | ||
✓ Should return a string with the same result value | ||
|
||
CVaR Monte Carlo | ||
✓ RiskJS.CVaRMonteCarlo() should be a function | ||
✓ Should throw error when tried with wrong arguments (111ms) | ||
✓ Should return a string with the same result value (99ms) | ||
|
||
3 passing (213ms) | ||
CVaR Variance Covariance | ||
✓ RiskJS.CVaRVarianceCovariance() should be a function | ||
✓ Should throw error when tried with wrong arguments | ||
✓ Should return a string with the same result value | ||
|
||
|
||
9 passing (221ms) | ||
``` | ||
|
||
#### Dependencies | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const | ||
RiskJS = require('../index.js'), | ||
should = require('should'), | ||
fs = require('fs'), | ||
csv = require('csv-parse/lib/sync'); | ||
|
||
const source = './test/data.csv'; | ||
|
||
// Load data from csv file | ||
console.log('Loading data from "%s"', source); | ||
const data = csv(fs.readFileSync(source, 'utf8'), { | ||
skip_empty_lines: true | ||
}); | ||
// console.log(data); | ||
|
||
describe('CVaR Historical', () => { | ||
var value; | ||
|
||
it('RiskJS.CVaRHistorical() should be a function', () => { | ||
RiskJS.CVaRHistorical.should.be.a.Function; | ||
}); | ||
|
||
it('Should throw error when tried with wrong arguments', () => { | ||
(() => RiskJS.CVaRHistorical()).should.throw('needs three arguments'); | ||
(() => RiskJS.CVaRHistorical(data, [0.5,0.5])).should.throw('needs three arguments'); | ||
(() => value = RiskJS.CVaRHistorical(data, [0.5,0.5], 0.95)).should.not.throw(); | ||
}); | ||
|
||
it('Should return a string with the same result value', () => { | ||
const res = RiskJS.CVaRHistorical(data, [0.5,0.5], 0.95); | ||
res.should.be.a.String; | ||
res.should.equal(value); | ||
// console.log('CVaR Historical = %s', res); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const | ||
RiskJS = require('../index.js'), | ||
should = require('should'), | ||
fs = require('fs'), | ||
csv = require('csv-parse/lib/sync'); | ||
|
||
const source = './test/data.csv'; | ||
|
||
// Load data from csv file | ||
console.log('Loading data from "%s"', source); | ||
const data = csv(fs.readFileSync(source, 'utf8'), { | ||
skip_empty_lines: true | ||
}); | ||
// console.log(data); | ||
|
||
describe('CVaR Monte Carlo', () => { | ||
var value; | ||
|
||
it('RiskJS.CVaRMonteCarlo() should be a function', () => { | ||
RiskJS.CVaRMonteCarlo.should.be.a.Function; | ||
}); | ||
|
||
it('Should throw error when tried with wrong arguments', () => { | ||
(() => RiskJS.CVaRMonteCarlo()).should.throw('needs three arguments'); | ||
(() => RiskJS.CVaRMonteCarlo(data, [0.5,0.5])).should.throw('needs three arguments'); | ||
(() => value = RiskJS.CVaRMonteCarlo(data, [0.5,0.5], 0.95)).should.not.throw(); | ||
}); | ||
|
||
it('Should return a string with the same result value', () => { | ||
const res = RiskJS.CVaRMonteCarlo(data, [0.5,0.5], 0.95); | ||
res.should.be.a.String; | ||
res.should.equal(value); | ||
// console.log('CVaR Monte Carlo = %s', res); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters