Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
furechan committed Sep 22, 2024
1 parent 8c02d04 commit ba5627c
Show file tree
Hide file tree
Showing 40 changed files with 17,036 additions and 10,169 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Include cython files
recursive-include src *.c *.pxi *.pyx
recursive-include src *.c *.pxd
recursive-exclude src *.pxi *.pyx

# Include data files
recursive-include src *.csv
160 changes: 80 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

This library offers a curated list of technical analysis indicators
implemented in cython. It is built around `numpy` arrays and aims to be compatible
with both `pandas` and `polars` dataframes where possible.
with `pandas` or `polars` dataframes where possible.


> **Warning**
Expand All @@ -20,19 +20,19 @@ The `mintalib` package contains three main modules:

## Functions

Indicators are available as simple functions via the `functions` module,
Functions are available via the `functions` module,
with names like `SMA`, `EMA`, `RSI`, `MACD`, all in **upper case**.
The first parameter of a function is either `prices` or `series` depending on whether
the functions expects a dataframe of prices or a single series.
Functions that expect series data can still be applied to prices data, in which case they use
the `close` column by default or otherwize the column specified with the `item` parameter.
Functions that expect series data can be applied to a prices dataframe, in which case they use
the column specified with the `item` parameter or by default the `close` column.

A `prices` dataframe can be a pandas dataframe, a polars dataframe or a dictionary of numpy arrays.
The column names for prices are expected to include `open`, `high`, `low`, `close` all in **lower case**.
A `series` can be a pandas series, a polars series or any iterable compatible with numpy arrays.

Functions attempt to wrap their result to match their input, so that for example
pandas based inputs will yield pandas based results with matching index.
Functions automatically wrap their result to match their input, so that for example
pandas based inputs will yield pandas based results with a matching index.


```python
Expand All @@ -54,26 +54,31 @@ high200 = MAX(prices, 200, item='high') # MAX of 'high' with period = 200
```


## Composable Interface
## Indicators

Indicators are also available through a composable interface via the `indicators` module,
with similar the same names all in **uper case**.
Each indicator is implemented as a class to be instanciated with calculation parameters.
The instance objects are callables that can be applied to series or prices data like regular functions.
So for example `SMA(50)` is a callable object that will return the 50 period simple moving average of its argument.
Indicators are available via the `indicators` module, with similar names as functions all in **uper case**.
Indicators offer a composable interface where a function is bound with its calculation parameters. When instantiated with parameters an indicator yields a callable that can be applied to prices or series data. Indicators support the `@` operator as syntactic sugar to apply the indicator to data. So for example `SMA(50) @ prices` can be used to compute the 50 period simple moving average on `prices`, insted of `SMA(50)(prices)`.

Indicators can be composed with the `@` operator,
where for example `EMA(20) @ ROC(5)` means `EMA(20)` applied to `ROC(5)`.
The same `@` operator can also be used to apply an indicator to some data,
where for example `SMA(50) @ prices` can be used to compute the 50 period simple moving average on `prices`.

Please note that with pandas dataframes you can compose and assign multiple indicators in one go
```python
sma1 = SMA(50) @ prices
sma2 = SMA(200) @ prices
```

The `@` operator can also be used to compose indicators, where for example `ROC(1) @ EMA(20)` means `ROC(1)` applied to `EMA(20)`.


```python
slope = ROC(1) @ EMA(20) @ prices
```

Please note that with pandas dataframes you can compose and assign multiple indicators in one call
using the builtin `assign` method.

```python
import yfinance as yf

from mintalib.indicators import EMA, SMA, ROC, RSI, SLOPE, EVAL
from mintalib.indicators import EMA, SMA, ROC, RSI, EVAL

# fetch prices (eg with yfinance)
prices = yf.Ticker('AAPL').history('5y')
Expand All @@ -86,14 +91,9 @@ result = prices.assign(
sma50 = SMA(50),
sma200 = SMA(200),
rsi = RSI(14),
slope = SLOPE(20),
trend = EMA(20) @ ROC(5),
pos = EVAL("sma50 > sma200")
slope = ROC(1) @ EMA(20),
uptrend = EVAL("sma50 > sma200")
)

# you will notice that the EVAL expression at the end
# can use the names sma50 and sma200 that where defined
# just above in the same function call!
```


Expand All @@ -119,60 +119,60 @@ python -mpip install git+https://github.com/furechan/mintalib.git

## List of Indicators

