Пример #1
0
from datetime import date
import pandas as pd
import matplotlib.dates as mdates

# example from - http://matplotlib.org/examples/pylab_examples/finance_demo.html

start = date(2012,9,1)
end = date(2015,9,21)

mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
alldays = DayLocator()              # minor ticks on the days
weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
dayFormatter = DateFormatter('%d')      # e.g., 12
#proxies = {'http':'proxy1.wipro.com:8080'}
proxies = {}
df = get_price_history(stock = 'RELIANCE', start = start, 
                      end = end, proxies = proxies)
                      
df["Date"] = pd.to_datetime(df.index)
df.Date = mdates.date2num(df.Date.dt.to_pydatetime())
quotes = [tuple(x) for x in df[['Date', 'Open', 'High', 'Low', 'Close', 'Volume']].to_records(index=False)]


#quotes = quotes_historical_yahoo_ohlc('INTC', date1, date2)
if len(quotes) == 0:
    raise SystemExit

fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)
ax.xaxis.set_major_locator(mondays)
ax.xaxis.set_minor_locator(alldays)
ax.xaxis.set_major_formatter(weekFormatter)
Пример #2
0
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 15 19:33:20 2015

@author: SW274998
"""
from nsepy.archives import get_price_history
from datetime import date
import numpy

start = date(2010, 6, 1)
end = date(2015, 9, 1)

d = get_price_history(stock="RELIANCE", start=start, end=end)
d["VLog"] = numpy.log10(d["Volume"])
d["Ratio"] = d["High"] / d["Low"] - 1
d[["Ratio", "VLog"]].plot(secondary_y="VLog")
Пример #3
0
from datetime import date
import pandas as pd
import matplotlib.dates as mdates

# example from - http://matplotlib.org/examples/pylab_examples/finance_demo.html

start = date(2012, 9, 1)
end = date(2015, 9, 21)

mondays = WeekdayLocator(MONDAY)  # major ticks on the mondays
alldays = DayLocator()  # minor ticks on the days
weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
dayFormatter = DateFormatter('%d')  # e.g., 12
#proxies = {'http':'proxy1.wipro.com:8080'}
proxies = {}
df = get_price_history(stock='RELIANCE', start=start, end=end, proxies=proxies)

df["Date"] = pd.to_datetime(df.index)
df.Date = mdates.date2num(df.Date.dt.to_pydatetime())
quotes = [
    tuple(x)
    for x in df[['Date', 'Open', 'High', 'Low', 'Close', 'Volume']].to_records(
        index=False)
]

#quotes = quotes_historical_yahoo_ohlc('INTC', date1, date2)
if len(quotes) == 0:
    raise SystemExit

fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)
Пример #4
0
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 15 19:33:20 2015

@author: SW274998
"""
from nsepy.archives import get_price_history
from datetime import date
import numpy
start = date(2010, 6, 1)
end = date(2015, 9, 1)

d = get_price_history(stock='RELIANCE', start=start, end=end)
d['VLog'] = numpy.log10(d['Volume'])
d['Ratio'] = d['High'] / d['Low'] - 1
d[['Ratio', 'VLog']].plot(secondary_y='VLog')
Пример #5
0
from nsepy.archives import get_price_history
from nsepy import indices
from datetime import date
#Stock price history
sbin = get_price_history(stock = 'SBIN',
                        start = date(2015,1,1), 
                        end = date(2015,1,10))
sbin[[ 'VWAP', 'Turnover']].plot(secondary_y='Turnover')
#Index price history
nifty = indices.archives.get_price_history(index = "NIFTY 50", 
                                            start = date(2015,9,1), 
                                            end = date(2015,9,24))
nifty[['Close', 'Turnover']].plot(secondary_y='Turnover')
#Index P/E ratio history
nifty_pe = indices.archives.get_pe_history(index = "NIFTY 50", 
                                            start = date(2015,9,1), 
                                            end = date(2015,9,24))
nifty_pe['Index'] = nifty['Close']
nifty_pe[['Index', 'P/E']].plot(secondary_y='P/E')
Пример #6
0
from datetime import date
import pandas as pd
import matplotlib.dates as mdates

# example from - http://matplotlib.org/examples/pylab_examples/finance_demo.html

start = date(2015,9,1)
end = date(2015,9,21)

mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
alldays = DayLocator()              # minor ticks on the days
weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
dayFormatter = DateFormatter('%d')      # e.g., 12
#proxies = {'http':'proxy1.wipro.com:8080'}

df = get_price_history(stock='SBIN', start=start, 
                      end = end)
                      
df["Date"] = pd.to_datetime(df.index)
df.Date = mdates.date2num(df.Date.dt.to_pydatetime())
quotes = [tuple(x) for x in df[['Date', 'Open', 'High', 'Low', 'Close', 'Volume']].to_records(index=False)]


#quotes = quotes_historical_yahoo_ohlc('INTC', date1, date2)
if len(quotes) == 0:
    raise SystemExit

fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)
ax.xaxis.set_major_locator(mondays)
ax.xaxis.set_minor_locator(alldays)
ax.xaxis.set_major_formatter(weekFormatter)
Пример #7
0
from nsepy.archives import get_price_history


