Package: thestockslib
thestockslibA simple library to manage stocks dataSample code# library import
from thestockslib import TheStock

# initialization
stock = TheStock('AAPL')

# getting live price
stock.getliveprice()

# getting current Yahoo recommendation
r = stock.getyahoorecommendation()
TheStock.getyahoorecommendationstring(r)

# getting Yahoo performance outlook information (short term, medium term, long term)
stock.getyahooperformanceoutlook()

# getting historical price at July 31st, 2020
stock.gethistoricalprice('2020-07-31')

# adding some mapping to recommendations actions
stock.addactiontoperiod('buy', 7) # when a 'buy' suggestion is received, consider a sell after 7 days
stock.addactiontoperiod('strong buy', 7) # when a 'strong buy' suggestion is received, consider a sell after 7 days
stock.addactiontoperiod('long-term buy', 30) # when a 'long-term buy' suggestion is received, consider a sell after 30 days

# initializing the suggester name
suggestername = 'Cascend'

# simulating purchases by suggester name
purchases = stock.simulatepurchases(suggestername)
print(purchases)

# simulating sells
stock.simulatesells(purchases)

# compute suggester's reliability for 'buy' actions
stock.getsuggestionreliability(suggestername, 'buy')Available EnumsConsideredAverageThisEnumis used to pass as input the average method to adopt, when historical data are requested.
Following values are possible:OPEN_CLOSE, to consider as daily value the average between open and close prices for a given stockHIGH_LOW, to consider as daily value the average between higher and lower prices for that day, for given stockAvailable classesJust a singleTheStockclass is available.Following attributes are supported:tickerthe string of the ticker considered (e.g.AAPL)tickerobjecttheyfinanceTicker objectdateformatthe date format to consider (default to%Y-%m-%d)consideredaveragethe average computation metric to consider (default toConsideredAverage.OPEN_CLOSE)historicaldatathe historical market data for the current ticker, according toyfinancedata format, converted to an array of recordsFollowing methods are supported:__init__(self, t, df='%Y-%m-%d', ca=ConsideredAverage.OPEN_CLOSE), initializes theTheStockobjectt(str) is the ticker/symboldf(str) is the date format to considerca(ConsideredAverage) is the average to consideraddactiontoperiod(a, p), adds a match between a recommendation action and the duration to consider for that recommendationa(str) is the action title/name, as mapped with the list of recommedationsp(int) is the period to consider, in daysconvertdatetime(d), converts a datetime objectdto a string, in the formatdfpassed during the object initializationd(datetime) the datetime object to convertgetliveprice(round_decimals=2), returns the current live price for the current symbolround_decimals(int) the decimals to consider for roundinggethistoricalprice(d, round_decimals=2), returns the historical price for the current symbol at timedd(datetime) the date to considerround_decimals(int) the decimals to consider for roundingsimulatepurchases(s), simulates purchases of the current symbol for the suggesterss(str) the suggester's name to considersimulatesells(p), simulates sell of given purchasesp, after the expiration of the relative period for the action suggested for that purchasep(list) the list of purchases objectsgetsuggestionreliabilitydata(suggester, suggestion, transactionprice=0.0), provides structured information on the reliability of a given suggester and for a given suggestionsuggester(str) the suggester's namesuggestion(str) the suggestion actiontransactionprice(float) the price for transaction to considergetsuggestionreliability(suggester, suggestion, transactionprice=0.0), computes the reliability of a given suggester and for a given suggestionsuggester(str) the suggester's namesuggestion(str) the suggestion actiontransactionprice(float) the price for transaction to considergenerategraphs(fcast_time, alphavantage_apikey, outputname_pre=''), generates the graphs to be displayed for the current symbolfcast_time(int) the forecast time to consider, in daysalphavantage_apikey(str) theAlphaVantageAPI key to useoutputname_pre(str) the preliminary file name to use for generated graphsgetyahoorecommendation(), returns the current Yahoo recommendation for the current symbolgetyahooperformanceoutlook(), returns the current Yahoo performance outlook for the current symbol (output is a list containing, in order, short term, medium term, long term results)getcompanynews(finnhub_apikey, fromdate=None), returns the list of today news related to the current symbolfinnhub_apikey(str) theFinnHubAPI key to usefromdate(str) the starting date to consider when retrieving the news, if the retrieval of news older than today is neededFollowing statical methods are supported:getrevolutsymbols(), returns the list of symbols supported byRevolutcombineimages(l, vertical=False, outputfile='output.png'), combines a list of images to an output filel(list) the list of file names of the input images to combinevertical(bool) the combination mode (vertical or horizonal)outputfile(str) the output file name to generateremoveimages(outputname_pre=''), removes all images generatedoutputname_pre(str) the preliminary file name to use for generated graphsgetyahoorecommendationstring(r), retrieves the Yahoo recommendation string from the input value represented asfloatr(float) the recommendation value represented asfloatTODOImprove code readabilityContactsYou can find me onTwitteras@auino.