| Name | Description |
|:-----------------|:------------------------------------------|
| ADX | Average Directional Index |
| ATR | Average True Range |
| AVGPRICE | Average Price |
| BBANDS | Bollinger Bands |
| BOP | Balance of Power |
| CCI | Commodity Channel Index |
| CMF | Chaikin Money Flow |
| CROSSOVER | Cross Over |
| CROSSUNDER | Cross Under |
| DEMA | Double Exponential Moving Average |
| DIFF | Difference |
| EFFICIENCY_RATIO | Efficiency Ratio (Kaufman) |
| EMA | Exponential Moving Average |
| EVAL | Expression Eval (pandas only) |
| EXP | Exponential |
| FLAG_ABOVE | Flag for value above level |
| FLAG_BELOW | Flag for value below level |
| FORECAST | Forecast (time linear regression) |
| INVERT_FLAG | Invert flag |
| KAMA | Kaufman Adaptive Moving Average (Kaufman) |
| KELTNER | Keltner Channel |
| LATR | Average True Range (logarithmic) |
| LOG | Logarithm |
| MA | Generic Moving Average |
| MACD | Moving Average Convergenge Divergence |
| MAD | Mean Absolute Deviation |
| MAX | Rolling Maximum |
| MFI | Money Flow Index |
| MIDPRICE | Mid Price |
| MIN | Rolling Minimum |
| MINUSDI | Minus Directional Index |
| NATR | Average True Range (normalized) |
| PLUSDI | Plus Directional Index |
| PPO | Price Percentage Oscillator |
| PRICE | Generic Price |
| RMA | Rolling Moving Average (RSI Style) |
| ROC | Rate of Change |
| RSI | Relative Strength Index |
| RVALUE | RValue (time linear regression) |
| SAR | Parabolic Stop and Reverse |
| SLOPE | Slope (time linear regression) |
| SMA | Simple Moving Average |
| STDEV | Standard Deviation |
| STOCH | Stochastic Oscillator |
| STREAK_DOWN | Consecutive streak of downs |
| STREAK_UP | Consecutive streak of ups |
| SUM | Rolling Sum |
| TEMA | Triple Exponential Moving Average |
| TRANGE | True Range |
| TYPPRICE | Typical Price |
| UPDOWN_FLAG | Flag for value crossing levels up & down |
| WCLPRICE | Weighted Close Price |
| WMA | Weighted Moving Average |
| Name | Description |
|:------------|:------------------------------------------|
| ADX | Average Directional Index |
| ATR | Average True Range |
| AVGPRICE | Average Price |
| BBANDS | Bollinger Bands |
| BOP | Balance of Power |
| CCI | Commodity Channel Index |
| CMF | Chaikin Money Flow |
| CROSSOVER | Cross Over |
| CROSSUNDER | Cross Under |
| DEMA | Double Exponential Moving Average |
| DIFF | Difference |
| EMA | Exponential Moving Average |
| EVAL | Expression Eval (pandas only) |
| EXP | Exponential |
| FLAG_ABOVE | Flag for value above level |
| FLAG_BELOW | Flag for value below level |
| FLAG_INVERT | Inverse flag |
| FLAG_UPDOWN | Flag for value crossing up & down levels |
| FORECAST | Forecast (time linear regression) |
| HMA | Hull Moving Average |
| KAMA | Kaufman Adaptive Moving Average (Kaufman) |
| KELTNER | Keltner Channel |
| KER | Kaufman Efficiency Ratio |
| LATR | Average True Range (logarithmic) |
| LOG | Logarithm |
| MA | Generic Moving Average |
| MACD | Moving Average Convergenge Divergence |
| MAD | Mean Absolute Deviation |
| MAX | Rolling Maximum |
| MFI | Money Flow Index |
| MIDPRICE | Mid Price |
| MIN | Rolling Minimum |
| MINUSDI | Minus Directional Index |
| NATR | Average True Range (normalized) |
| PLUSDI | Plus Directional Index |
| PPO | Price Percentage Oscillator |
| PRICE | Generic Price |
| RMA | Rolling Moving Average (RSI Style) |
| ROC | Rate of Change |
| RSI | Relative Strength Index |
| RVALUE | RValue (time linear regression) |
| SAR | Parabolic Stop and Reverse |
| SLOPE | Slope (time linear regression) |
| SMA | Simple Moving Average |
| STDEV | Standard Deviation |
| STOCH | Stochastic Oscillator |
| STREAK | Consecutive streak of ups or downs |
| SUM | Rolling Sum |
| TEMA | Triple Exponential Moving Average |
| TRANGE | True Range |
| TYPPRICE | Typical Price |
| WCLPRICE | Weighted Close Price |
| WMA | Weighted Moving Average |


23 changes: 0 additions & 23 deletions archive/noxfile.py

This file was deleted.

35 changes: 0 additions & 35 deletions archive/python-package.yaml

This file was deleted.

Loading

0 comments on commit ba5627c

Please sign in to comment.