dates = [('01-01-2015', '31-01-2015'), ('01-04-2015', '31-07-2015'),
         ('01-07-2015',   '30-10-2015'), ('01-10-2015', '31-12-2015')]

for date in dates:
    df = get_price_history(stock = 'DABUR', start = date[0], end = date[1])
    print df  ['Close'] 
Пример #8
0
    a = np.convolve(x, weights, mode='full')[:len(x)]
    a[:n] = a[n]
    return a
share = pd.read_csv('ind_nifty50list.csv', parse_dates=True)
ints1=0
columns = ['Share', 'RSI','50DMA','Close','MRsi5Day']
#columns = ['Share', 'RSI']
dfnew = pd.DataFrame(columns=columns)


while (ints1 <100) :
            sharen=share.at[ints1,'Symbol']
            ints1 = ints1 + 1
            strs = sharen
            df=get_price_history(stock = strs,start = start,end = enddate)
            r=df

            r.sort()
            prices = r['Close']
            rsi = relative_strength(prices)

            ma50 = moving_average(prices, 50, type='simple')
            ints=np.size(rsi)
            dfrsi = pd.DataFrame(rsi)
            x = np.asarray(rsi)
            Moving=np.asarray(ma50)
            dfnew.loc[len(dfnew)+1]=[strs, x[ints-1 ],Moving[ints-1 ],prices[ints-1], dfrsi.tail().max() ]
            if ints1>30:
                break
Пример #9
0
from datetime import date
import pandas as pd
import matplotlib.dates as mdates

# example from - http://matplotlib.org/examples/pylab_examples/finance_demo.html

start = date(2015, 9, 1)
end = date(2015, 9, 21)

mondays = WeekdayLocator(MONDAY)  # major ticks on the mondays
alldays = DayLocator()  # minor ticks on the days
weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
dayFormatter = DateFormatter('%d')  # e.g., 12
#proxies = {'http':'proxy1.wipro.com:8080'}

df = get_price_history(stock='SBIN', start=start, end=end)

df["Date"] = pd.to_datetime(df.index)
df.Date = mdates.date2num(df.Date.dt.to_pydatetime())
quotes = [
    tuple(x)
    for x in df[['Date', 'Open', 'High', 'Low', 'Close', 'Volume']].to_records(
        index=False)
]

#quotes = quotes_historical_yahoo_ohlc('INTC', date1, date2)
if len(quotes) == 0:
    raise SystemExit

fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)
Пример #10
0
Created on Thu Sep 24 19:57:15 2015

@author: SW274998
"""

from math import pi

import pandas as pd

from bokeh.sampledata.stocks import MSFT
from bokeh.plotting import figure, show, output_file

from nsepy.archives import get_price_history
from datetime import date

df = get_price_history(stock = 'SBIN', start = date(2015,8,1),
                            end = date(2015,9,24))
df["Date"] = pd.to_datetime(df.index)

mids = (df.Open + df.Close)/2
spans = abs(df.Close-df.Open)

inc = df.Close > df.Open
dec = df.Open > df.Close
w = 12*60*60*1000 # half day in ms

output_file("candlestick.html", title="candlestick.py example")

TOOLS = "pan,wheel_zoom,box_zoom,reset,save"

p = figure(x_axis_type="datetime", tools=TOOLS, plot_width=1000, toolbar_location="left")
Пример #11
0
@author: SW274998
"""

from math import pi

import pandas as pd

from bokeh.sampledata.stocks import MSFT
from bokeh.plotting import figure, show, output_file

from nsepy.archives import get_price_history
from datetime import date

df = get_price_history(stock='SBIN',
                       start=date(2015, 8, 1),
                       end=date(2015, 9, 24))
df["Date"] = pd.to_datetime(df.index)

mids = (df.Open + df.Close) / 2
spans = abs(df.Close - df.Open)

inc = df.Close > df.Open
dec = df.Open > df.Close
w = 12 * 60 * 60 * 1000  # half day in ms

output_file("candlestick.html", title="candlestick.py example")

TOOLS = "pan,wheel_zoom,box_zoom,reset,save"

p = figure(x_axis_type="datetime",
Пример #12
0
import numpy as np
import pandas as pd
import statsmodels
from statsmodels.tsa.stattools import coint
import matplotlib.pyplot as plt
from nsepy.archives import get_price_history
from datetime import date

S1 = get_price_history(stock='SBIN',
                       start=date(2015, 1, 1),
                       end=date(2015, 10, 10))
S2 = get_price_history(stock='ICICIBANK',
                       start=date(2015, 1, 1),
                       end=date(2015, 10, 10))
result = coint(S1[['Close']], S2[['Close']])
score = result[0]
pvalue = result[1]

#S1[['Close']].plot()
#S2[['Close']].plot()

score, pvalue, _ = coint(S1[['Close']], S2[['Close']])
diff_series = S2[['Close']] - S1[['Close']]
diff_series.plot()


def zscore(series):
    return (series - series.mean()) / np.std(series)


zscore(diff_series).plot()