Skip to content

Instantly share code, notes, and snippets.

@zjhmale
Created January 24, 2020 06:32
Show Gist options
  • Save zjhmale/06608e822d27e4fba8509fa5266e1d09 to your computer and use it in GitHub Desktop.
Save zjhmale/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()
@zjhmale
Copy link
Author

zjhmale commented Jan 24, 2020

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