Skip to content

Commit 615f3a8

Browse files
committed
v2.4.0
1 parent f76effa commit 615f3a8

File tree

3 files changed

+119
-6
lines changed

3 files changed

+119
-6
lines changed

deno.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nshiab/journalism",
3-
"version": "2.3.3",
3+
"version": "2.4.0",
44
"exports": {
55
".": "./src/index.ts",
66
"./web": "./src/web.ts"
@@ -27,7 +27,7 @@
2727
"@nshiab/journalism-format": "jsr:@nshiab/journalism-format@^1.1.2",
2828
"@nshiab/journalism-geo": "jsr:@nshiab/journalism-geo@^1.0.3",
2929
"@nshiab/journalism-google": "jsr:@nshiab/journalism-google@^1.0.4",
30-
"@nshiab/journalism-statistics": "jsr:@nshiab/journalism-statistics@^1.0.2",
30+
"@nshiab/journalism-statistics": "jsr:@nshiab/journalism-statistics@^1.1.0",
3131
"@nshiab/journalism-web": "jsr:@nshiab/journalism-web@^1.0.1",
3232
"@nshiab/journalism-web-scraping": "jsr:@nshiab/journalism-web-scraping@^1.0.2"
3333
},

deno.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

llm.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,6 +3139,55 @@ const significantSnow = vancouverSnow.filter((record) =>
31393139
console.table(significantSnow);
31403140
```
31413141
3142+
## getGbmParameters
3143+
3144+
Calculates the parameters (drift `mu` and volatility `sigma`) for a Geometric
3145+
Brownian Motion (GBM) model based on historical data.
3146+
3147+
Geometric Brownian Motion is a continuous-time stochastic process often used to
3148+
model stock prices and other financial assets. This function estimates the drift
3149+
and volatility from a series of observed values, assuming the returns follow a
3150+
log-normal distribution.
3151+
3152+
**When to use this function:**
3153+
3154+
- To estimate parameters for simulating future asset paths using GBM
3155+
- When you have a sequence of historical prices or values and need to determine
3156+
their annualized growth rate (drift) and risk (volatility)
3157+
- To model potential future scenarios for a stock, index, or commodity based on
3158+
historical trends
3159+
3160+
### Signature
3161+
3162+
```typescript
3163+
function getGbmParameters(
3164+
values: number[],
3165+
periodsPerYear: number,
3166+
): { mu: number; sigma: number };
3167+
```
3168+
3169+
### Parameters
3170+
3171+
- **`values`**: - An array of numerical values (e.g., historical prices)
3172+
- **`periodsPerYear`**: - The number of data points per year (e.g., 252 for
3173+
daily trading days, 12 for monthly data, 52 for weekly)
3174+
3175+
### Returns
3176+
3177+
An object containing the annualized drift (`mu`) and annualized volatility
3178+
(`sigma`)
3179+
3180+
### Examples
3181+
3182+
```ts
3183+
const prices = [100, 102, 101, 105, 107, 110];
3184+
const periodsPerYear = 252; // Daily data
3185+
3186+
const { mu, sigma } = calculateGbmParameters(prices, periodsPerYear);
3187+
console.log(`Annualized Drift (mu): ${mu.toFixed(4)}`);
3188+
console.log(`Annualized Volatility (sigma): ${sigma.toFixed(4)}`);
3189+
```
3190+
31423191
## getGeoTiffDetails
31433192
31443193
Extracts detailed information from a GeoTIFF file, which can then be used with
@@ -3236,6 +3285,70 @@ const value = await getGeoTiffValues(45.50, -73.57, geoTiffDetails);
32363285
console.log(value); // 255
32373286
```
32383287
3288+
## getGmbPath
3289+
3290+
Generates a simulated path for an asset using the Geometric Brownian Motion
3291+
(GBM) model.
3292+
3293+
Geometric Brownian Motion is a continuous-time stochastic process in which the
3294+
logarithm of the randomly varying quantity follows a Brownian motion with drift.
3295+
It is widely used in mathematical finance to model stock prices, as it ensures
3296+
that values remain positive and accounts for compounded returns.
3297+
3298+
**When to use this function:**
3299+
3300+
- To simulate future value paths for a stock, index, or other financial asset
3301+
- For risk management and stress testing by generating multiple potential
3302+
scenarios
3303+
- To visualize the impact of volatility and drift on an investment over time
3304+
3305+
**Note:** You can use `getGbmParameters` to estimate the `mu` and `sigma`
3306+
parameters from historical data before generating a path.
3307+
3308+
### Signature
3309+
3310+
```typescript
3311+
function getGmbPath(
3312+
startValue: number,
3313+
mu: number,
3314+
sigma: number,
3315+
years: number,
3316+
periodsPerYear: number,
3317+
): number[];
3318+
```
3319+
3320+
### Parameters
3321+
3322+
- **`startValue`**: - The initial value of the asset at the beginning of the
3323+
simulation
3324+
- **`mu`**: - The expected annualized drift (average growth rate) of the asset
3325+
- **`sigma`**: - The annualized volatility (degree of variation) of the asset
3326+
- **`years`**: - The total duration of the simulation in years
3327+
- **`periodsPerYear`**: - The number of simulation steps per year (e.g., 252 for
3328+
daily trading days, 12 for monthly data, 52 for weekly)
3329+
3330+
### Returns
3331+
3332+
An array of numerical values representing the simulated path, including the
3333+
`startValue`
3334+
3335+
### Examples
3336+
3337+
```ts
3338+
import getGbmParameters from "./getGbmParameters";
3339+
3340+
const historicalValues = [100, 102, 101, 105, 107, 110];
3341+
const periodsPerYear = 252; // Daily data
3342+
3343+
// Estimate parameters from historical data
3344+
const { mu, sigma } = getGbmParameters(historicalValues, periodsPerYear);
3345+
3346+
// Generate a simulated path for the next year
3347+
const startValue = historicalValues[historicalValues.length - 1];
3348+
const path = generateGBMPath(startValue, mu, sigma, 1, periodsPerYear);
3349+
console.log(`Simulated path: ${path.map((v) => v.toFixed(2)).join(", ")}`);
3350+
```
3351+
32393352
## getHtmlTable
32403353
32413354
Extracts tabular data from an HTML table on a given URL and returns it as an

0 commit comments

Comments
 (0)