Skip to content

Commit acda11b

Browse files
committed
Update readme
1 parent 8e544e4 commit acda11b

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

README.md

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ pip install pyindicators
1414

1515
* Native Python implementation, no external dependencies needed except for Polars or Pandas
1616
* Dataframe first approach, with support for both pandas dataframes and polars dataframes
17-
* Trend indicators(#trend-indicators)
17+
* [Trend indicators](#trend-indicators)
1818
* [Simple Moving Average (SMA)](#simple-moving-average-sma)
1919
* [Exponential Moving Average (EMA)](#exponential-moving-average-ema)
20-
* Momentum indicators(#momentum-indicators)
20+
* [Momentum indicators](#momentum-indicators)
2121
* [Relative Strength Index (RSI)](#relative-strength-index-rsi)
2222
* [Relative Strength Index Wilders method (RSI)](#wilders-relative-strength-index-wilders-rsi)
23-
* Indicator helpers(#indicator-helpers)
23+
* [Indicator helpers](#indicator-helpers)
2424
* [Crossover](#crossover)
2525
* [Is Crossover](#is-crossover)
2626

@@ -161,7 +161,7 @@ pl_df.show(10)
161161

162162
# Calculate EMA and crossover for Pandas DataFrame
163163
pd_df = ema(pd_df, source_column="Close", period=200, result_column="EMA_200")
164-
pl_df = ema(pd_df, source_column="Close", period=50, result_column="EMA_50")
164+
pd_df = ema(pd_df, source_column="Close", period=50, result_column="EMA_50")
165165
pd_df = crossover(
166166
pd_df,
167167
first_column="EMA_50",
@@ -179,29 +179,53 @@ pd_df.tail(10)
179179
from polars import DataFrame as plDataFrame
180180
from pandas import DataFrame as pdDataFrame
181181

182-
from pyindicators import is_crossover
183-
184-
# Polars DataFrame
185-
pl_df = plDataFrame({
186-
"EMA_50": [200, 201, 202, 203, 204, 205, 206, 208, 208, 210],
187-
"EMA_200": [200, 201, 202, 203, 204, 205, 206, 207, 209, 209],
188-
"DateTime": pd.date_range("2021-01-01", periods=10, freq="D")
189-
})
190-
# Pandas DataFrame
191-
pd_df = pdDataFrame({
192-
"EMA_50": [200, 201, 202, 203, 204, 205, 206, 208, 208, 210],
193-
"EMA_200": [200, 201, 202, 203, 204, 205, 206, 207, 209, 209],
194-
"DateTime": pd.date_range("2021-01-01", periods=10, freq="D")
195-
})
182+
from investing_algorithm_framework import CSVOHLCVMarketDataSource
183+
from pyindicators import crossover, ema
184+
185+
# For this example the investing algorithm framework is used for dataframe creation,
186+
csv_path = "./tests/test_data/OHLCV_BTC-EUR_BINANCE_15m_2023-12-01:00:00_2023-12-25:00:00.csv"
187+
data_source = CSVOHLCVMarketDataSource(csv_file_path=csv_path)
196188

189+
pl_df = data_source.get_data()
190+
pd_df = data_source.get_data(pandas=True)
191+
192+
# Calculate EMA and crossover for Polars DataFrame
193+
pl_df = ema(pl_df, source_column="Close", period=200, result_column="EMA_200")
194+
pl_df = ema(pl_df, source_column="Close", period=50, result_column="EMA_50")
195+
pl_df = crossover(
196+
pl_df,
197+
first_column="EMA_50",
198+
second_column="EMA_200",
199+
result_column="Crossover_EMA"
200+
)
201+
202+
# If you want the function to calculate the crossovors in the function
197203
if is_crossover(
198204
pl_df, first_column="EMA_50", second_column="EMA_200", data_points=3
199205
):
200-
print("Crossover detected in Polars DataFrame")
206+
print("Crossover detected in Pandas DataFrame in the last 3 data points")
201207

208+
# If you want to use the result of a previous crossover calculation
209+
if is_crossover(pl_df, crossover_column="Crossover_EMA", data_points=3):
210+
print("Crossover detected in Pandas DataFrame in the last 3 data points")
211+
212+
# Calculate EMA and crossover for Pandas DataFrame
213+
pd_df = ema(pd_df, source_column="Close", period=200, result_column="EMA_200")
214+
pd_df = ema(pd_df, source_column="Close", period=50, result_column="EMA_50")
215+
pd_df = crossover(
216+
pd_df,
217+
first_column="EMA_50",
218+
second_column="EMA_200",
219+
result_column="Crossover_EMA"
220+
)
202221

222+
# If you want the function to calculate the crossovors in the function
203223
if is_crossover(
204224
pd_df, first_column="EMA_50", second_column="EMA_200", data_points=3
205225
):
206-
print("Crossover detected in Pandas DataFrame")
226+
print("Crossover detected in Pandas DataFrame in the last 3 data points")
227+
228+
# If you want to use the result of a previous crossover calculation
229+
if is_crossover(pd_df, crossover_column="Crossover_EMA", data_points=3):
230+
print("Crossover detected in Pandas DataFrame in the last 3 data points")
207231
```

0 commit comments

Comments
 (0)