Exemplo n.º 1
0
def redraw_chart(myTimeData):

    dataTransform = ["intraday", opentime, closetime]
    period = periods[0]
    myTimeData = mySymbol.get_timeData(period)
    AxesStyle = ""
    title = "Bar Chart. " + str(symbolID) + r" . Price ($\$$)"
    ylabel = ul5.period_dic[myTimeData.period]

    #    fig = gl.init_figure()
    ax = gl.tradingBarChart(myTimeData,
                            legend=["Close price"],
                            color="k",
                            nf=1,
                            labels=[title, "", ylabel],
                            AxesStyle="Normal" + AxesStyle,
                            dataTransform=dataTransform)
    gl.subplots_adjust(left=.09,
                       bottom=.10,
                       right=.90,
                       top=.95,
                       wspace=.20,
                       hspace=0)
Exemplo n.º 2
0
########## Obtain the data ###############
price = Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]).get_timeSeries(["Close"])
volume = Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]).get_timeSeries(["Volume"])
ret1 = Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]).get_timeSeriesReturn(["Close"])*100
dates = Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]).get_dates()

#print dates[0], dates[26], dates[27]
################# Plotting the data #################
if(trading_graph):
    # Trading plot of the points !
    title = "CLOSE Price, Volume and Return evolution"
    
    ax1 = gl.subplot2grid((5,1), (0,0), rowspan=2, colspan=1) 
    gl.tradingBarChart(Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]), ax = ax1,
                             dataTransform = dataTransform, AxesStyle = "Normal - No xaxis",
                             labels = [title,"",symbolIDs[symbol_ID_indx1] +"(" +str(periods[0])+")"])
    
    ax2 = gl.subplot2grid((5,1), (2,0), rowspan=1, colspan=1, sharex = ax1) 
    gl.stem(dates, volume, ax  = ax2, dataTransform = dataTransform,
                   AxesStyle = "Normal - No xaxis - Ny:4",
                   labels = ["","",symbolIDs[0] +"("+ str(periods[0])+ "M)"], legend = [ "Volume"])

    ax3 = gl.subplot2grid((5,1), (3,0), rowspan=2, colspan=1, sharex = ax1) 
    gl.stem(dates, ret1, ax = ax3, dataTransform = dataTransform,
                   AxesStyle = "Normal",
                   labels = ["","",symbolIDs[0] +"("+ str(periods[0])+ "M)"], legend = ["Return"])
#    
    gl.set_fontSizes(ax = [ax1,ax2,ax3], title = 20, xlabel = 20, ylabel = 20, 
                      legend = 20, xticks = 10, yticks = 10)
    
Exemplo n.º 3
0
        symbolID = symbolIDs_pf[i]
        myTimeData = myPortfolio.get_symbols([symbolID])[0].get_timeData(period)
        returns = myTimeData.get_timeSeriesReturn(["Close"])
        dates = myTimeData.get_dates()
        AxesStyle = " - No xaxis"
        if (i == len(symbolIDs_pf) -1):
            AxesStyle = ""
        if (i == 0):
            title = "Bar Chart. " + str(symbolIDs) + r" . Price ($\$$)"
            title2 = "Return"
        else:
            title = ""
            title2 = ""
        ylabel =   symbolID + " (" + ul.period_dic[myTimeData.period] + ")"
        ax = gl.tradingBarChart(myTimeData,  legend = ["Close price"], color = "k", 
                    nf = 1, sharex = axeshare, labels = [title,"",ylabel], 
                    AxesStyle = "Normal" + AxesStyle)
#                    dataTransform = dataTransform)
        ax = gl.stem(dates, returns,  legend = ["Return"], color = "k", 
                    nf = 1, sharex = axeshare, labels = [title2,"",""], 
                    AxesStyle = "Normal" + AxesStyle + " - No yaxis")
#                    dataTransform = dataTransform)
                    
        axeshare = ax
        
    gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.10, hspace=0)
    image_name = "differentSymbols.png"
    gl.savefig(folder_images + image_name, 
               dpi = 100, sizeInches = [30, 12])
           
           
Exemplo n.º 4
0
folder_images = "../pics/gl/"
gl.set_subplots(4,1)
 # TODO: Align the transformation of the daily prices to 
axeshare = None
for i in range(len(periods)):
    period = periods[i]
    myTimeData = mySymbol.get_timeData(period)
    
    AxesStyle = " - No xaxis"
    if (i == len(periods) -1):
        AxesStyle = ""
    
    if (i == 0):
        title = "Bar Chart. " + str(symbols[0]) + r" . Price ($\$$)"
    else:
        title = ""
    ylabel =   ul.period_dic[myTimeData.period]
    ax = gl.tradingBarChart(myTimeData,  legend = ["Close price"], color = "k", 
                nf = 1, sharex = axeshare, labels = [title,"",ylabel], AxesStyle = "Normal" + AxesStyle, 
                dataTransform = dataTransform)
    axeshare = ax
gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.20, hspace=0)
image_name = "differentPeriods.png"
gl.savefig(folder_images + image_name, 
           dpi = 100, sizeInches = [30, 12])
# TODO: We can also use the library of indicators especifing the period. 
# If no period specified, we use the dayly or the bigges one.


#######################
        symbols[0]) + "(" + ul.period_dic[timeData.period] + ")"
    gl.tradingLineChart(timeData,
                        seriesName="Close",
                        ax=ax1,
                        legend=["Close price"],
                        labels=[title, "", r"Price ($\$$)"],
                        AxesStyle="Normal - No xaxis",
                        dataTransform=dataTransform)

elif (typeChart == "Bar"):
    title = "Bar Chart. " + str(
        symbols[0]) + "(" + ul.period_dic[timeData.period] + ")"
    gl.tradingBarChart(timeData,
                       ax=ax1,
                       legend=["Close price"],
                       color="k",
                       labels=[title, "", r"Price ($\$$)"],
                       AxesStyle="Normal - No xaxis",
                       dataTransform=dataTransform)

elif (typeChart == "CandleStick"):
    title = "CandleStick Chart. " + str(
        symbols[0]) + "(" + ul.period_dic[timeData.period] + ")"
    gl.tradingCandleStickChart(timeData,
                               ax=ax1,
                               legend=["Close price"],
                               color="k",
                               colorup="r",
                               colordown="k",
                               alpha=0.5,
                               lw=3,
Exemplo n.º 6
0
############### PLOTTING #################################
##########################################################
"""

if (plotting_daily):
    
    # Get the daily values of the remaining days
    timeData_daily = tut.get_daily_timedata(timeData, symbols[0])
    ## Get the daily HLOC
    H,L,O,C,V = np.array(timeData_daily.TD[["High","Low","Open","Close","Volume"]][:]).T
    
    gl.init_figure()
    ax1 = gl.subplot2grid((4,1), (0,0), rowspan=3, colspan=1)
    
    title = "Bar Chart. " + str(symbols[0]) + "(" + ul.period_dic[1440]+ ")" 
    gl.tradingBarChart(timeData_daily, ax = ax1,  legend = ["Close price"], color = "k",
                        labels = [title,"",r"Rate"], AxesStyle = "Normal - No xaxis")
         
    ax2 = gl.subplot2grid((4,1), (3,0), rowspan=1, colspan=1, sharex = ax1)
    gl.tradingVolume(timeData_daily, ax = ax2,legend = ["Volume"], 
                     AxesStyle = "Normal", labels = ["","","Volume"], color = "#53868B")
    
    
    gl.set_fontSizes(ax = [ax1,ax2], title = 20, xlabel = 20, ylabel = 20, 
                      legend = 10, xticks = 10, yticks = 10)
    image_name = "daily_data"
    gl.savefig(folder_images + image_name, 
               dpi = 100, sizeInches = [20, 7])
    
if (plotting_flag):
    # Open and close hours !
    if(tranformIntraday):
Exemplo n.º 7
0
EMAslow = Cartera.symbols[symbol1].TDs[period1].EMA(n = Lslow)
EMAfast = Cartera.symbols[symbol1].TDs[period1].EMA(n = Lfast)
price = Cartera.symbols[symbol1].TDs[period1].get_timeSeries()
dataHLOC = Cartera.symbols[symbol1].TDs[period1].get_timeSeries(["High","Low","Open","Close"])
dates = Cartera.symbols[symbol1].TDs[period1].get_dates()

########## Plotting ! ####################
gl.set_subplots(4,1)

## Plot both prices and EMAs
ax1 = gl.plot(dates,price, legend = ["Price"],
        labels = ["Crossing MA Strategy", "","Price"], alpha = 0, nf = 1)
        
title = "Bar Chart. " + str(symbols[0]) + "(" + ul.period_dic[timeData.period]+ ")" 
timeData = Cartera.symbols[]
gl.tradingBarChart(timeData, ax = ax1,  legend = ["Close price"], color = "k",
                    labels = [title,"",r"Price ($\$$)"], AxesStyle = "Normal - No xaxis")

gl.plot(dates,EMAslow, legend = ["Slow"], lw = 1, color = "b")
gl.plot(dates,EMAfast, legend = ["fast"], lw = 1, color = "r", xaxis_mode = "hidden")

## Entry Axes 
ax2 = gl.plot(dates, ul.scale(EMAfast  - EMAslow), legend = ["Difference"]
        ,nf = 1, sharex = ax1, labels = ["","","Events"], fill = 1, alpha = 0.3)
gl.stem(dates,crosses, legend = ["TradeSignal"] )
gl.scatter(dates, ul.scale(EMAfast  - EMAslow), lw = 0.5, alpha = 0.5)
gl.plot(dates,np.zeros(crosses.shape))


 
# We can observe the apparent delay !
Exemplo n.º 8
0
symbol_ID2 = symbolIDs[symbol_ID_indx2]

#print dates[0], dates[26], dates[27]
################# Plotting the data #################
if (trading_graph):

    # Trading plot of the points !

    title = "CLOSE Price, Volume and Return evolution"

    ax1 = gl.subplot2grid((4, 1), (0, 0), rowspan=1, colspan=1)
    gl.tradingBarChart(Cartera.get_timeData(symbolIDs[symbol_ID_indx1],
                                            periods[0]),
                       ax=ax1,
                       dataTransform=dataTransform,
                       AxesStyle="Normal - No xaxis",
                       color="k",
                       labels=[
                           title, "", symbolIDs[symbol_ID_indx1] + "(" +
                           str(periods[0]) + "M)"
                       ])

    ax2 = gl.subplot2grid((4, 1), (1, 0), rowspan=1, colspan=1, sharex=ax1)
    gl.tradingBarChart(
        Cartera.get_timeData(symbolIDs[symbol_ID_indx2], periods[0]),
        ax=ax2,
        dataTransform=dataTransform,
        AxesStyle="Normal - No xaxis",
        color="k",
        labels=[
            "", "", symbolIDs[symbol_ID_indx2] + "(" + str(periods[0]) + "M)"
        ])
Exemplo n.º 9
0
#Cartera.get_timeData(symbolIDs[0],15).fill_data()
#Cartera.get_timeData(symbolIDs[1],15).fill_data()
ret1 = Cartera.get_timeData(symbolIDs[0], 15).get_timeSeriesReturn() * 100
ret2 = Cartera.get_timeData(symbolIDs[1], 15).get_timeSeriesReturn() * 100
dates = Cartera.get_timeData(symbolIDs[1], 15).get_dates()

print(dates[0], dates[26], dates[27])
################# Plotting the data #################
if (trading_graph):
    # Trading plot of the points !
    gl.set_subplots(2, 1)
    title = "Price evolution for 2 securities"
    ax1 = gl.tradingBarChart(Cartera.get_timeData(symbolIDs[0], 15),
                             nf=1,
                             dataTransform=dataTransform,
                             AxesStyle="Normal - No xaxis",
                             labels=[title, "", symbolIDs[0] + "(15M)"])
    gl.tradingBarChart(Cartera.get_timeData(symbolIDs[1], 15),
                       nf=1,
                       sharex=ax1,
                       dataTransform=dataTransform,
                       AxesStyle="Normal",
                       labels=["", "", symbolIDs[1] + "(15M)"])

    gl.savefig(folder_images + 'PriceEvolution2Symb15.png',
               dpi=100,
               sizeInches=[14, 7])

    # Returns stem plot of the points
    gl.set_subplots(2, 1)
Exemplo n.º 10
0
dataTransform = ["intraday", opentime, closetime]

#Cartera.get_timeData(symbolIDs[0],15).fill_data()
#Cartera.get_timeData(symbolIDs[1],15).fill_data()
ret1 = Cartera.get_timeData(symbolIDs[0],15).get_timeSeriesReturn()*100
ret2 = Cartera.get_timeData(symbolIDs[1],15).get_timeSeriesReturn()*100
dates = Cartera.get_timeData(symbolIDs[1],15).get_dates()

print (dates[0], dates[26], dates[27])
################# Plotting the data #################
if(trading_graph):
    # Trading plot of the points !
    gl.set_subplots(2,1)
    title = "Price evolution for 2 securities"
    ax1 = gl.tradingBarChart(Cartera.get_timeData(symbolIDs[0],15), nf = 1,
                             dataTransform = dataTransform, AxesStyle = "Normal - No xaxis",
                             labels = [title,"",symbolIDs[0] +"(15M)"])
    gl.tradingBarChart(Cartera.get_timeData(symbolIDs[1],15), nf = 1, sharex = ax1,
                       dataTransform = dataTransform, AxesStyle = "Normal",
                        labels = ["","",symbolIDs[1] +"(15M)"])

    gl.savefig(folder_images +'PriceEvolution2Symb15.png', 
               dpi = 100, sizeInches = [14, 7])
               
    # Returns stem plot of the points
    gl.set_subplots(2,1)
    title = "Return for 2 securities"
    ax1 = gl.stem(dates, ret1, nf = 1, dataTransform = dataTransform,
                   AxesStyle = "Normal - No xaxis",
                   labels = [title,"",symbolIDs[0] +"(15M)"])
    gl.stem(dates, ret2, nf = 1, dataTransform = dataTransform, sharex = ax1,