Skip to content

Instantly share code, notes, and snippets.

@swr1bm86
Created January 24, 2020 06:32
Show Gist options
  • Save swr1bm86/06608e822d27e4fba8509fa5266e1d09 to your computer and use it in GitHub Desktop.
Save swr1bm86/06608e822d27e4fba8509fa5266e1d09 to your computer and use it in GitHub Desktop.
display infinite and finite ema
import numpy as np
import pandas as pd
import plotly.graph_objects as go
from finta import TA
if __name__ == '__main__':
ts = pd.date_range('1/1/2000', periods=100)
price = pd.DataFrame(np.random.randn(100, 1), index=ts, columns=['close'])
# https://blog.csdn.net/Papageno_Xue/article/details/82705157
ema_finite = TA.EMA(price)
ema_infinite = TA.EMA(price, adjust=False)
fig = go.Figure()
fig.add_trace(go.Scatter(x=ts, y=price.iloc[:, 0],
mode='lines',
name='price'))
fig.add_trace(go.Scatter(x=ts, y=ema_finite,
mode='lines',
name='ema-finite'))
fig.add_trace(go.Scatter(x=ts, y=ema_infinite,
mode='lines',
name='ema-infinite'))
fig.show()
@swr1bm86
Copy link
Author

image

the infinite and finite EMA will only diverge at the very first beginning period

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment