indiTraders - Forum for the Active Indian Trader  

Go Back   indiTraders - Forum for the Active Indian Trader > Tools > Software > Other Platforms

Reply
 
Bookmark and Share LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 21-04-2016, 07:33 PM
nTP's Avatar
nTP nTP is offline
Flash Crash
 
Join Date: Dec 2013
Location: kolkata
Posts: 2,077
Thanks: 7,884
Thanked 2,291 Times in 1,369 Posts
nTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud ofnTP has much to be proud of
Default py : SCTR

Hi

I am having little bit issue with this coding as the output is differing from the expected.I am expecting little help from the forum members to complete rest of the code with correct output:

reg: SCTR.

SCTR Details


Code:
from nsepy import get_history
from datetime import date
import pandas as pd
import requests
from io import BytesIO 
import certifi
from scipy import stats
from dateutil.relativedelta import relativedelta
#import numpy as np
#import matplotlib.pyplot as plt
import datetime
import numpy as np
import matplotlib.colors as colors
import matplotlib.finance as finance
import matplotlib.dates as mdates
import matplotlib.ticker as mticker
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import talib as ta
from talib import MA_Type

#Long-Term Indicators (weighting)

#  * Percent above/below 200-day EMA (30%)
#  * 125-Day Rate-of-Change (30%)

#Medium-Term Indicators (weighting)

#  * Percent above/below 50-day EMA (15%)
#  * 20-day Rate-of-Change (15%)

# Short-Term Indicators (weighting)

#  * 3-day slope of PPO-Histogram (5%)
#  * 14-day RSI (5%)

url1 = 'https://www1.nseindia.com/content/indices/ind_nifty_Alpha_Index.csv'
def datainpy(url):

	headers = { 'Accept' : '*/*',
	            'User-Agent' : 'Mozilla/5.0',
	            'Refers' : 'http://www.nseindia.com',
	            'Connection' : 'keep-alive'
	          }
            
	getContents = requests.get(url,headers=headers).content
	symbol_list=pd.read_csv(BytesIO(getContents))

	print(symbol_list.head())

	for eachSymbol in symbol_list['Symbol']:
	    stock = get_history(symbol = eachSymbol,
	                        start = date(2000,3,20),
	                        end = date(2016,3,30))
	    stock.drop_duplicates(inplace=True)
	    stock.drop(stock.columns[[0,1,2,7,8,10,11,12,13]], axis = 1, inplace = True)
	    print (stock.head())
	    print(stock.head())
	    stock.index=pd.to_datetime(stock.index)
	    stock.to_csv('./HistoricalData//' + eachSymbol + '.csv' , date_format='%Y%m%d')
            return stock;

def PPOCust(c, fastperiod, slowperiod, signalperiod):
	    """Percentage Price Oscillator"""
	    fast = ta.EMA(c, fastperiod)
	    slow = ta.EMA(c, slowperiod)
	    ppo = 100 * (fast - slow) / slow
	    signal = ta.EMA(ppo, signalperiod)
	    histogram = ppo - signal
	    return histogram

def slopeCust(x,n):
	
	for i in range(len(x)):
	   	if i<len(x)-n: 
	 	       slope = stats.linregress(x[i:i+n],y[i:i+n])[0]
        return slope 

StockData=datainpy(url=url1)   
StockData.dropna()
ppoHist=PPOCust(StockData['Last'].values,12,26,3)

slope3days=slopeCust(ppoHist,ppoHist[:-3],3)
print(StockData.head())
type(StockData)
np.set_printoptions(precision=3)



RSI14=ta.RSI(StockData['Last'].values,14)

DMA200=ta.SMA(StockData['Last'].values,200)

EMA50=ta.EMA(StockData['Last'].values,14)

ROC125=ta.ROC(StockData['Last'].values,125)

ROC20=ta.ROC(StockData['Last'].values,14)

weightPctDiffOfEMA50=(((StockData['Last'].values-EMA50)*100)/StockData['Last'].values)*15

weightPctDiffOfDMA200=(((StockData['Last'].values-DMA200)*100)/StockData['Last'].values)*30

weightROC125=ROC125*30

weightROC20=ROC20*15

weightRSI14=RSI14*5
if slopeCust >= -45 :
	weightslope3days=((slope3days+1)*50)*5
else :
	weightslope3days=0

weightppoHist=ppoHist*5
print(weightppoHist)
SCTR=(weightPctDiffOfDMA200+weightPctDiffOfEMA50+weightROC125+weightROC20+weightppoHist+weightRSI14)/100


print(SCTR)
actually stucking to get the slope of the ppo histogram And result was not matching.
__________________
thx
nTuple

Disclaimer: I am not a Research Analyst and not registered with any regulating authority. All posts are for educational purpose only.

Consider us a dumb -dumble guy in this analysis, any type of real time example will be quick-learn approach.

Last edited by nTP; 21-04-2016 at 08:26 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to nTP For This Useful Post:
Reply

indiTraders - Forum for the Active Indian Trader > Tools > Software > Other Platforms


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 08:00 PM.


vBulletin Copyright by vBulletin

Content Relevant URLs by vBSEO 3.3.2