Skip to content

Commit

Permalink
Fixing Documentation (#451)
Browse files Browse the repository at this point in the history
# Describe Request

Updated all the documentation and bumped to 2.1.0 based on a few
remaining code changes that were needed. Now the work I set out to do
originally is completely finished. You're good to merge @cinar ! 👍
  • Loading branch information
cereallarceny authored Apr 15, 2024
1 parent 0a8fc96 commit 1d447cf
Show file tree
Hide file tree
Showing 48 changed files with 1,756 additions and 1,765 deletions.
200 changes: 100 additions & 100 deletions README.md

Large diffs are not rendered by default.

326 changes: 13 additions & 313 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indicatorts",
"version": "2.0.0",
"version": "2.1.0",
"description": "Stock technical indicators and strategies in TypeScript for browser and server programs.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -50,14 +50,14 @@
"homepage": "https://github.com/cinar/indicatorts#readme",
"devDependencies": {
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"esbuild": "^0.20.1",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"esbuild": "^0.20.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
"typescript": "^5.4.5"
}
}
35 changes: 19 additions & 16 deletions src/backtest/index.md → src/backtest/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
### Backtest
# Backtest

Backtesting is the method for seeing how well a strategy would have done. The following backtesting functions are provided for evaluating strategies.

- [Strategy Info](#strategy-info)
- [Strategy Result](#strategy-result)
- [Backtest Function](#backtest-function)
- [Company Info](#company-info)
- [Company Result](#company-result)
- [Strategy Stats](#strategy-stats)
- [Compute Strategy Stats](#compute-strategy-stats)
- [Backtest](#backtest)
- [Strategy Info](#strategy-info)
- [Strategy Result](#strategy-result)
- [Backtest Function](#backtest-function)
- [Company Info](#company-info)
- [Company Result](#company-result)
- [Strategy Stats](#strategy-stats)
- [Compute Strategy Stats](#compute-strategy-stats)
- [Disclaimer](#disclaimer)
- [License](#license)

#### Strategy Info
## Strategy Info

The [StrategyInfo](./strategyInfo.ts) provides a strategy function with a name.

Expand All @@ -36,7 +39,7 @@ const strategyInfo: StrategyInfo = {

The strategy infos for all strategies are provided under [STRATEGY_INFOS](./strategyInfo.ts).

#### Strategy Result
## Strategy Result

The [StrategyResult](./strategyResult.ts) provides the result of a given strategy after the backtest.

Expand All @@ -50,17 +53,17 @@ interface StrategyResult {

The _info_ is the [Strategy Info](#strategy-info), the _gain_ is the result of the strategy at the end, and the _lastAction_ is the last action provided by the given strategy.

#### Backtest Function
## Backtest Function

The [backtest](./backtest.ts) function takes an [Asset](../strategy/index.md#Asset), an array of [StrategyInfo](#strategy-info), and returns an array of [StrategyResult](#strategy-result).
The [backtest](./backtest.ts) function takes an [Asset](../strategy/README.md#Asset), an array of [StrategyInfo](#strategy-info), and returns an array of [StrategyResult](#strategy-result).

```TypeScript
import {bactest} from 'indicatorts';

const results = backtest(asset, STRATEGY_INFOS);
```

#### Company Info
## Company Info

The [CompanyInfo](../company/companyInfo.ts) provides the company information.

Expand All @@ -75,7 +78,7 @@ interface CompanyInfo {

The [SP500_COMPANIES](../company/companyInfo.ts) are provided.

#### Company Result
## Company Result

The [CompanyResult](./companyResult.ts) provides the company result.

Expand All @@ -88,7 +91,7 @@ interface CompanyResult {

The _companyInfo_ is the [CompanyInfo](#company-info), and _strategyResults_ is an array of [StrategyResult](#strategy-result).

#### Strategy Stats
## Strategy Stats

The [StrategyStats](./strategyStats.ts) provides the stats for a given strategy.

Expand All @@ -104,7 +107,7 @@ interface StrategyStats {

The _strategyInfo_ is the [StrategyInfo](#strategy-info) of the given strategy, _score_ is the total count of times this strategy generated the highest gain, the _minGain_ is the minimum gain, _maxGain_ is the maximum gain, and the _averageGain_ is the average gain.

##### Compute Strategy Stats
### Compute Strategy Stats

The [computeStrategyStats](./strategyStats.ts) takes an array for [CompanyResult](#company-result), and returns an array of [StrategyStats](#strategy-stats).

Expand Down
25 changes: 14 additions & 11 deletions src/chart/index.md → src/chart/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
### Chart
# Chart

Chart provides an easy way to plot the outcome of the indicators and the strategies.

- [Chart Initialization](#chart-initialization)
- [Data Set](#data-set)
- [Add Data](#add-data)
- [Remove Data](#remove-data)
- [Draw Chart](#draw-chart)
- [Chart](#chart)
- [Chart Initialization](#chart-initialization)
- [Data Set](#data-set)
- [Add Data](#add-data)
- [Remove Data](#remove-data)
- [Draw Chart](#draw-chart)
- [Disclaimer](#disclaimer)
- [License](#license)

#### Chart Initialization
## Chart Initialization

The [Chart](./chart.ts) is used to draw the plot on a given canvas.

Expand All @@ -22,7 +25,7 @@ import {Chart} from 'indicatorts';
const chart = new Chart('canvas');
```

#### Data Set
## Data Set

The [DataSet](./chart.ts) interface provides the necessary information for ploting the data.

Expand All @@ -37,7 +40,7 @@ export interface DataSet {

The _legend_ is the legend to display for the data, the _values_ are the data values, the optional _style_ is either a single color, or an array of colors, and the optional _width_ is the width of the line.

#### Add Data
## Add Data

The [add](./chart.ts) function is used to add data to the chart.

Expand All @@ -50,15 +53,15 @@ chart.add({
});
```

#### Remove Data
## Remove Data

The [remove](./chart.ts) function is used to remove data from chart by the given _legend_ value.

```TypeScript
const removed = chart.remove(legend);
```

#### Draw Chart
## Draw Chart

The [draw](./chart.ts) function is used to draw the added data to the chart.

Expand Down
203 changes: 203 additions & 0 deletions src/indicator/momentum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# Momentum Indicators

Momentum indicators measure the speed of movement.

- [Momentum Indicators](#momentum-indicators)
- [Awesome Oscillator (AO)](#awesome-oscillator-ao)
- [Chaikin Oscillator (CMO)](#chaikin-oscillator-cmo)
- [Ichimoku Cloud](#ichimoku-cloud)
- [Percentage Price Oscillator (PPO)](#percentage-price-oscillator-ppo)
- [Percentage Volume Oscillator (PVO)](#percentage-volume-oscillator-pvo)
- [Price Rate of Change (ROC)](#price-rate-of-change-roc)
- [Relative Strength Index (RSI)](#relative-strength-index-rsi)
- [Stochastic Oscillator (STOCH)](#stochastic-oscillator-stoch)
- [Williams R (WILLR)](#williams-r-willr)
- [Disclaimer](#disclaimer)
- [License](#license)

**NOTE:** All configuration objects for all indicators are optional. If no configuration object is passed, the default configuration will be used. Likewise, you may also partially pass a configuration object, and the default values will be used for the missing properties.

## Awesome Oscillator (AO)

The [awesomeOscillator](./awesomeOscillator.ts) function calculates the awesome oscillator based on low and high daily prices for a given stock. It is an indicator used to measure market momentum.

```
Median Price = ((Low + High) / 2)
AO = 5-Period SMA - 34-Period SMA.
```

```TypeScript
import { ao } from 'indicatorts';

const defaultConfig = { fast: 5, slow: 34 };
const result = ao(highs, lows, defaultConfig);

// Alternatively:
// const result = awesomeOscillator(highs, lows, defaultConfig);
```

## Chaikin Oscillator (CMO)

The [chaikinOscillator](./chaikinOscillator.ts) function measures the momentum of the [Accumulation/Distribution (A/D)](../volume/README.md#accumulationdistribution-ad) using the [Moving Average Convergence Divergence (MACD)](../trend/README.md#moving-average-convergence-divergence-macd) formula. It takes the difference between fast and slow periods EMA of the A/D. Cross above the A/D line indicates bullish.

```
CO = Ema(fastPeriod, AD) - Ema(slowPeriod, AD)
```

```TypeScript
import { cmo } from 'indicatorts';

const defaultConfig = { fast: 3, slow: 10 };
const { adResult, cmoResult } = cmo(highs, lows, closings, volumes, defaultConfig);

// Alternatively:
// const { adResult, cmoResult } = chaikinOscillator(highs, lows, closings, volumes, defaultConfig);
```

Most frequently used fast and short periods are 3 and 10.

## Ichimoku Cloud

The [ichimokuCloud](./ichimokuCloud.ts), also known as Ichimoku Kinko Hyo, calculates a versatile indicator that defines support and resistence, identifies trend direction, gauges momentum, and provides trading signals.

```
Tenkan-sen (Conversion Line) = (9-Period High + 9-Period Low) / 2
Kijun-sen (Base Line) = (26-Period High + 26-Period Low) / 2
Senkou Span A (Leading Span A) = (Conversion Line + Base Line) / 2
Senkou Span B (Leading Span B) = (52-Period High + 52-Period Low) / 2
Chikou Span (Lagging Span) = Closing plotted 26 days in the past.
```

```TypeScript
import { ichimokuCloud } from 'indicatorts';

const defaultConfig = { short: 9, medium: 26, long: 52, close: 26 };
const { conversion, base, leadingSpanA, leadingSpanB, leadingSpan } = ichimokuCloud(highs, lows, closings, defaultConfig);
```

## Percentage Price Oscillator (PPO)

The [percentagePriceOscillator](./percentagePriceOscillator.ts) function calculates a momentum oscillator for the price It is used to indicate the ups and downs based on the price. A breakout is confirmed when PPO is positive.

```
PPO = ((EMA(fastPeriod, prices) - EMA(slowPeriod, prices)) / EMA(longPeriod, prices)) * 100
Signal = EMA(9, PPO)
Histogram = PPO - Signal
```

```TypeScript
import { ppo } from 'indicatorts';

const defaultConfig = { fast: 12, slow: 26, signal: 9 };
const { ppoResult, signal, histogram } = ppo(prices, defaultConfig);

// Alternatively:
// const { ppoResult, signal, histogram } = percentagePriceOscillator(prices, defaultConfig);
```

## Percentage Volume Oscillator (PVO)

The [percentageVolumeOscillator](./percentageVolumeOscillator.ts) function calculates a momentum oscillator for the volume It is used to indicate the ups and downs based on the volume. A breakout is confirmed when PVO is positive.

```
PVO = ((EMA(fastPeriod, volumes) - EMA(slowPeriod, volumes)) / EMA(longPeriod, volumes)) * 100
Signal = EMA(9, PVO)
Histogram = PVO - Signal
```

```TypeScript
import { pvo } from 'indicatorts';

const defaultConfig = { fast: 12, slow: 26, signal: 9 };
const { pvoResult, signal, histogram } = pvo(volumes, defaultConfig);

// Alternatively:
// const { pvoResult, signal, histogram } = percentageVolumeOscillator(volumes, defaultConfig);
```

## Price Rate of Change (ROC)

The [roc](./priceRateOfChange.ts) function calculates a unbounded momentum indicator for the closing prices. A rising ROC above zero typically indicates an uptrend whereas a falling ROC below zero indicates a downtrend.

```
ROC[i] = 0 when i < period
ROC[i] = (close[i] / close[i-period] - 1) * 100 when i >= period
```

```TypeScript
import { roc } from 'indicatorts';

const defaultConfig = { period: 3 };
const result = roc(close, defaultConfig);

// Alternatively:
// const result = priceRateOfChange(close, defaultConfig);
```

Ensure that the array `close` does not contain $0$ to avoid division by 0 errors.

## Relative Strength Index (RSI)

The [rsi](./relativeStrengthIndex.ts) function calculates a momentum indicator that measures the magnitude of recent price changes to evaluate overbought and oversold conditions using a window period.

```
RS = Average Gain / Average Loss
RSI = 100 - (100 / (1 + RS))
```

```TypeScript
import { rsi } from 'indicatorts';

const defaultConfig = { period: 14 };
const result = rsi(closings, defaultConfig);

// Alternatively:
// const result = relativeStrengthIndex(closings, defaultConfig);
```

## Stochastic Oscillator (STOCH)

The [stochasticOscillator](./stochasticOscillator.ts) function calculates a momentum indicator that shows the location of the closing relative to high-low range over a set number of periods.

```
K = (Closing - Lowest Low) / (Highest High - Lowest Low) * 100
D = 3-Period SMA of K
```

```TypeScript
import { stoch } from 'indicatorts';

const defaultConfig = { kPeriod: 14, dPeriod: 3 };
const { k, d } = stoch(highs, lows, closings, defaultConfig);

// Alternatively:
// const { k, d } = stochasticOscillator(highs, lows, closings, defaultConfig);
```

## Williams R (WILLR)

The [williamsR](./williamsR.ts) function calculates the Williams R based on low, high, and closing prices. It is a type of momentum indicator that moves between 0 and -100 and measures overbought and oversold levels.

```
WR = (Highest High - Closing) / (Highest High - Lowest Low)
```

```TypeScript
import { willr } from 'indicatorts';

const defaultConfig = { period: 14 };
const result = willr(highs, lows, closings, defaultConfig);

// Alternatively:
// const result = williamsR(highs, lows, closings, defaultConfig);
```

## Disclaimer

The information provided on this project is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.

## License

Copyright (c) 2022 Onur Cinar. All Rights Reserved.

The source code is provided under MIT License.
8 changes: 4 additions & 4 deletions src/indicator/momentum/chaikinOscillator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe('Chaikin Oscillator (CMO)', () => {
fast: 2,
slow: 5,
});
deepStrictEqual(roundDigitsAll(2, actual.ad), expectedAD);
deepStrictEqual(roundDigitsAll(2, actual.cmo), expectedCMO);
deepStrictEqual(roundDigitsAll(2, actual.adResult), expectedAD);
deepStrictEqual(roundDigitsAll(2, actual.cmoResult), expectedCMO);
});

it('should be able to compute without a config', () => {
Expand All @@ -36,7 +36,7 @@ describe('Chaikin Oscillator (CMO)', () => {
];

const actual = cmo(highs, lows, closings, volumes);
deepStrictEqual(roundDigitsAll(2, actual.ad), expectedAD);
deepStrictEqual(roundDigitsAll(2, actual.cmo), expectedCMO);
deepStrictEqual(roundDigitsAll(2, actual.adResult), expectedAD);
deepStrictEqual(roundDigitsAll(2, actual.cmoResult), expectedCMO);
});
});
Loading

0 comments on commit 1d447cf

Please sign in to comment.