Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code for calculating EMA Exponential Moving Average on any Poloniex market #713

Closed
gemini100 opened this issue Nov 29, 2017 · 3 comments
Closed
Assignees

Comments

@gemini100
Copy link

gemini100 commented Nov 29, 2017

hi Igor and community,
it's not an issue, but i publish here because not under oop coding
here is my little contribution on ccxt
for poloniex a python 3.5 function that compute the last value of ema for any pair

you need to call: calculema(300,14,'BTC','AMP')
for a periodic of 300 seconds and on 14 hours historical data of AMP/BTC market

import requests
import json
import time
import urllib.request
import pandas as pd
import numpy as np

def ExpMovingAverage(values, window):
    weights = np.exp(np.linspace(-1., 0., window))
    weights /= weights.sum()
    a =  np.convolve(values, weights, mode='full')[:len(values)]
    a[:window] = a[window]
    return a


def calcalema(period1,hrsnumbers,basesur,cur):
	# period1 300, 900, 1800, 7200, 14400, and 86400
	rightnow=time.time()
	url ='https://poloniex.com/public?command=returnChartData&currencyPair='+basesur+'_'+cur +'&start=' + str(int(rightnow - hrsnumbers*60*60)) + '&end=9999999999&period='+ str(period1)
	
	rrie = requests.get(url)
	r2rie=rrie.json()
	
	lescloses=list()
	for i in r2rie:
		for key,val in i.items():
			
			lescloses.append(i['close'])
				
	
	return  ExpMovingAverage(lescloses, period1)
@kroitor kroitor self-assigned this Nov 29, 2017
@kroitor
Copy link
Member

kroitor commented Nov 29, 2017

Thank you!

I'm sure Python coders will find this contribution useful for learning and for practical purposes as well!

I can't really integrate this code into ccxt, because statistical calculations are beyond the scope of the library for now, that is why we have numpy (used in the above example) and other cool standalone libs for that which can be combined with ccxt to cover most of the needs. I'll leave this issue open for a while.

@kroitor kroitor changed the title code for calculating ema exponentian moving average on any poloniex market code for calculating EMA Exponential Moving Average on any Poloniex market Nov 29, 2017
@gemini100
Copy link
Author

gemini100 commented Nov 29, 2017 via email

@kroitor kroitor closed this as completed Dec 1, 2017
@andrewnaem
Copy link

i think -1.0 in linspace must be 1.0 in positive to add more weight to recent data not old data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants